Commit 2bce12fa70f2eddaad3f1b253205ab59879da215
Committed by
GitHub
Merge pull request #3268 from vvlladd28/improvement/map/bounds-marker-cluster
[3.0] Fix updated bounds for marker cluster mode
Showing
1 changed file
with
21 additions
and
13 deletions
... | ... | @@ -322,9 +322,13 @@ export default abstract class LeafletMap { |
322 | 322 | bounds.extend(polygon.leafletPoly.getBounds()); |
323 | 323 | }); |
324 | 324 | } |
325 | - this.markers.forEach((marker) => { | |
326 | - bounds.extend(marker.leafletMarker.getLatLng()); | |
327 | - }); | |
325 | + if ((this.options as MarkerSettings).useClusterMarkers) { | |
326 | + bounds.extend(this.markersCluster.getBounds()); | |
327 | + } else { | |
328 | + this.markers.forEach((marker) => { | |
329 | + bounds.extend(marker.leafletMarker.getLatLng()); | |
330 | + }); | |
331 | + } | |
328 | 332 | |
329 | 333 | const mapBounds = this.map.getBounds(); |
330 | 334 | if (bounds.isValid() && (!this.bounds || !mapBounds.contains(bounds))) { |
... | ... | @@ -398,16 +402,20 @@ export default abstract class LeafletMap { |
398 | 402 | |
399 | 403 | private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings, |
400 | 404 | updateBounds = true, callback?): Marker { |
401 | - const newMarker = new Marker(this, this.convertPosition(data), settings, data, dataSources, this.dragMarker); | |
402 | - if (callback) | |
403 | - newMarker.leafletMarker.on('click', () => { callback(data, true) }); | |
404 | - if (this.bounds && updateBounds) | |
405 | - this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng())); | |
406 | - this.markers.set(key, newMarker); | |
407 | - if (!this.options.useClusterMarkers) { | |
408 | - this.map.addLayer(newMarker.leafletMarker); | |
409 | - } | |
410 | - return newMarker; | |
405 | + const newMarker = new Marker(this, this.convertPosition(data), settings, data, dataSources, this.dragMarker); | |
406 | + if (callback) { | |
407 | + newMarker.leafletMarker.on('click', () => { | |
408 | + callback(data, true) | |
409 | + }); | |
410 | + } | |
411 | + if (this.bounds && updateBounds && !(this.options as MarkerSettings).useClusterMarkers) { | |
412 | + this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng())); | |
413 | + } | |
414 | + this.markers.set(key, newMarker); | |
415 | + if (!this.options.useClusterMarkers) { | |
416 | + this.map.addLayer(newMarker.leafletMarker); | |
417 | + } | |
418 | + return newMarker; | |
411 | 419 | } |
412 | 420 | |
413 | 421 | private updateMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings): Marker { | ... | ... |