...
|
...
|
@@ -21,10 +21,10 @@ export default abstract class LeafletMap { |
21
|
21
|
ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map));
|
22
|
22
|
options: MapOptions;
|
23
|
23
|
isMarketCluster;
|
|
24
|
+ bounds: L.LatLngBounds;
|
24
|
25
|
|
25
|
26
|
|
26
|
27
|
constructor($container: HTMLElement, options: MapOptions) {
|
27
|
|
- console.log("LeafletMap -> constructor -> options", options)
|
28
|
28
|
this.options = options;
|
29
|
29
|
}
|
30
|
30
|
|
...
|
...
|
@@ -52,6 +52,11 @@ export default abstract class LeafletMap { |
52
|
52
|
|
53
|
53
|
public setMap(map: L.Map) {
|
54
|
54
|
this.map = map;
|
|
55
|
+ if (this.options.useDefaultCenterPosition) {
|
|
56
|
+ this.map.panTo(this.options.defaultCenterPosition);
|
|
57
|
+ this.bounds = map.getBounds();
|
|
58
|
+ }
|
|
59
|
+ else this.bounds = new L.LatLngBounds(null, null)
|
55
|
60
|
this.map$.next(this.map);
|
56
|
61
|
}
|
57
|
62
|
|
...
|
...
|
@@ -147,7 +152,9 @@ export default abstract class LeafletMap { |
147
|
152
|
let defaultSettings: MarkerSettings = {
|
148
|
153
|
color: '#FD2785'
|
149
|
154
|
}
|
150
|
|
- this.markers.set(key, new Marker(this.map, location, { ...defaultSettings, ...settings }))
|
|
155
|
+ const newMarker = new Marker(this.map, location, { ...defaultSettings, ...settings });
|
|
156
|
+ this.map.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()));
|
|
157
|
+ this.markers.set(key, newMarker);
|
151
|
158
|
});
|
152
|
159
|
}
|
153
|
160
|
|
...
|
...
|
@@ -172,7 +179,6 @@ export default abstract class LeafletMap { |
172
|
179
|
}
|
173
|
180
|
|
174
|
181
|
else {
|
175
|
|
- this.map$
|
176
|
182
|
this.createPolyline(polyData.map(data => this.convertPosition(data)), this.options);
|
177
|
183
|
}
|
178
|
184
|
|
...
|
...
|
@@ -187,8 +193,13 @@ export default abstract class LeafletMap { |
187
|
193
|
}
|
188
|
194
|
|
189
|
195
|
createPolyline(locations, settings) {
|
190
|
|
- this.ready$.subscribe(() =>
|
191
|
|
- this.poly = new Polyline(this.map, locations, settings)
|
192
|
|
- )
|
|
196
|
+ this.ready$.subscribe(() => {
|
|
197
|
+ this.poly = new Polyline(this.map, locations, settings);
|
|
198
|
+ const bounds = this.bounds.extend(this.poly.leafletPoly.getBounds());
|
|
199
|
+ if (bounds.isValid()) {
|
|
200
|
+ this.map.fitBounds(bounds);
|
|
201
|
+ this.bounds = bounds;
|
|
202
|
+ }
|
|
203
|
+ });
|
193
|
204
|
}
|
194
|
205
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|