@nextgis/leaflet-map-adapter 1.9.1 → 1.11.0

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.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 1.9.1; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 1.11.0; author: NextGIS */
2
2
  import { EventEmitter } from 'events';
3
3
  import { Control, DomEvent, GeoJSON, FeatureGroup, DivIcon, Marker, CircleMarker, ImageOverlay as ImageOverlay$1, Layer, Util, CRS, GridLayer, DomUtil, TileLayer as TileLayer$1, Map } from 'leaflet';
4
4
  import { debounce as debounce$1, defined } from '@nextgis/utils';
@@ -25,6 +25,9 @@ function createControl(control, options = {}, map) {
25
25
  if (options.bar) {
26
26
  element.classList.add('leaflet-bar');
27
27
  }
28
+ if (options.addClass) {
29
+ element.classList.add(options.addClass);
30
+ }
28
31
  if (!options.margin && !options.bar) {
29
32
  element.style.marginBottom = '0px';
30
33
  element.style.marginTop = '0px';
@@ -502,7 +505,10 @@ class GeoJsonAdapter extends BaseAdapter {
502
505
  async _openPopup(def, options = {}, type, latLng) {
503
506
  var _a, _b;
504
507
  const { feature, layer } = def;
505
- const { minWidth, autoPan, maxWidth, closeButton: closeButton_, } = { minWidth: 300, ...options };
508
+ const { minWidth, autoPan, maxWidth, closeButton: closeButton_, } = {
509
+ minWidth: 300,
510
+ ...options,
511
+ };
506
512
  const closeButton = closeButton_ !== null && closeButton_ !== void 0 ? closeButton_ : !this.options.selectOnHover;
507
513
  let popup;
508
514
  const _closeHandlers = [];
@@ -730,14 +736,14 @@ class GeoJsonAdapter extends BaseAdapter {
730
736
  }
731
737
  }
732
738
  _handleMouseEvents(layer) {
733
- const isSelected = (l) => this._selectedLayers.indexOf(l) !== -1;
734
739
  const { onClick, onLayerClick, onMouseOut, onMouseOver } = this.options;
735
740
  // TODO: remove backward compatibility for onLayerClick
736
741
  const onClick_ = onClick || onLayerClick;
737
742
  if (onClick_) {
738
743
  layer.on('click', (e) => {
744
+ const selected = !!this._getSelected(layer);
739
745
  onClick_({
740
- selected: isSelected(e.target),
746
+ selected,
741
747
  ...this._createMouseEvent(e),
742
748
  });
743
749
  }, this);
@@ -759,6 +765,9 @@ class GeoJsonAdapter extends BaseAdapter {
759
765
  source: source,
760
766
  });
761
767
  }
768
+ _getSelected(layer) {
769
+ return this._selectedLayers.find((x) => x.layer === layer);
770
+ }
762
771
  _selectOnLayerClick(e) {
763
772
  DomEvent.stopPropagation(e);
764
773
  const layer = e.target;
@@ -769,7 +778,7 @@ class GeoJsonAdapter extends BaseAdapter {
769
778
  feature,
770
779
  ...createFeaturePositionOptions(feature),
771
780
  };
772
- const isSelected = this._selectedLayers.find((x) => x.layer === layer);
781
+ const isSelected = this._getSelected(layer);
773
782
  if (isSelected) {
774
783
  if (this.options && this.options.unselectOnSecondClick) {
775
784
  this._unSelectLayer(isSelected);
@@ -1373,6 +1382,7 @@ class LeafletMapAdapter$1 {
1373
1382
  if (this.map) {
1374
1383
  this.map.remove();
1375
1384
  }
1385
+ this._stopWatchSizeChangeToUpdateMinZoom();
1376
1386
  }
1377
1387
  getContainer() {
1378
1388
  return this.map && this.map.getContainer();
@@ -1423,17 +1433,22 @@ class LeafletMapAdapter$1 {
1423
1433
  }
1424
1434
  if (maxBounds !== undefined) {
1425
1435
  if (maxBounds) {
1426
- map.setMaxBounds(arrayToBoundsExpression(maxBounds));
1436
+ const b = arrayToBoundsExpression(maxBounds);
1437
+ map.setMaxBounds(b);
1438
+ map.setMinZoom(map.getBoundsZoom(b));
1439
+ this._watchSizeChangeToUpdateMinZoom(b);
1427
1440
  }
1428
1441
  else {
1429
1442
  // @ts-ignore `null` works for unset maxBounds, but not in typing
1430
1443
  map.setMaxBounds(null);
1444
+ this._stopWatchSizeChangeToUpdateMinZoom();
1431
1445
  }
1432
1446
  }
1433
1447
  if (maxZoom !== undefined) {
1434
1448
  map.setMaxZoom(maxZoom);
1435
1449
  }
1436
1450
  if (minZoom !== undefined) {
1451
+ this._stopWatchSizeChangeToUpdateMinZoom();
1437
1452
  map.setMinZoom(minZoom);
1438
1453
  }
1439
1454
  }
@@ -1568,6 +1583,27 @@ class LeafletMapAdapter$1 {
1568
1583
  this._unselectCb.length = 0;
1569
1584
  this._unselectCb.push(cb);
1570
1585
  }
1586
+ _watchSizeChangeToUpdateMinZoom(bounds) {
1587
+ this._stopWatchSizeChangeToUpdateMinZoom();
1588
+ const container = this.getContainer();
1589
+ const map = this.map;
1590
+ if (container && map && window.ResizeObserver) {
1591
+ this._resizeObserver = new ResizeObserver(() => {
1592
+ map.setMinZoom(map.getBoundsZoom(bounds));
1593
+ });
1594
+ this._resizeObserver.observe(container);
1595
+ }
1596
+ }
1597
+ _stopWatchSizeChangeToUpdateMinZoom() {
1598
+ const map = this.map;
1599
+ if (map) {
1600
+ map.setMinZoom(0);
1601
+ }
1602
+ if (this._resizeObserver) {
1603
+ this._resizeObserver.disconnect();
1604
+ this._resizeObserver = undefined;
1605
+ }
1606
+ }
1571
1607
  _addMapListeners() {
1572
1608
  const map = this.map;
1573
1609
  if (map) {