@nextgis/leaflet-map-adapter 2.0.0 → 2.1.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/README.md CHANGED
@@ -7,9 +7,7 @@ WebMap adapter to use [Leaflet](https://leafletjs.com/) GIS framework.
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- $ npm install --save-dev leaflet @nextgis/leaflet-map-adapter
11
- # or
12
- $ yarn add leaflet @nextgis/leaflet-map-adapter
10
+ npm install leaflet @nextgis/leaflet-map-adapter
13
11
  ```
14
12
 
15
13
  ## Usage
package/lib/index.d.ts CHANGED
@@ -63,6 +63,7 @@ declare class LeafletMapAdapter implements MapAdapter<Map, any, Control> {
63
63
  private _watchSizeChangeToUpdateMinZoom;
64
64
  private _stopWatchSizeChangeToUpdateMinZoom;
65
65
  private _addMapListeners;
66
+ private _updateMinZoomForBounds;
66
67
  }
67
68
 
68
69
  export { LeafletMapAdapter as default };
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 2.0.0; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 2.1.0; author: NextGIS */
2
2
  var domain;
3
3
 
4
4
  // This constructor is used to store event handlers. Instantiating this is
@@ -16066,6 +16066,16 @@ class TileAdapter extends BaseAdapter {
16066
16066
  }
16067
16067
  }
16068
16068
  }
16069
+ updateLayer() {
16070
+ if (this.layer) {
16071
+ const currentUrl = this.layer._url;
16072
+ const timestamp = (/* @__PURE__ */ new Date()).getTime();
16073
+ const separator = currentUrl.includes("?") ? "&" : "?";
16074
+ const newUrl = currentUrl.replace(/(\?|&)timestamp=\d*/g, "") + separator + `timestamp=${timestamp}`;
16075
+ this.layer.setUrl(newUrl);
16076
+ this.layer.redraw();
16077
+ }
16078
+ }
16069
16079
  }
16070
16080
 
16071
16081
  var __defProp$2 = Object.defineProperty;
@@ -16233,6 +16243,8 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
16233
16243
  center: center && [center[1], center[0]],
16234
16244
  zoom
16235
16245
  }, mapAdapterOptions));
16246
+ this._updateMinZoomForBounds(minZoom);
16247
+ this._watchSizeChangeToUpdateMinZoom();
16236
16248
  const defPane = this.map.createPane("order-0");
16237
16249
  this.map._addUnselectCb = (def) => {
16238
16250
  this._addUnselectCb(def);
@@ -16296,19 +16308,17 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
16296
16308
  if (maxBounds) {
16297
16309
  const b = arrayToBoundsExpression(maxBounds);
16298
16310
  map.setMaxBounds(b);
16299
- map.setMinZoom(map.getBoundsZoom(b));
16300
- this._watchSizeChangeToUpdateMinZoom(b);
16311
+ this._updateMinZoomForBounds();
16301
16312
  } else {
16302
16313
  map.setMaxBounds(null);
16303
- this._stopWatchSizeChangeToUpdateMinZoom();
16314
+ this._updateMinZoomForBounds();
16304
16315
  }
16305
16316
  }
16306
16317
  if (maxZoom !== void 0) {
16307
16318
  map.setMaxZoom(maxZoom);
16308
16319
  }
16309
16320
  if (minZoom !== void 0) {
16310
- this._stopWatchSizeChangeToUpdateMinZoom();
16311
- map.setMinZoom(minZoom);
16321
+ this._updateMinZoomForBounds(minZoom);
16312
16322
  }
16313
16323
  }
16314
16324
  }
@@ -16442,22 +16452,18 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
16442
16452
  this._unselectCb.length = 0;
16443
16453
  this._unselectCb.push(cb);
16444
16454
  }
16445
- _watchSizeChangeToUpdateMinZoom(bounds) {
16455
+ _watchSizeChangeToUpdateMinZoom() {
16446
16456
  this._stopWatchSizeChangeToUpdateMinZoom();
16447
16457
  const container = this.getContainer();
16448
16458
  const map = this.map;
16449
16459
  if (container && map && window.ResizeObserver) {
16450
16460
  this._resizeObserver = new ResizeObserver(() => {
16451
- map.setMinZoom(map.getBoundsZoom(bounds));
16461
+ this._updateMinZoomForBounds();
16452
16462
  });
16453
16463
  this._resizeObserver.observe(container);
16454
16464
  }
16455
16465
  }
16456
16466
  _stopWatchSizeChangeToUpdateMinZoom() {
16457
- const map = this.map;
16458
- if (map) {
16459
- map.setMinZoom(0);
16460
- }
16461
16467
  if (this._resizeObserver) {
16462
16468
  this._resizeObserver.disconnect();
16463
16469
  this._resizeObserver = void 0;
@@ -16484,6 +16490,28 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
16484
16490
  }
16485
16491
  }
16486
16492
  }
16493
+ _updateMinZoomForBounds(zoom) {
16494
+ var _a;
16495
+ const map = this.map;
16496
+ if (map) {
16497
+ zoom = zoom != null ? zoom : map.getMinZoom();
16498
+ const defaultBounds = leafletSrcExports.latLngBounds(
16499
+ leafletSrcExports.latLng(-90, -18e3),
16500
+ leafletSrcExports.latLng(90, 18e3)
16501
+ );
16502
+ const maxBounds = (_a = map.options.maxBounds) != null ? _a : defaultBounds;
16503
+ if (maxBounds !== void 0) {
16504
+ map.setMinZoom(0);
16505
+ const boundsZoom = map.getBoundsZoom(maxBounds, true);
16506
+ const minZoom = zoom < boundsZoom ? boundsZoom : zoom;
16507
+ map.options.minZoom = minZoom;
16508
+ map.setMinZoom(minZoom);
16509
+ if (map.getZoom() < minZoom) {
16510
+ map.setZoom(minZoom);
16511
+ }
16512
+ }
16513
+ }
16514
+ }
16487
16515
  };
16488
16516
  __publicField(_LeafletMapAdapter, "layerAdapters", {
16489
16517
  GEOJSON: GeoJsonAdapter,