@nextgis/leaflet-map-adapter 1.8.4 → 1.9.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 CHANGED
@@ -20,6 +20,7 @@ import { Map as Map_2 } from 'leaflet';
20
20
  import type { MapAdapter } from '@nextgis/webmap';
21
21
  import type { MapControl } from '@nextgis/webmap';
22
22
  import type { MapOptions } from '@nextgis/webmap';
23
+ import type { ViewOptions } from '@nextgis/webmap';
23
24
 
24
25
  declare class AttributionControl extends Control.Attribution {
25
26
  constructor(options: AttributionControlOptions & ControlOptions);
@@ -52,12 +53,13 @@ declare class LeafletMapAdapter implements MapAdapter<Map_2, any, Control> {
52
53
  getControlContainer(): HTMLElement;
53
54
  setCursor(cursor: string): void;
54
55
  setView(lngLat: LngLatArray, zoom?: number): void;
56
+ setView(options: ViewOptions): void;
55
57
  setCenter(lngLat: LngLatArray): void;
56
58
  getCenter(): LngLatArray | undefined;
57
59
  setZoom(zoom: number): void;
58
60
  getZoom(): number | undefined;
59
61
  getBounds(): LngLatBoundsArray | undefined;
60
- fitBounds(e: LngLatBoundsArray, options?: FitOptions): void;
62
+ fitBounds(bounds: LngLatBoundsArray, options?: FitOptions): void;
61
63
  getLayerAdapter(name: string): Type<LayerAdapter<L.Map, any, any>>;
62
64
  createControl(control: MapControl, options: CreateControlOptions): L.Control;
63
65
  createButtonControl(options: ButtonControlOptions): L.Control;
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 1.8.4; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 1.9.0; author: NextGIS */
2
2
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3
3
 
4
4
  var events = {exports: {}};
@@ -15087,7 +15087,7 @@ class GeoJsonAdapter extends BaseAdapter {
15087
15087
  }
15088
15088
  }
15089
15089
  }
15090
- async _openPopup(def, options = {}, type, latlng) {
15090
+ async _openPopup(def, options = {}, type, latLng) {
15091
15091
  var _a, _b;
15092
15092
  const { feature, layer } = def;
15093
15093
  const { minWidth, autoPan, maxWidth, closeButton: closeButton_, } = { minWidth: 300, ...options };
@@ -15139,7 +15139,7 @@ class GeoJsonAdapter extends BaseAdapter {
15139
15139
  }, this);
15140
15140
  }
15141
15141
  this._openedPopup.push([popup, _closeHandlers, def]);
15142
- popup.openPopup(latlng);
15142
+ popup.openPopup(latLng);
15143
15143
  }
15144
15144
  }
15145
15145
  _removePopup(popup) {
@@ -15301,15 +15301,19 @@ class GeoJsonAdapter extends BaseAdapter {
15301
15301
  }
15302
15302
  }
15303
15303
  this._handleMouseEvents(layer);
15304
- if (popup) {
15305
- this._openPopup({
15306
- target: this,
15307
- layer,
15308
- feature,
15309
- ...createFeaturePositionOptions(feature),
15310
- }, popupOptions, 'api');
15311
- }
15312
- this._updateTooltip({ layer, feature });
15304
+ // The timeout is needed to display the popup immediately when adding a layer to the map.
15305
+ // Without a timeout, the layer may not yet have a _map object
15306
+ setTimeout(() => {
15307
+ if (popup) {
15308
+ this._openPopup({
15309
+ target: this,
15310
+ layer,
15311
+ feature,
15312
+ ...createFeaturePositionOptions(feature),
15313
+ }, popupOptions, 'api');
15314
+ }
15315
+ this._updateTooltip({ layer, feature });
15316
+ });
15313
15317
  }
15314
15318
  }
15315
15319
  }
@@ -15885,6 +15889,15 @@ class OsmAdapter extends TileAdapter {
15885
15889
  }
15886
15890
  }
15887
15891
 
