@nextgis/leaflet-map-adapter 3.0.0-alpha.1 → 3.0.0-alpha.13

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
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  import { Control, ControlOptions, Map, Layer, GridLayer, LeafletMouseEvent } from 'leaflet';
4
3
  import { AttributionControlOptions, MapAdapter, LayerAdapter, MapOptions, ViewOptions, FitOptions, MapControl, CreateControlOptions, ButtonControlOptions, LocateOptions, LocationEvents, Locate } from '@nextgis/webmap';
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 3.0.0-alpha.1; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 3.0.0-alpha.13; author: NextGIS */
2
2
  var domain;
3
3
 
4
4
  // This constructor is used to store event handlers. Instantiating this is
@@ -29,7 +29,7 @@ EventEmitter.init = function() {
29
29
  this.domain = null;
30
30
  if (EventEmitter.usingDomains) {
31
31
  // if there is an active domain, then attach to it.
32
- if (domain.active ) ;
32
+ if (domain.active) ;
33
33
  }
34
34
 
35
35
  if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -14631,10 +14631,6 @@ function createButtonControl(options, map) {
14631
14631
  );
14632
14632
  }
14633
14633
 
14634
- function defined(val) {
14635
- return val !== void 0 && val !== null;
14636
- }
14637
-
14638
14634
  function debounce(cb, wait = 10) {
14639
14635
  let timeoutId;
14640
14636
  function wrapper(...args) {
@@ -14653,6 +14649,25 @@ function debounce(cb, wait = 10) {
14653
14649
  return wrapper;
14654
14650
  }
14655
14651
 
14652
+ function defined(val) {
14653
+ return val !== void 0 && val !== null;
14654
+ }
14655
+
14656
+ function updateUrlParams(urlStr, params) {
14657
+ const url = new URL(urlStr);
14658
+ const searchParams = new URLSearchParams(url.search);
14659
+ Object.entries(params).forEach(([key, value]) => {
14660
+ if (value === void 0) {
14661
+ searchParams.delete(key);
14662
+ } else {
14663
+ searchParams.set(key, value);
14664
+ }
14665
+ });
14666
+ searchParams.set("timestamp", String((/* @__PURE__ */ new Date()).getTime()));
14667
+ const newSearch = [...searchParams.entries()].map(([key, value]) => `${key}=${value}`).join("&");
14668
+ return `${url.origin}${url.pathname}?${newSearch}`;
14669
+ }
14670
+
14656
14671
  function boundsToArray(bounds) {
14657
14672
  const ne = bounds.getNorthEast();
14658
14673
  const sw = bounds.getSouthWest();
@@ -14918,8 +14933,8 @@ function isPaintCallback(paint) {
14918
14933
  }
14919
14934
 
14920
14935
  var __defProp$9 = Object.defineProperty;
14921
- var __defProps$4 = Object.defineProperties;
14922
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
14936
+ var __defProps$5 = Object.defineProperties;
14937
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
14923
14938
  var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
14924
14939
  var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
14925
14940
  var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
@@ -14935,7 +14950,7 @@ var __spreadValues$6 = (a, b) => {
14935
14950
  }
14936
14951
  return a;
14937
14952
  };
14938
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
14953
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
14939
14954
  var __objRest$2 = (source, exclude) => {
14940
14955
  var target = {};
14941
14956
  for (var prop in source)
@@ -15030,7 +15045,7 @@ class GeoJsonPaint {
15030
15045
  if (html) {
15031
15046
  element.innerHTML = html;
15032
15047
  }
15033
- const divIcon = new leafletSrcExports.DivIcon(__spreadProps$4(__spreadValues$6({
15048
+ const divIcon = new leafletSrcExports.DivIcon(__spreadProps$5(__spreadValues$6({
15034
15049
  className: ""
15035
15050
  }, toLIconOpt), {
15036
15051
  html: element
@@ -15079,8 +15094,8 @@ class GeoJsonPaint {
15079
15094
  }
15080
15095
 
15081
15096
  var __defProp$8 = Object.defineProperty;
15082
- var __defProps$3 = Object.defineProperties;
15083
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
15097
+ var __defProps$4 = Object.defineProperties;
15098
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
15084
15099
  var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
15085
15100
  var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
15086
15101
  var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
@@ -15096,7 +15111,7 @@ var __spreadValues$5 = (a, b) => {
15096
15111
  }
15097
15112
  return a;
15098
15113
  };
15099
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
15114
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
15100
15115
  var __publicField$5 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
15101
15116
  var __async = (__this, __arguments, generator) => {
15102
15117
  return new Promise((resolve, reject) => {
@@ -15145,7 +15160,7 @@ class GeoJsonAdapter extends BaseAdapter {
15145
15160
  addLayer(options) {
15146
15161
  Object.assign(this.options, options);
15147
15162
  this.paint = options.paint;
15148
- this.layer = new leafletSrcExports.FeatureGroup([], __spreadProps$3(__spreadValues$5({}, options.nativeOptions), {
15163
+ this.layer = new leafletSrcExports.FeatureGroup([], __spreadProps$4(__spreadValues$5({}, options.nativeOptions), {
15149
15164
  pane: this.pane
15150
15165
  }));
15151
15166
  this.selectedPaint = options.selectedPaint;
@@ -15444,13 +15459,15 @@ class GeoJsonAdapter extends BaseAdapter {
15444
15459
  const unselectOnClose = (_b = (_a = this.options.popupOptions) == null ? void 0 : _a.unselectOnClose) != null ? _b : true;
15445
15460
  if (unselectOnClose) {
15446
15461
  const p = layer.getPopup();
15447
- p && p.once(
15448
- "remove",
15449
- () => {
15450
- close();
15451
- },
15452
- this
15453
- );
15462
+ if (p) {
15463
+ p.once(
15464
+ "remove",
15465
+ () => {
15466
+ close();
15467
+ },
15468
+ this
15469
+ );
15470
+ }
15454
15471
  }
15455
15472
  this._openedPopup.push([popup, _closeHandlers, def]);
15456
15473
  popup.openPopup(latLng);
@@ -15495,7 +15512,7 @@ class GeoJsonAdapter extends BaseAdapter {
15495
15512
  if (feature) {
15496
15513
  return this._paint.preparePaint(__spreadValues$5(__spreadValues$5({}, PAINT), paint(feature)));
15497
15514
  } else {
15498
- return this._paint.preparePaint(__spreadProps$3(__spreadValues$5({}, PAINT), { type: "path" }));
15515
+ return this._paint.preparePaint(__spreadProps$4(__spreadValues$5({}, PAINT), { type: "path" }));
15499
15516
  }
15500
15517
  }
15501
15518
  };
@@ -15818,6 +15835,7 @@ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key,
15818
15835
  var __publicField$2 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
15819
15836
  class ImageLayer extends leafletSrcExports.Layer {
15820
15837
  constructor(url, options) {
15838
+ var _a;
15821
15839
  super(options);
15822
15840
  __publicField$2(this, "defaultWmsParams", {
15823
15841
  service: "WMS",
@@ -15835,6 +15853,7 @@ class ImageLayer extends leafletSrcExports.Layer {
15835
15853
  opacity: 1,
15836
15854
  isBack: false,
15837
15855
  minZoom: 0,
15856
+ maxZoom: void 0,
15838
15857
  pane: "tilePane",
15839
15858
  headers: null,
15840
15859
  withCredentials: false,
@@ -15858,7 +15877,11 @@ class ImageLayer extends leafletSrcExports.Layer {
15858
15877
  }
15859
15878
  }
15860
15879
  leafletSrcExports.Util.setOptions(this, opts);
15861
- this.wmsParams = leafletSrcExports.Util.extend({}, this.defaultWmsParams, params);
15880
+ this.wmsParams = leafletSrcExports.Util.extend(
15881
+ {},
15882
+ this.defaultWmsParams,
15883
+ (_a = params == null ? void 0 : params.params) != null ? _a : {}
15884
+ );
15862
15885
  }
15863
15886
  setParams(params) {
15864
15887
  leafletSrcExports.Util.extend(this.wmsParams, params);
@@ -16006,6 +16029,8 @@ class ImageLayer extends leafletSrcExports.Layer {
16006
16029
  }
16007
16030
 
16008
16031
  var __defProp$4 = Object.defineProperty;
16032
+ var __defProps$3 = Object.defineProperties;
16033
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
16009
16034
  var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
16010
16035
  var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
16011
16036
  var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
@@ -16021,6 +16046,7 @@ var __spreadValues$4 = (a, b) => {
16021
16046
  }
16022
16047
  return a;
16023
16048
  };
16049
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
16024
16050
  var __publicField$1 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
16025
16051
  class ImageAdapter extends BaseAdapter {
16026
16052
  constructor() {
@@ -16028,15 +16054,21 @@ class ImageAdapter extends BaseAdapter {
16028
16054
  __publicField$1(this, "layer");
16029
16055
  }
16030
16056
  addLayer(options) {
16057
+ var _a;
16031
16058
  const url = options && options.url;
16032
16059
  if (url) {
16033
- options = __spreadValues$4({ transparent: true }, options);
16034
16060
  const updateWmsParamsFromOpt = options.updateWmsParams;
16035
- this.layer = new ImageLayer(url, __spreadValues$4(__spreadValues$4(__spreadValues$4({
16061
+ this.layer = new ImageLayer(url, __spreadProps$3(__spreadValues$4(__spreadValues$4(__spreadValues$4({
16036
16062
  pane: this.pane,
16037
16063
  headers: options.headers,
16038
16064
  setViewDelay: options.setViewDelay
16039
- }, options), options.params), options.nativeOptions));
16065
+ }, __spreadProps$3(__spreadValues$4({
16066
+ transparent: true
16067
+ }, options), {
16068
+ opacity: (_a = options.opacity) != null ? _a : void 0
16069
+ })), options.params), options.nativeOptions), {
16070
+ maxZoom: 12
16071
+ }));
16040
16072
  if (updateWmsParamsFromOpt) {
16041
16073
  const updateWmsParams = this.layer.updateWmsParams;
16042
16074
  this.layer.updateWmsParams = function(map) {
@@ -16047,6 +16079,13 @@ class ImageAdapter extends BaseAdapter {
16047
16079
  return this.layer;
16048
16080
  }
16049
16081
  }
16082
+ updateLayer(options) {
16083
+ if (this.layer) {
16084
+ const params = (options == null ? void 0 : options.params) || {};
16085
+ leafletSrcExports.Util.extend(this.layer.wmsParams, params);
16086
+ this.layer.update();
16087
+ }
16088
+ }
16050
16089
  }
16051
16090
  __publicField$1(ImageAdapter, "queue", imageQueue);
16052
16091
 
@@ -16170,13 +16209,12 @@ class TileAdapter extends BaseAdapter {
16170
16209
  }
16171
16210
  }
16172
16211
  }
16173
- updateLayer() {
16212
+ updateLayer(options) {
16174
16213
  if (this.layer) {
16175
16214
  const currentUrl = this.layer._url;
16176
- const timestamp = (/* @__PURE__ */ new Date()).getTime();
16177
- const separator = currentUrl.includes("?") ? "&" : "?";
16178
- const newUrl = currentUrl.replace(/(\?|&)timestamp=\d*/g, "") + separator + `timestamp=${timestamp}`;
16179
- this.layer.setUrl(newUrl);
16215
+ if (options == null ? void 0 : options.params) {
16216
+ this.layer.setUrl(updateUrlParams(currentUrl, options.params));
16217
+ }
16180
16218
  this.layer.redraw();
16181
16219
  }
16182
16220
  }
@@ -16494,7 +16532,7 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
16494
16532
  }
16495
16533
  }
16496
16534
  removeLayer(layer) {
16497
- layer && layer.remove && layer.remove();
16535
+ if (layer && layer.remove) layer.remove();
16498
16536
  }
16499
16537
  showLayer(layer) {
16500
16538
  if (this.map) {