Merge pull request #3268 from vvlladd28/improvement/map/bounds-marker-cluster

[3.0] Fix updated bounds for marker cluster mode
This commit is contained in:
Igor Kulikov 2020-08-10 14:36:27 +03:00 committed by GitHub
commit 2bce12fa70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -322,9 +322,13 @@ export default abstract class LeafletMap {
bounds.extend(polygon.leafletPoly.getBounds()); bounds.extend(polygon.leafletPoly.getBounds());
}); });
} }
this.markers.forEach((marker) => { if ((this.options as MarkerSettings).useClusterMarkers) {
bounds.extend(marker.leafletMarker.getLatLng()); bounds.extend(this.markersCluster.getBounds());
}); } else {
this.markers.forEach((marker) => {
bounds.extend(marker.leafletMarker.getLatLng());
});
}
const mapBounds = this.map.getBounds(); const mapBounds = this.map.getBounds();
if (bounds.isValid() && (!this.bounds || !mapBounds.contains(bounds))) { if (bounds.isValid() && (!this.bounds || !mapBounds.contains(bounds))) {
@ -398,16 +402,20 @@ export default abstract class LeafletMap {
private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings, private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings,
updateBounds = true, callback?): Marker { updateBounds = true, callback?): Marker {
const newMarker = new Marker(this, this.convertPosition(data), settings, data, dataSources, this.dragMarker); const newMarker = new Marker(this, this.convertPosition(data), settings, data, dataSources, this.dragMarker);
if (callback) if (callback) {
newMarker.leafletMarker.on('click', () => { callback(data, true) }); newMarker.leafletMarker.on('click', () => {
if (this.bounds && updateBounds) callback(data, true)
this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng())); });
this.markers.set(key, newMarker); }
if (!this.options.useClusterMarkers) { if (this.bounds && updateBounds && !(this.options as MarkerSettings).useClusterMarkers) {
this.map.addLayer(newMarker.leafletMarker); this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()));
} }
return newMarker; this.markers.set(key, newMarker);
if (!this.options.useClusterMarkers) {
this.map.addLayer(newMarker.leafletMarker);
}
return newMarker;
} }
private updateMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings): Marker { private updateMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings): Marker {