@cowegis/client 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/factory/MapFactory.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import osmtogeojson from 'osmtogeojson';
|
|
2
2
|
|
|
3
3
|
import leaflet from '../leaflet';
|
|
4
|
+
import {mapFactory} from "../factory";
|
|
5
|
+
import {determineListener} from "../factory/bindEvents";
|
|
6
|
+
import pointToLayer from "../geojson/pointToLayer";
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Get the bounds as overpass bbox string.
|
|
@@ -30,19 +33,21 @@ export default leaflet.FeatureGroup.extend({
|
|
|
30
33
|
*
|
|
31
34
|
* @param options
|
|
32
35
|
*/
|
|
33
|
-
initialize: function (options) {
|
|
34
|
-
|
|
35
|
-
options.pointToLayer
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
initialize: function (options, element) {
|
|
37
|
+
options.pointToLayer = options.pointToLayer
|
|
38
|
+
? determineListener(options.pointToLayer, element)
|
|
39
|
+
: this.pointToLayer;
|
|
40
|
+
|
|
41
|
+
options.onEachFeature = options.onEachFeature
|
|
42
|
+
? determineListener(options.onEachFeature, element)
|
|
43
|
+
: this.onEachFeature;
|
|
40
44
|
|
|
41
45
|
leaflet.Util.setOptions(this, options);
|
|
42
|
-
this.options.dynamicLoad = !!this.options.query.match(/BBOX/g);
|
|
46
|
+
this.options.dynamicLoad = !this.options.adjustBounds && !!this.options.query.match(/BBOX/g);
|
|
43
47
|
|
|
44
48
|
this._layer = leaflet.geoJson();
|
|
45
49
|
this._layers = {};
|
|
50
|
+
this._element = element;
|
|
46
51
|
|
|
47
52
|
this.addLayer(this._layer);
|
|
48
53
|
},
|
|
@@ -58,7 +63,7 @@ export default leaflet.FeatureGroup.extend({
|
|
|
58
63
|
|
|
59
64
|
var bounds = toOverpassBBoxString(this._map.getBounds());
|
|
60
65
|
var query = this.options.query.replace(/(BBOX)/g, bounds);
|
|
61
|
-
var url = this.options.endpoint + 'interpreter?data=[out:json];' + query;
|
|
66
|
+
var url = this.options.endpoint + 'interpreter?data=' + encodeURIComponent('[out:json];' + query);
|
|
62
67
|
|
|
63
68
|
this._map.fire('dataloading', {layer: this});
|
|
64
69
|
|
|
@@ -74,11 +79,9 @@ export default leaflet.FeatureGroup.extend({
|
|
|
74
79
|
this.removeLayer(this._layer);
|
|
75
80
|
this._layer = layer;
|
|
76
81
|
|
|
77
|
-
if (this.options.
|
|
82
|
+
if (this.options.adjustBounds && layer.getBounds().isValid()) {
|
|
78
83
|
var bounds = this._map.getBounds();
|
|
79
|
-
bounds
|
|
80
|
-
|
|
81
|
-
this._map.fitBounds(bounds, this._map.getBoundsOptions());
|
|
84
|
+
this._map.fitBounds(bounds.extend(layer.getBounds()));
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
this._map.fire('dataload', {layer: this});
|
|
@@ -88,8 +91,9 @@ export default leaflet.FeatureGroup.extend({
|
|
|
88
91
|
* @param map
|
|
89
92
|
*/
|
|
90
93
|
onAdd: function (map) {
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
if (this.options.dynamicLoad) {
|
|
95
|
+
map.on('moveend', this.refreshData, this);
|
|
96
|
+
}
|
|
93
97
|
|
|
94
98
|
this.refreshData();
|
|
95
99
|
},
|
|
@@ -103,20 +107,18 @@ export default leaflet.FeatureGroup.extend({
|
|
|
103
107
|
marker.setRadius(feature.properties.radius);
|
|
104
108
|
}
|
|
105
109
|
|
|
106
|
-
// TODO: Icon handling
|
|
107
110
|
if (feature.properties.icon) {
|
|
108
|
-
icon =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
&& feature.properties.tags.amenity
|
|
112
|
-
&& this.options.amenityIcons[feature.properties.tags.amenity]
|
|
113
|
-
) {
|
|
114
|
-
//icon = L.contao.getIcon(this.options.amenityIcons[feature.properties.tags.amenity]);
|
|
111
|
+
icon = feature.properties.icon;
|
|
112
|
+
} else if (feature.properties.amenity) {
|
|
113
|
+
icon = this.options.amenityIcons[feature.properties.amenity] || undefined;
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
if (icon && this._element.config.map.presets.icons[icon]) {
|
|
117
|
+
mapFactory.createIcon(
|
|
118
|
+
this._element.config.map.presets.icons[icon],
|
|
119
|
+
feature.properties,
|
|
120
|
+
this._element
|
|
121
|
+
).then(icon => marker.setIcon(icon));
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
|
|
@@ -83,6 +83,10 @@ export default async function (config, element) {
|
|
|
83
83
|
? determineListener(config.options.pointToLayer, element)
|
|
84
84
|
: pointToLayer;
|
|
85
85
|
|
|
86
|
+
if (config.options.onEachFeature) {
|
|
87
|
+
config.options.onEachFeature = determineListener(config.options.onEachFeature, element);
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
config.options.pointToLayer = (feature, latlng) => pointToLayerCallback(feature, latlng, element, pointToLayer);
|
|
87
91
|
|
|
88
92
|
const layer = leaflet.geoJSON(data, config.options);
|