@cowegis/client 1.0.2 → 1.0.3
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,7 @@
|
|
|
1
1
|
import osmtogeojson from 'osmtogeojson';
|
|
2
2
|
|
|
3
3
|
import leaflet from '../leaflet';
|
|
4
|
+
import {mapFactory} from "../factory";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Get the bounds as overpass bbox string.
|
|
@@ -30,7 +31,7 @@ export default leaflet.FeatureGroup.extend({
|
|
|
30
31
|
*
|
|
31
32
|
* @param options
|
|
32
33
|
*/
|
|
33
|
-
initialize: function (options) {
|
|
34
|
+
initialize: function (options, element) {
|
|
34
35
|
if (!options.pointToLayer) {
|
|
35
36
|
options.pointToLayer = this.pointToLayer;
|
|
36
37
|
}
|
|
@@ -39,10 +40,11 @@ export default leaflet.FeatureGroup.extend({
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
leaflet.Util.setOptions(this, options);
|
|
42
|
-
this.options.dynamicLoad = !!this.options.query.match(/BBOX/g);
|
|
43
|
+
this.options.dynamicLoad = !this.options.adjustBounds && !!this.options.query.match(/BBOX/g);
|
|
43
44
|
|
|
44
45
|
this._layer = leaflet.geoJson();
|
|
45
46
|
this._layers = {};
|
|
47
|
+
this._element = element;
|
|
46
48
|
|
|
47
49
|
this.addLayer(this._layer);
|
|
48
50
|
},
|
|
@@ -58,7 +60,7 @@ export default leaflet.FeatureGroup.extend({
|
|
|
58
60
|
|
|
59
61
|
var bounds = toOverpassBBoxString(this._map.getBounds());
|
|
60
62
|
var query = this.options.query.replace(/(BBOX)/g, bounds);
|
|
61
|
-
var url = this.options.endpoint + 'interpreter?data=[out:json];' + query;
|
|
63
|
+
var url = this.options.endpoint + 'interpreter?data=' + encodeURIComponent('[out:json];' + query);
|
|
62
64
|
|
|
63
65
|
this._map.fire('dataloading', {layer: this});
|
|
64
66
|
|
|
@@ -74,11 +76,9 @@ export default leaflet.FeatureGroup.extend({
|
|
|
74
76
|
this.removeLayer(this._layer);
|
|
75
77
|
this._layer = layer;
|
|
76
78
|
|
|
77
|
-
if (this.options.
|
|
79
|
+
if (this.options.adjustBounds && layer.getBounds().isValid()) {
|
|
78
80
|
var bounds = this._map.getBounds();
|
|
79
|
-
bounds
|
|
80
|
-
|
|
81
|
-
this._map.fitBounds(bounds, this._map.getBoundsOptions());
|
|
81
|
+
this._map.fitBounds(bounds.extend(layer.getBounds()));
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
this._map.fire('dataload', {layer: this});
|
|
@@ -88,8 +88,9 @@ export default leaflet.FeatureGroup.extend({
|
|
|
88
88
|
* @param map
|
|
89
89
|
*/
|
|
90
90
|
onAdd: function (map) {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
if (this.options.dynamicLoad) {
|
|
92
|
+
map.on('moveend', this.refreshData, this);
|
|
93
|
+
}
|
|
93
94
|
|
|
94
95
|
this.refreshData();
|
|
95
96
|
},
|
|
@@ -103,20 +104,18 @@ export default leaflet.FeatureGroup.extend({
|
|
|
103
104
|
marker.setRadius(feature.properties.radius);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
// TODO: Icon handling
|
|
107
107
|
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]);
|
|
108
|
+
icon = feature.properties.icon;
|
|
109
|
+
} else if (feature.properties.amenity) {
|
|
110
|
+
icon = this.options.amenityIcons[feature.properties.amenity] || undefined;
|
|
115
111
|
}
|
|
116
112
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
if (icon && this._element.config.map.presets.icons[icon]) {
|
|
114
|
+
mapFactory.createIcon(
|
|
115
|
+
this._element.config.map.presets.icons[icon],
|
|
116
|
+
feature.properties,
|
|
117
|
+
this._element
|
|
118
|
+
).then(icon => marker.setIcon(icon));
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
|