Commit cffe2135f2149cb748ca5e355f40e146640b27c5

Authored by Vladyslav_Prykhodko
1 parent 9b92f67b

Fix updated bounds for marker cluster mode

... ... @@ -320,9 +320,13 @@ export default abstract class LeafletMap {
320 320 bounds.extend(polygon.leafletPoly.getBounds());
321 321 });
322 322 }
323   - this.markers.forEach((marker) => {
324   - bounds.extend(marker.leafletMarker.getLatLng());
325   - });
  323 + if ((this.options as MarkerSettings).useClusterMarkers) {
  324 + bounds.extend(this.markersCluster.getBounds());
  325 + } else {
  326 + this.markers.forEach((marker) => {
  327 + bounds.extend(marker.leafletMarker.getLatLng());
  328 + });
  329 + }
326 330
327 331 const mapBounds = this.map.getBounds();
328 332 if (bounds.isValid() && (!this.bounds || !mapBounds.contains(bounds))) {
... ... @@ -396,16 +400,20 @@ export default abstract class LeafletMap {
396 400
397 401 private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings,
398 402 updateBounds = true, callback?): Marker {
399   - const newMarker = new Marker(this, this.convertPosition(data), settings, data, dataSources, this.dragMarker);
400   - if (callback)
401   - newMarker.leafletMarker.on('click', () => { callback(data, true) });
402   - if (this.bounds && updateBounds)
403   - this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()));
404   - this.markers.set(key, newMarker);
405   - if (!this.options.useClusterMarkers) {
406   - this.map.addLayer(newMarker.leafletMarker);
407   - }
408   - return newMarker;
  403 + const newMarker = new Marker(this, this.convertPosition(data), settings, data, dataSources, this.dragMarker);
  404 + if (callback) {
  405 + newMarker.leafletMarker.on('click', () => {
  406 + callback(data, true)
  407 + });
  408 + }
  409 + if (this.bounds && updateBounds && !(this.options as MarkerSettings).useClusterMarkers) {
  410 + this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()));
  411 + }
  412 + this.markers.set(key, newMarker);
  413 + if (!this.options.useClusterMarkers) {
  414 + this.map.addLayer(newMarker.leafletMarker);
  415 + }
  416 + return newMarker;
409 417 }
410 418
411 419 private updateMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings): Marker {
... ...