@nextgis/leaflet-map-adapter 2.0.2 → 2.2.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.
- package/lib/index.d.ts +1 -0
- package/lib/leaflet-map-adapter.esm-browser.js +64 -29
- package/lib/leaflet-map-adapter.esm-browser.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-browser.prod.js +1 -1
- package/lib/leaflet-map-adapter.esm-browser.prod.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.js +65 -30
- package/lib/leaflet-map-adapter.esm-bundler.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.prod.js +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.prod.js.map +1 -1
- package/lib/leaflet-map-adapter.global.js +64 -29
- package/lib/leaflet-map-adapter.global.js.map +1 -1
- package/lib/leaflet-map-adapter.global.prod.js +1 -1
- package/lib/leaflet-map-adapter.global.prod.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/** Bundle of @nextgis/leaflet-map-adapter; version: 2.0
|
|
1
|
+
/** Bundle of @nextgis/leaflet-map-adapter; version: 2.2.0; author: NextGIS */
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { Control, DomEvent, GeoJSON, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1,
|
|
3
|
+
import { Control, DomEvent, GeoJSON, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1, Util, Layer, CRS, GridLayer, DomUtil, TileLayer as TileLayer$1, Map, latLngBounds, latLng } from 'leaflet';
|
|
4
4
|
import { defined, debounce as debounce$1 } from '@nextgis/utils';
|
|
5
5
|
import { isPaintCallback, isPaint } from '@nextgis/paint';
|
|
6
6
|
|
|
@@ -1115,30 +1115,32 @@ var __publicField$3 = (obj, key, value) => {
|
|
|
1115
1115
|
class ImageOverlay extends ImageOverlay$1 {
|
|
1116
1116
|
constructor(imageUrl, bounds, options) {
|
|
1117
1117
|
super(imageUrl, bounds, options);
|
|
1118
|
-
__publicField$3(this, "
|
|
1118
|
+
__publicField$3(this, "_aborter");
|
|
1119
1119
|
}
|
|
1120
1120
|
cancelLoad() {
|
|
1121
|
-
if (this.
|
|
1122
|
-
this.
|
|
1123
|
-
this.
|
|
1121
|
+
if (this._aborter) {
|
|
1122
|
+
this._aborter();
|
|
1123
|
+
this._aborter = void 0;
|
|
1124
1124
|
}
|
|
1125
1125
|
}
|
|
1126
1126
|
_initImage() {
|
|
1127
1127
|
super._initImage();
|
|
1128
1128
|
const headers = this.options.headers;
|
|
1129
|
+
const img = this._image;
|
|
1130
|
+
const src = img.src;
|
|
1129
1131
|
if (headers) {
|
|
1130
|
-
const img = this._image;
|
|
1131
|
-
const src = img.src;
|
|
1132
1132
|
img.src = "";
|
|
1133
|
-
this.
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
headers
|
|
1140
|
-
)
|
|
1133
|
+
this._aborter = callAjax(
|
|
1134
|
+
src,
|
|
1135
|
+
(response) => {
|
|
1136
|
+
img.src = response;
|
|
1137
|
+
},
|
|
1138
|
+
headers
|
|
1141
1139
|
);
|
|
1140
|
+
} else {
|
|
1141
|
+
this._aborter = () => {
|
|
1142
|
+
img.setAttribute("src", Util.emptyImageUrl);
|
|
1143
|
+
};
|
|
1142
1144
|
}
|
|
1143
1145
|
}
|
|
1144
1146
|
}
|
|
@@ -1177,6 +1179,7 @@ class ImageLayer extends Layer {
|
|
|
1177
1179
|
__publicField$2(this, "_url");
|
|
1178
1180
|
__publicField$2(this, "_currentUrl");
|
|
1179
1181
|
__publicField$2(this, "_currentOverlay");
|
|
1182
|
+
__publicField$2(this, "_loadedOverlay");
|
|
1180
1183
|
this._url = url;
|
|
1181
1184
|
const params = {};
|
|
1182
1185
|
const opts = {};
|
|
@@ -1230,15 +1233,18 @@ class ImageLayer extends Layer {
|
|
|
1230
1233
|
this._currentUrl = url;
|
|
1231
1234
|
const viewPortBuffer = this.options.viewPortBuffer || 0;
|
|
1232
1235
|
const bounds = this._map.getBounds().pad(viewPortBuffer);
|
|
1236
|
+
if (this._loadedOverlay) {
|
|
1237
|
+
this._loadedOverlay.cancelLoad();
|
|
1238
|
+
this._loadedOverlay.off("load");
|
|
1239
|
+
this._loadedOverlay = void 0;
|
|
1240
|
+
}
|
|
1233
1241
|
const overlay = new ImageOverlay(url, bounds, {
|
|
1234
1242
|
opacity: 0,
|
|
1235
1243
|
pane: this.options.pane,
|
|
1236
1244
|
headers: this.options.headers
|
|
1237
1245
|
});
|
|
1238
1246
|
overlay.addTo(this._map);
|
|
1239
|
-
|
|
1240
|
-
this._currentOverlay.cancelLoad();
|
|
1241
|
-
}
|
|
1247
|
+
this._loadedOverlay = overlay;
|
|
1242
1248
|
overlay.once(
|
|
1243
1249
|
"load",
|
|
1244
1250
|
() => {
|
|
@@ -1251,6 +1257,7 @@ class ImageLayer extends Layer {
|
|
|
1251
1257
|
} else if (this._currentOverlay) {
|
|
1252
1258
|
this._map.removeLayer(this._currentOverlay);
|
|
1253
1259
|
}
|
|
1260
|
+
this._loadedOverlay = void 0;
|
|
1254
1261
|
this._currentOverlay = overlay;
|
|
1255
1262
|
overlay.setOpacity(
|
|
1256
1263
|
this.options.opacity !== void 0 ? this.options.opacity : 1
|
|
@@ -1514,6 +1521,16 @@ class TileAdapter extends BaseAdapter {
|
|
|
1514
1521
|
}
|
|
1515
1522
|
}
|
|
1516
1523
|
}
|
|
1524
|
+
updateLayer() {
|
|
1525
|
+
if (this.layer) {
|
|
1526
|
+
const currentUrl = this.layer._url;
|
|
1527
|
+
const timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1528
|
+
const separator = currentUrl.includes("?") ? "&" : "?";
|
|
1529
|
+
const newUrl = currentUrl.replace(/(\?|&)timestamp=\d*/g, "") + separator + `timestamp=${timestamp}`;
|
|
1530
|
+
this.layer.setUrl(newUrl);
|
|
1531
|
+
this.layer.redraw();
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1517
1534
|
}
|
|
1518
1535
|
|
|
1519
1536
|
var __defProp$2 = Object.defineProperty;
|
|
@@ -1681,6 +1698,8 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
|
|
|
1681
1698
|
center: center && [center[1], center[0]],
|
|
1682
1699
|
zoom
|
|
1683
1700
|
}, mapAdapterOptions));
|
|
1701
|
+
this._updateMinZoomForBounds(minZoom);
|
|
1702
|
+
this._watchSizeChangeToUpdateMinZoom();
|
|
1684
1703
|
const defPane = this.map.createPane("order-0");
|
|
1685
1704
|
this.map._addUnselectCb = (def) => {
|
|
1686
1705
|
this._addUnselectCb(def);
|
|
@@ -1744,19 +1763,17 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
|
|
|
1744
1763
|
if (maxBounds) {
|
|
1745
1764
|
const b = arrayToBoundsExpression(maxBounds);
|
|
1746
1765
|
map.setMaxBounds(b);
|
|
1747
|
-
|
|
1748
|
-
this._watchSizeChangeToUpdateMinZoom(b);
|
|
1766
|
+
this._updateMinZoomForBounds();
|
|
1749
1767
|
} else {
|
|
1750
1768
|
map.setMaxBounds(null);
|
|
1751
|
-
this.
|
|
1769
|
+
this._updateMinZoomForBounds();
|
|
1752
1770
|
}
|
|
1753
1771
|
}
|
|
1754
1772
|
if (maxZoom !== void 0) {
|
|
1755
1773
|
map.setMaxZoom(maxZoom);
|
|
1756
1774
|
}
|
|
1757
1775
|
if (minZoom !== void 0) {
|
|
1758
|
-
this.
|
|
1759
|
-
map.setMinZoom(minZoom);
|
|
1776
|
+
this._updateMinZoomForBounds(minZoom);
|
|
1760
1777
|
}
|
|
1761
1778
|
}
|
|
1762
1779
|
}
|
|
@@ -1890,22 +1907,18 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
|
|
|
1890
1907
|
this._unselectCb.length = 0;
|
|
1891
1908
|
this._unselectCb.push(cb);
|
|
1892
1909
|
}
|
|
1893
|
-
_watchSizeChangeToUpdateMinZoom(
|
|
1910
|
+
_watchSizeChangeToUpdateMinZoom() {
|
|
1894
1911
|
this._stopWatchSizeChangeToUpdateMinZoom();
|
|
1895
1912
|
const container = this.getContainer();
|
|
1896
1913
|
const map = this.map;
|
|
1897
1914
|
if (container && map && window.ResizeObserver) {
|
|
1898
1915
|
this._resizeObserver = new ResizeObserver(() => {
|
|
1899
|
-
|
|
1916
|
+
this._updateMinZoomForBounds();
|
|
1900
1917
|
});
|
|
1901
1918
|
this._resizeObserver.observe(container);
|
|
1902
1919
|
}
|
|
1903
1920
|
}
|
|
1904
1921
|
_stopWatchSizeChangeToUpdateMinZoom() {
|
|
1905
|
-
const map = this.map;
|
|
1906
|
-
if (map) {
|
|
1907
|
-
map.setMinZoom(0);
|
|
1908
|
-
}
|
|
1909
1922
|
if (this._resizeObserver) {
|
|
1910
1923
|
this._resizeObserver.disconnect();
|
|
1911
1924
|
this._resizeObserver = void 0;
|
|
@@ -1932,6 +1945,28 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
|
|
|
1932
1945
|
}
|
|
1933
1946
|
}
|
|
1934
1947
|
}
|
|
1948
|
+
_updateMinZoomForBounds(zoom) {
|
|
1949
|
+
var _a;
|
|
1950
|
+
const map = this.map;
|
|
1951
|
+
if (map) {
|
|
1952
|
+
zoom = zoom != null ? zoom : map.getMinZoom();
|
|
1953
|
+
const defaultBounds = latLngBounds(
|
|
1954
|
+
latLng(-90, -18e3),
|
|
1955
|
+
latLng(90, 18e3)
|
|
1956
|
+
);
|
|
1957
|
+
const maxBounds = (_a = map.options.maxBounds) != null ? _a : defaultBounds;
|
|
1958
|
+
if (maxBounds !== void 0) {
|
|
1959
|
+
map.setMinZoom(0);
|
|
1960
|
+
const boundsZoom = map.getBoundsZoom(maxBounds, true);
|
|
1961
|
+
const minZoom = zoom < boundsZoom ? boundsZoom : zoom;
|
|
1962
|
+
map.options.minZoom = minZoom;
|
|
1963
|
+
map.setMinZoom(minZoom);
|
|
1964
|
+
if (map.getZoom() < minZoom) {
|
|
1965
|
+
map.setZoom(minZoom);
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1935
1970
|
};
|
|
1936
1971
|
__publicField(_LeafletMapAdapter, "layerAdapters", {
|
|
1937
1972
|
GEOJSON: GeoJsonAdapter,
|