15892
+ function arrayToBoundsExpression(bounds) {
15893
+ const e = bounds;
15894
+ // top, left, bottom, right
15895
+ return [
15896
+ [e[3], e[0]],
15897
+ [e[1], e[2]],
15898
+ ];
15899
+ }
15900
+
15888
15901
  class LeafletMapAdapter$1 {
15889
15902
  constructor() {
15890
15903
  this.options = { target: 'map' };
@@ -15908,10 +15921,7 @@ class LeafletMapAdapter$1 {
15908
15921
  this.map = new leafletSrc.exports.Map(this.options.target, {
15909
15922
  attributionControl: false,
15910
15923
  zoomControl: false,
15911
- maxBounds: mb && [
15912
- [mb[1], mb[0]],
15913
- [mb[3], mb[2]],
15914
- ],
15924
+ maxBounds: mb ? arrayToBoundsExpression(mb) : undefined,
15915
15925
  maxZoom,
15916
15926
  minZoom,
15917
15927
  center: center && [center[1], center[0]],
@@ -15948,14 +15958,52 @@ class LeafletMapAdapter$1 {
15948
15958
  this.map.getContainer().style.cursor = cursor;
15949
15959
  }
15950
15960
  }
15951
- setView(lngLat, zoom) {
15952
- const [lng, lat] = lngLat;
15953
- if (this.map) {
15954
- if (typeof zoom === 'number') {
15955
- this.map.setView([lat, lng], zoom, { animate: false });
15961
+ setView(lngLatOrOpt, zoom) {
15962
+ const map = this.map;
15963
+ if (!map)
15964
+ return;
15965
+ if (Array.isArray(lngLatOrOpt)) {
15966
+ const lngLat = lngLatOrOpt;
15967
+ const [lng, lat] = lngLat;
15968
+ if (this.map) {
15969
+ if (typeof zoom === 'number') {
15970
+ this.map.setView([lat, lng], zoom, { animate: false });
15971
+ }
15972
+ else {
15973
+ this.setCenter([lng, lat]);
15974
+ }
15975
+ }
15976
+ }
15977
+ else {
15978
+ const { zoom, center, maxBounds, bounds, minZoom, maxZoom } = lngLatOrOpt;
15979
+ if (center && zoom !== undefined) {
15980
+ this.setView(center, zoom);
15956
15981
  }
15957
15982
  else {
15958
- this.setCenter([lng, lat]);
15983
+ if (zoom !== undefined) {
15984
+ this.setZoom(zoom);
15985
+ }
15986
+ if (center) {
15987
+ this.setCenter(center);
15988
+ }
15989
+ }
15990
+ if (bounds) {
15991
+ this.fitBounds(bounds);
15992
+ }
15993
+ if (maxBounds !== undefined) {
15994
+ if (maxBounds) {
15995
+ map.setMaxBounds(arrayToBoundsExpression(maxBounds));
15996
+ }
15997
+ else {
15998
+ // @ts-ignore `null` works for unset maxBounds, but not in typing
15999
+ map.setMaxBounds(null);
16000
+ }
16001
+ }
16002
+ if (maxZoom !== undefined) {
16003
+ map.setMaxZoom(maxZoom);
16004
+ }
16005
+ if (minZoom !== undefined) {
16006
+ map.setMinZoom(minZoom);
15959
16007
  }
15960
16008
  }
15961
16009
  }
@@ -15990,7 +16038,7 @@ class LeafletMapAdapter$1 {
15990
16038
  return [sw.lng, sw.lat, ne.lng, ne.lat];
15991
16039
  }
15992
16040
  // [west, south, east, north]
15993
- fitBounds(e, options = {}) {
16041
+ fitBounds(bounds, options = {}) {
15994
16042
  if (this.map) {
15995
16043
  const { maxZoom, offset, padding } = options;
15996
16044
  const opt = {};
@@ -16003,11 +16051,7 @@ class LeafletMapAdapter$1 {
16003
16051
  if (offset) {
16004
16052
  opt.padding = offset;
16005
16053
  }
16006
- // top, left, bottom, right
16007
- this.map.fitBounds([
16008
- [e[3], e[0]],
16009
- [e[1], e[2]],
16010
- ], opt);
16054
+ this.map.fitBounds(arrayToBoundsExpression(bounds), opt);
16011
16055
  }
16012
16056
  }
16013
16057
  getLayerAdapter(name) {