@nextgis/leaflet-map-adapter 3.1.0 → 4.0.0-alpha.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,6 +1,7 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 3.1.0; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 4.0.0-alpha.0; author: NextGIS */
2
+ import { LeafletControlContainer, createControl, createButtonControl, createToggleControl } from '@nextgis/leaflet-control-container';
2
3
  import { EventEmitter } from 'events';
3
- import { Control, DomEvent, GeoJSON, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1, Layer, Util, GridLayer, DomUtil, TileLayer as TileLayer$1, Map, latLngBounds, latLng } from 'leaflet';
4
+ import { Control, GeoJSON, DomEvent, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1, Layer, Util, GridLayer, DomUtil, TileLayer as TileLayer$1, Map, latLngBounds, latLng } from 'leaflet';
4
5
  import { defined, debounce as debounce$1, isObject, updateUrlParams } from '@nextgis/utils';
5
6
  import { isPaintCallback, isPaint } from '@nextgis/paint';
6
7
  import Queue from '@nextgis/queue';
@@ -22,81 +23,6 @@ class AttributionControl extends Control.Attribution {
22
23
  }
23
24
  }
24
25
 
25
- function createControl(control, options = {}, map) {
26
- const C = Control.extend({
27
- onAdd() {
28
- const element = document.createElement("div");
29
- const content = control.onAdd(map);
30
- element.classList.add("leaflet-control");
31
- if (options.bar) {
32
- element.classList.add("leaflet-bar");
33
- }
34
- if (options.addClass) {
35
- element.classList.add(options.addClass);
36
- }
37
- if (!options.margin && !options.bar) {
38
- element.style.marginBottom = "0px";
39
- element.style.marginTop = "0px";
40
- element.style.marginLeft = "0px";
41
- element.style.marginRight = "0px";
42
- }
43
- if (content) {
44
- element.appendChild(content);
45
- }
46
- DomEvent.disableClickPropagation(element);
47
- return element;
48
- },
49
- onRemove() {
50
- control.onRemove();
51
- }
52
- });
53
- return new C();
54
- }
55
-
56
- function createButtonControl(options, map) {
57
- const link = document.createElement("a");
58
- const title = options.title || "";
59
- link.href = "#";
60
- link.title = title;
61
- link.setAttribute("role", "button");
62
- link.setAttribute("aria-label", title);
63
- if (options.addClass) {
64
- link.classList.add(options.addClass);
65
- }
66
- DomEvent.disableClickPropagation(link);
67
- DomEvent.on(link, "click", DomEvent.stop);
68
- if (options.html instanceof HTMLElement) {
69
- link.appendChild(options.html);
70
- } else if (typeof options.html === "string") {
71
- link.innerHTML = options.html;
72
- }
73
- const onClick = (e) => {
74
- e.stopPropagation();
75
- options.onClick();
76
- };
77
- return createControl(
78
- {
79
- onAdd() {
80
- if (options.onClick !== void 0) {
81
- link.addEventListener("click", onClick);
82
- }
83
- return link;
84
- },
85
- onRemove() {
86
- const parent = link.parentNode;
87
- if (parent) {
88
- parent.removeChild(link);
89
- }
90
- if (options.onClick !== void 0) {
91
- link.removeEventListener("click", onClick);
92
- }
93
- }
94
- },
95
- { bar: true },
96
- map
97
- );
98
- }
99
-
100
26
  function boundsToArray(bounds) {
101
27
  const ne = bounds.getNorthEast();
102
28
  const sw = bounds.getSouthWest();
@@ -1688,6 +1614,7 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
1688
1614
  __publicField(this, "emitter", new EventEmitter());
1689
1615
  __publicField(this, "map");
1690
1616
  __publicField(this, "_resizeObserver");
1617
+ __publicField(this, "_controlContainer");
1691
1618
  __publicField(this, "_unselectCb", []);
1692
1619
  __publicField(this, "_universalEvents", [
1693
1620
  "move",
@@ -1726,6 +1653,7 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
1726
1653
  this._updateMinZoomForBounds(minZoom);
1727
1654
  this._watchSizeChangeToUpdateMinZoom();
1728
1655
  const defPane = this.map.createPane("order-0");
1656
+ this._controlContainer = new LeafletControlContainer(this.map);
1729
1657
  this.map._addUnselectCb = (def) => {
1730
1658
  this._addUnselectCb(def);
1731
1659
  };
@@ -1738,12 +1666,19 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
1738
1666
  if (this.map) {
1739
1667
  this.map.remove();
1740
1668
  }
1669
+ if (this._controlContainer) {
1670
+ this._controlContainer.detach();
1671
+ this._controlContainer = void 0;
1672
+ }
1741
1673
  this._stopWatchSizeChangeToUpdateMinZoom();
1742
1674
  }
1743
1675
  getContainer() {
1744
1676
  return this.map && this.map.getContainer();
1745
1677
  }
1746
1678
  getControlContainer() {
1679
+ if (this._controlContainer) {
1680
+ return this._controlContainer.getContainer();
1681
+ }
1747
1682
  const controlContainer = this.map && this.map._controlContainer;
1748
1683
  if (controlContainer) {
1749
1684
  return controlContainer;
@@ -1857,16 +1792,17 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
1857
1792
  createButtonControl(options) {
1858
1793
  return createButtonControl(options, this);
1859
1794
  }
1860
- addControl(control, position) {
1861
- control.options.position = position.replace("-", "");
1862
- if (this.map) {
1863
- this.map.addControl(control);
1864
- return control;
1795
+ createToggleControl(options) {
1796
+ return createToggleControl(options, this);
1797
+ }
1798
+ addControl(control, position, options) {
1799
+ if (this._controlContainer) {
1800
+ return this._controlContainer.addControl(control, position, options);
1865
1801
  }
1866
1802
  }
1867
1803
  removeControl(control) {
1868
- if (this.map) {
1869
- this.map.removeControl(control);
1804
+ if (this._controlContainer) {
1805
+ this._controlContainer.removeControl(control);
1870
1806
  }
1871
1807
  }
1872
1808
  removeLayer(layer) {