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

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.5; 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) {
@@ -14653,6 +14653,21 @@ function debounce(cb, wait = 10) {
14653
14653
  return wrapper;
14654
14654
  }
14655
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;
@@ -15495,7 +15510,7 @@ class GeoJsonAdapter extends BaseAdapter {
15495
15510
  if (feature) {
15496
15511
  return this._paint.preparePaint(__spreadValues$5(__spreadValues$5({}, PAINT), paint(feature)));
15497
15512
  } else {
15498
- return this._paint.preparePaint(__spreadProps$3(__spreadValues$5({}, PAINT), { type: "path" }));
15513
+ return this._paint.preparePaint(__spreadProps$4(__spreadValues$5({}, PAINT), { type: "path" }));
15499
15514
  }
15500
15515
  }
15501
15516
  };
@@ -15818,6 +15833,7 @@ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key,
15818
15833
  var __publicField$2 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
15819
15834
  class ImageLayer extends leafletSrcExports.Layer {
15820
15835
  constructor(url, options) {
15836
+ var _a;
15821
15837
  super(options);
15822
15838
  __publicField$2(this, "defaultWmsParams", {
15823
15839
  service: "WMS",
@@ -15835,6 +15851,7 @@ class ImageLayer extends leafletSrcExports.Layer {
15835
15851
  opacity: 1,
15836
15852
  isBack: false,
15837
15853
  minZoom: 0,
15854
+ maxZoom: void 0,
15838
15855
  pane: "tilePane",
15839
15856
  headers: null,
15840
15857
  withCredentials: false,
@@ -15858,7 +15875,11 @@ class ImageLayer extends leafletSrcExports.Layer {
15858
15875
  }
15859
15876
  }
15860
15877
  leafletSrcExports.Util.setOptions(this, opts);
15861
- this.wmsParams = leafletSrcExports.Util.extend({}, this.defaultWmsParams, params);
15878
+ this.wmsParams = leafletSrcExports.Util.extend(
15879
+ {},
15880
+ this.defaultWmsParams,
15881
+ (_a = params == null ? void 0 : params.params) != null ? _a : {}
15882
+ );
15862
15883
  }
15863
15884
  setParams(params) {
15864
15885
  leafletSrcExports.Util.extend(this.wmsParams, params);
@@ -16006,6 +16027,8 @@ class ImageLayer extends leafletSrcExports.Layer {
16006
16027
  }
16007
16028
 
16008
16029
  var __defProp$4 = Object.defineProperty;
16030
+ var __defProps$3 = Object.defineProperties;
16031
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
16009
16032
  var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
16010
16033
  var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
16011
16034
  var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
@@ -16021,6 +16044,7 @@ var __spreadValues$4 = (a, b) => {
16021
16044
  }
16022
16045
  return a;
16023
16046
  };
16047
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
16024
16048
  var __publicField$1 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
16025
16049
  class ImageAdapter extends BaseAdapter {
16026
16050
  constructor() {
@@ -16028,15 +16052,21 @@ class ImageAdapter extends BaseAdapter {
16028
16052
  __publicField$1(this, "layer");
16029
16053
  }
16030
16054
  addLayer(options) {
16055
+ var _a;
16031
16056
  const url = options && options.url;
16032
16057
  if (url) {
16033
- options = __spreadValues$4({ transparent: true }, options);
16034
16058
  const updateWmsParamsFromOpt = options.updateWmsParams;
16035
- this.layer = new ImageLayer(url, __spreadValues$4(__spreadValues$4(__spreadValues$4({
16059
+ this.layer = new ImageLayer(url, __spreadProps$3(__spreadValues$4(__spreadValues$4(__spreadValues$4({
16036
16060
  pane: this.pane,
16037
16061
  headers: options.headers,
16038
16062
  setViewDelay: options.setViewDelay
16039
- }, options), options.params), options.nativeOptions));
16063
+ }, __spreadProps$3(__spreadValues$4({
16064
+ transparent: true
16065
+ }, options), {
16066
+ opacity: (_a = options.opacity) != null ? _a : void 0
16067
+ })), options.params), options.nativeOptions), {
16068
+ maxZoom: 12
16069
+ }));
16040
16070
  if (updateWmsParamsFromOpt) {
16041
16071
  const updateWmsParams = this.layer.updateWmsParams;
16042
16072
  this.layer.updateWmsParams = function(map) {
@@ -16047,6 +16077,13 @@ class ImageAdapter extends BaseAdapter {
16047
16077
  return this.layer;
16048
16078
  }
16049
16079
  }
16080
+ updateLayer(options) {
16081
+ if (this.layer) {
16082
+ const params = (options == null ? void 0 : options.params) || {};
16083
+ leafletSrcExports.Util.extend(this.layer.wmsParams, params);
16084
+ this.layer.update();
16085
+ }
16086
+ }
16050
16087
  }
16051
16088
  __publicField$1(ImageAdapter, "queue", imageQueue);
16052
16089
 
@@ -16170,13 +16207,12 @@ class TileAdapter extends BaseAdapter {
16170
16207
  }
16171
16208
  }
16172
16209
  }
16173
- updateLayer() {
16210
+ updateLayer(options) {
16174
16211
  if (this.layer) {
16175
16212
  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);
16213
+ if (options == null ? void 0 : options.params) {
16214
+ this.layer.setUrl(updateUrlParams(currentUrl, options.params));
16215
+ }
16180
16216
  this.layer.redraw();
16181
16217
  }
16182
16218
  }