@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.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 2.0.2; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 2.2.0; author: NextGIS */
2
2
  var LeafletMapAdapter = (function () {
3
3
  'use strict';
4
4
 
@@ -15688,30 +15688,32 @@ var LeafletMapAdapter = (function () {
15688
15688
  class ImageOverlay extends leafletSrcExports.ImageOverlay {
15689
15689
  constructor(imageUrl, bounds, options) {
15690
15690
  super(imageUrl, bounds, options);
15691
- __publicField$3(this, "_abort", []);
15691
+ __publicField$3(this, "_aborter");
15692
15692
  }
15693
15693
  cancelLoad() {
15694
- if (this._abort) {
15695
- this._abort.forEach((x) => x());
15696
- this._abort = [];
15694
+ if (this._aborter) {
15695
+ this._aborter();
15696
+ this._aborter = void 0;
15697
15697
  }
15698
15698
  }
15699
15699
  _initImage() {
15700
15700
  super._initImage();
15701
15701
  const headers = this.options.headers;
15702
+ const img = this._image;
15703
+ const src = img.src;
15702
15704
  if (headers) {
15703
- const img = this._image;
15704
- const src = img.src;
15705
15705
  img.src = "";
15706
- this._abort.push(
15707
- callAjax(
15708
- src,
15709
- (response) => {
15710
- img.src = response;
15711
- },
15712
- headers
15713
- )
15706
+ this._aborter = callAjax(
15707
+ src,
15708
+ (response) => {
15709
+ img.src = response;
15710
+ },
15711
+ headers
15714
15712
  );
15713
+ } else {
15714
+ this._aborter = () => {
15715
+ img.setAttribute("src", leafletSrcExports.Util.emptyImageUrl);
15716
+ };
15715
15717
  }
15716
15718
  }
15717
15719
  }
@@ -15750,6 +15752,7 @@ var LeafletMapAdapter = (function () {
15750
15752
  __publicField$2(this, "_url");
15751
15753
  __publicField$2(this, "_currentUrl");
15752
15754
  __publicField$2(this, "_currentOverlay");
15755
+ __publicField$2(this, "_loadedOverlay");
15753
15756
  this._url = url;
15754
15757
  const params = {};
15755
15758
  const opts = {};
@@ -15803,15 +15806,18 @@ var LeafletMapAdapter = (function () {
15803
15806
  this._currentUrl = url;
15804
15807
  const viewPortBuffer = this.options.viewPortBuffer || 0;
15805
15808
  const bounds = this._map.getBounds().pad(viewPortBuffer);
15809
+ if (this._loadedOverlay) {
15810
+ this._loadedOverlay.cancelLoad();
15811
+ this._loadedOverlay.off("load");
15812
+ this._loadedOverlay = void 0;
15813
+ }
15806
15814
  const overlay = new ImageOverlay(url, bounds, {
15807
15815
  opacity: 0,
15808
15816
  pane: this.options.pane,
15809
15817
  headers: this.options.headers
15810
15818
  });
15811
15819
  overlay.addTo(this._map);
15812
- if (this._currentOverlay) {
15813
- this._currentOverlay.cancelLoad();
15814
- }
15820
+ this._loadedOverlay = overlay;
15815
15821
  overlay.once(
15816
15822
  "load",
15817
15823
  () => {
@@ -15824,6 +15830,7 @@ var LeafletMapAdapter = (function () {
15824
15830
  } else if (this._currentOverlay) {
15825
15831
  this._map.removeLayer(this._currentOverlay);
15826
15832
  }
15833
+ this._loadedOverlay = void 0;
15827
15834
  this._currentOverlay = overlay;
15828
15835
  overlay.setOpacity(
15829
15836
  this.options.opacity !== void 0 ? this.options.opacity : 1
@@ -16069,6 +16076,16 @@ var LeafletMapAdapter = (function () {
16069
16076
  }
16070
16077
  }
16071
16078
  }
16079
+ updateLayer() {
16080
+ if (this.layer) {
16081
+ const currentUrl = this.layer._url;
16082
+ const timestamp = (/* @__PURE__ */ new Date()).getTime();
16083
+ const separator = currentUrl.includes("?") ? "&" : "?";
16084
+ const newUrl = currentUrl.replace(/(\?|&)timestamp=\d*/g, "") + separator + `timestamp=${timestamp}`;
16085
+ this.layer.setUrl(newUrl);
16086
+ this.layer.redraw();
16087
+ }
16088
+ }
16072
16089
  }
16073
16090
 
16074
16091
  var __defProp$2 = Object.defineProperty;
@@ -16236,6 +16253,8 @@ var LeafletMapAdapter = (function () {
16236
16253
  center: center && [center[1], center[0]],
16237
16254
  zoom
16238
16255
  }, mapAdapterOptions));
16256
+ this._updateMinZoomForBounds(minZoom);
16257
+ this._watchSizeChangeToUpdateMinZoom();
16239
16258
  const defPane = this.map.createPane("order-0");
16240
16259
  this.map._addUnselectCb = (def) => {
16241
16260
  this._addUnselectCb(def);
@@ -16299,19 +16318,17 @@ var LeafletMapAdapter = (function () {
16299
16318
  if (maxBounds) {
16300
16319
  const b = arrayToBoundsExpression(maxBounds);
16301
16320
  map.setMaxBounds(b);
16302
- map.setMinZoom(map.getBoundsZoom(b));
16303
- this._watchSizeChangeToUpdateMinZoom(b);
16321
+ this._updateMinZoomForBounds();
16304
16322
  } else {
16305
16323
  map.setMaxBounds(null);
16306
- this._stopWatchSizeChangeToUpdateMinZoom();
16324
+ this._updateMinZoomForBounds();
16307
16325
  }
16308
16326
  }
16309
16327
  if (maxZoom !== void 0) {
16310
16328
  map.setMaxZoom(maxZoom);
16311
16329
  }
16312
16330
  if (minZoom !== void 0) {
16313
- this._stopWatchSizeChangeToUpdateMinZoom();
16314
- map.setMinZoom(minZoom);
16331
+ this._updateMinZoomForBounds(minZoom);
16315
16332
  }
16316
16333
  }
16317
16334
  }
@@ -16445,22 +16462,18 @@ var LeafletMapAdapter = (function () {
16445
16462
  this._unselectCb.length = 0;
16446
16463
  this._unselectCb.push(cb);
16447
16464
  }
16448
- _watchSizeChangeToUpdateMinZoom(bounds) {
16465
+ _watchSizeChangeToUpdateMinZoom() {
16449
16466
  this._stopWatchSizeChangeToUpdateMinZoom();
16450
16467
  const container = this.getContainer();
16451
16468
  const map = this.map;
16452
16469
  if (container && map && window.ResizeObserver) {
16453
16470
  this._resizeObserver = new ResizeObserver(() => {
16454
- map.setMinZoom(map.getBoundsZoom(bounds));
16471
+ this._updateMinZoomForBounds();
16455
16472
  });
16456
16473
  this._resizeObserver.observe(container);
16457
16474
  }
16458
16475
  }
16459
16476
  _stopWatchSizeChangeToUpdateMinZoom() {
16460
- const map = this.map;
16461
- if (map) {
16462
- map.setMinZoom(0);
16463
- }
16464
16477
  if (this._resizeObserver) {
16465
16478
  this._resizeObserver.disconnect();
16466
16479
  this._resizeObserver = void 0;
@@ -16487,6 +16500,28 @@ var LeafletMapAdapter = (function () {
16487
16500
  }
16488
16501
  }
16489
16502
  }
16503
+ _updateMinZoomForBounds(zoom) {
16504
+ var _a;
16505
+ const map = this.map;
16506
+ if (map) {
16507
+ zoom = zoom != null ? zoom : map.getMinZoom();
16508
+ const defaultBounds = leafletSrcExports.latLngBounds(
16509
+ leafletSrcExports.latLng(-90, -18e3),
16510
+ leafletSrcExports.latLng(90, 18e3)
16511
+ );
16512
+ const maxBounds = (_a = map.options.maxBounds) != null ? _a : defaultBounds;
16513
+ if (maxBounds !== void 0) {
16514
+ map.setMinZoom(0);
16515
+ const boundsZoom = map.getBoundsZoom(maxBounds, true);
16516
+ const minZoom = zoom < boundsZoom ? boundsZoom : zoom;
16517
+ map.options.minZoom = minZoom;
16518
+ map.setMinZoom(minZoom);
16519
+ if (map.getZoom() < minZoom) {
16520
+ map.setZoom(minZoom);
16521
+ }
16522
+ }
16523
+ }
16524
+ }
16490
16525
  };
16491
16526
  __publicField(_LeafletMapAdapter, "layerAdapters", {
16492
16527
  GEOJSON: GeoJsonAdapter,