@nextgis/leaflet-map-adapter 3.0.0-alpha.0 → 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.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 3.0.0-alpha.0; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 3.0.0-alpha.5; author: NextGIS */
2
2
  var LeafletMapAdapter = (function () {
3
3
  'use strict';
4
4
 
@@ -32,7 +32,7 @@ var LeafletMapAdapter = (function () {
32
32
  this.domain = null;
33
33
  if (EventEmitter.usingDomains) {
34
34
  // if there is an active domain, then attach to it.
35
- if (domain.active ) ;
35
+ if (domain.active) ;
36
36
  }
37
37
 
38
38
  if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -14656,6 +14656,21 @@ var LeafletMapAdapter = (function () {
14656
14656
  return wrapper;
14657
14657
  }
14658
14658
 
14659
+ function updateUrlParams(urlStr, params) {
14660
+ const url = new URL(urlStr);
14661
+ const searchParams = new URLSearchParams(url.search);
14662
+ Object.entries(params).forEach(([key, value]) => {
14663
+ if (value === void 0) {
14664
+ searchParams.delete(key);
14665
+ } else {
14666
+ searchParams.set(key, value);
14667
+ }
14668
+ });
14669
+ searchParams.set("timestamp", String((/* @__PURE__ */ new Date()).getTime()));
14670
+ const newSearch = [...searchParams.entries()].map(([key, value]) => `${key}=${value}`).join("&");
14671
+ return `${url.origin}${url.pathname}?${newSearch}`;
14672
+ }
14673
+
14659
14674
  function boundsToArray(bounds) {
14660
14675
  const ne = bounds.getNorthEast();
14661
14676
  const sw = bounds.getSouthWest();
@@ -14921,8 +14936,8 @@ var LeafletMapAdapter = (function () {
14921
14936
  }
14922
14937
 
14923
14938
  var __defProp$9 = Object.defineProperty;
14924
- var __defProps$4 = Object.defineProperties;
14925
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
14939
+ var __defProps$5 = Object.defineProperties;
14940
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
14926
14941
  var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
14927
14942
  var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
14928
14943
  var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
@@ -14938,7 +14953,7 @@ var LeafletMapAdapter = (function () {
14938
14953
  }
14939
14954
  return a;
14940
14955
  };
14941
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
14956
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
14942
14957
  var __objRest$2 = (source, exclude) => {
14943
14958
  var target = {};
14944
14959
  for (var prop in source)
@@ -15033,7 +15048,7 @@ var LeafletMapAdapter = (function () {
15033
15048
  if (html) {
15034
15049
  element.innerHTML = html;
15035
15050
  }
15036
- const divIcon = new leafletSrcExports.DivIcon(__spreadProps$4(__spreadValues$6({
15051
+ const divIcon = new leafletSrcExports.DivIcon(__spreadProps$5(__spreadValues$6({
15037
15052
  className: ""
15038
15053
  }, toLIconOpt), {
15039
15054
  html: element
@@ -15082,8 +15097,8 @@ var LeafletMapAdapter = (function () {
15082
15097
  }
15083
15098
 
15084
15099
  var __defProp$8 = Object.defineProperty;
15085
- var __defProps$3 = Object.defineProperties;
15086
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
15100
+ var __defProps$4 = Object.defineProperties;
15101
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
15087
15102
  var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
15088
15103
  var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
15089
15104
  var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
@@ -15099,7 +15114,7 @@ var LeafletMapAdapter = (function () {
15099
15114
  }
15100
15115
  return a;
15101
15116
  };
15102
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
15117
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
15103
15118
  var __publicField$5 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
15104
15119
  var __async = (__this, __arguments, generator) => {
15105
15120
  return new Promise((resolve, reject) => {
@@ -15148,7 +15163,7 @@ var LeafletMapAdapter = (function () {
15148
15163
  addLayer(options) {
15149
15164
  Object.assign(this.options, options);
15150
15165
  this.paint = options.paint;
15151
- this.layer = new leafletSrcExports.FeatureGroup([], __spreadProps$3(__spreadValues$5({}, options.nativeOptions), {
15166
+ this.layer = new leafletSrcExports.FeatureGroup([], __spreadProps$4(__spreadValues$5({}, options.nativeOptions), {
15152
15167
  pane: this.pane
15153
15168
  }));
15154
15169
  this.selectedPaint = options.selectedPaint;
@@ -15498,7 +15513,7 @@ var LeafletMapAdapter = (function () {
15498
15513
  if (feature) {
15499
15514
  return this._paint.preparePaint(__spreadValues$5(__spreadValues$5({}, PAINT), paint(feature)));
15500
15515
  } else {
15501
- return this._paint.preparePaint(__spreadProps$3(__spreadValues$5({}, PAINT), { type: "path" }));
15516
+ return this._paint.preparePaint(__spreadProps$4(__spreadValues$5({}, PAINT), { type: "path" }));
15502
15517
  }
15503
15518
  }
15504
15519
  };
@@ -15658,7 +15673,11 @@ var LeafletMapAdapter = (function () {
15658
15673
  }
15659
15674
  }
15660
15675
 
15661
- function callAjax(src, headers) {
15676
+ function callAjax({
15677
+ src,
15678
+ headers,
15679
+ withCredentials
15680
+ }) {
15662
15681
  let abortFunc = () => {
15663
15682
  };
15664
15683
  const promise = new Promise((resolve, reject) => {
@@ -15668,6 +15687,9 @@ var LeafletMapAdapter = (function () {
15668
15687
  for (const h in headers) {
15669
15688
  xhr.setRequestHeader(h, headers[h]);
15670
15689
  }
15690
+ if (withCredentials) {
15691
+ xhr.withCredentials = withCredentials;
15692
+ }
15671
15693
  xhr.onload = function() {
15672
15694
  const arrayBufferView = new Uint8Array(this.response);
15673
15695
  const blob = new Blob([arrayBufferView], { type: "image/png" });
@@ -15790,12 +15812,16 @@ var LeafletMapAdapter = (function () {
15790
15812
  }
15791
15813
  _initImage() {
15792
15814
  super._initImage();
15793
- const headers = this.options.headers;
15815
+ const { headers, withCredentials } = this.options;
15794
15816
  const img = this._image;
15795
15817
  const src = img.src;
15796
15818
  img.src = "";
15797
15819
  imageQueue.add(() => {
15798
- const [promise, abortFunc] = callAjax(src, headers);
15820
+ const [promise, abortFunc] = callAjax({
15821
+ src,
15822
+ headers,
15823
+ withCredentials
15824
+ });
15799
15825
  promise.then((imgUrl) => {
15800
15826
  img.src = imgUrl;
15801
15827
  });
@@ -15810,6 +15836,7 @@ var LeafletMapAdapter = (function () {
15810
15836
  var __publicField$2 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
15811
15837
  class ImageLayer extends leafletSrcExports.Layer {
15812
15838
  constructor(url, options) {
15839
+ var _a;
15813
15840
  super(options);
15814
15841
  __publicField$2(this, "defaultWmsParams", {
15815
15842
  service: "WMS",
@@ -15827,8 +15854,10 @@ var LeafletMapAdapter = (function () {
15827
15854
  opacity: 1,
15828
15855
  isBack: false,
15829
15856
  minZoom: 0,
15857
+ maxZoom: void 0,
15830
15858
  pane: "tilePane",
15831
15859
  headers: null,
15860
+ withCredentials: false,
15832
15861
  viewPortBuffer: 0,
15833
15862
  setViewDelay: 100
15834
15863
  });
@@ -15849,7 +15878,11 @@ var LeafletMapAdapter = (function () {
15849
15878
  }
15850
15879
  }
15851
15880
  leafletSrcExports.Util.setOptions(this, opts);
15852
- this.wmsParams = leafletSrcExports.Util.extend({}, this.defaultWmsParams, params);
15881
+ this.wmsParams = leafletSrcExports.Util.extend(
15882
+ {},
15883
+ this.defaultWmsParams,
15884
+ (_a = params == null ? void 0 : params.params) != null ? _a : {}
15885
+ );
15853
15886
  }
15854
15887
  setParams(params) {
15855
15888
  leafletSrcExports.Util.extend(this.wmsParams, params);
@@ -15898,7 +15931,8 @@ var LeafletMapAdapter = (function () {
15898
15931
  const overlay = new ImageOverlay(url, bounds, {
15899
15932
  opacity: 0,
15900
15933
  pane: this.options.pane,
15901
- headers: this.options.headers
15934
+ headers: this.options.headers,
15935
+ withCredentials: this.options.withCredentials
15902
15936
  });
15903
15937
  overlay.addTo(this._map);
15904
15938
  this._loadedOverlay = overlay;
@@ -15996,6 +16030,8 @@ var LeafletMapAdapter = (function () {
15996
16030
  }
15997
16031
 
15998
16032
  var __defProp$4 = Object.defineProperty;
16033
+ var __defProps$3 = Object.defineProperties;
16034
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
15999
16035
  var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
16000
16036
  var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
16001
16037
  var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
@@ -16011,6 +16047,7 @@ var LeafletMapAdapter = (function () {
16011
16047
  }
16012
16048
  return a;
16013
16049
  };
16050
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
16014
16051
  var __publicField$1 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
16015
16052
  class ImageAdapter extends BaseAdapter {
16016
16053
  constructor() {
@@ -16018,15 +16055,21 @@ var LeafletMapAdapter = (function () {
16018
16055
  __publicField$1(this, "layer");
16019
16056
  }
16020
16057
  addLayer(options) {
16058
+ var _a;
16021
16059
  const url = options && options.url;
16022
16060
  if (url) {
16023
- options = __spreadValues$4({ transparent: true }, options);
16024
16061
  const updateWmsParamsFromOpt = options.updateWmsParams;
16025
- this.layer = new ImageLayer(url, __spreadValues$4(__spreadValues$4(__spreadValues$4({
16062
+ this.layer = new ImageLayer(url, __spreadProps$3(__spreadValues$4(__spreadValues$4(__spreadValues$4({
16026
16063
  pane: this.pane,
16027
16064
  headers: options.headers,
16028
16065
  setViewDelay: options.setViewDelay
16029
- }, options), options.params), options.nativeOptions));
16066
+ }, __spreadProps$3(__spreadValues$4({
16067
+ transparent: true
16068
+ }, options), {
16069
+ opacity: (_a = options.opacity) != null ? _a : void 0
16070
+ })), options.params), options.nativeOptions), {
16071
+ maxZoom: 12
16072
+ }));
16030
16073
  if (updateWmsParamsFromOpt) {
16031
16074
  const updateWmsParams = this.layer.updateWmsParams;
16032
16075
  this.layer.updateWmsParams = function(map) {
@@ -16037,6 +16080,13 @@ var LeafletMapAdapter = (function () {
16037
16080
  return this.layer;
16038
16081
  }
16039
16082
  }
16083
+ updateLayer(options) {
16084
+ if (this.layer) {
16085
+ const params = (options == null ? void 0 : options.params) || {};
16086
+ leafletSrcExports.Util.extend(this.layer.wmsParams, params);
16087
+ this.layer.update();
16088
+ }
16089
+ }
16040
16090
  }
16041
16091
  __publicField$1(ImageAdapter, "queue", imageQueue);
16042
16092
 
@@ -16051,13 +16101,13 @@ var LeafletMapAdapter = (function () {
16051
16101
  }
16052
16102
  }
16053
16103
  createTile(coords, done) {
16054
- const url = this.getTileUrl(coords);
16104
+ const src = this.getTileUrl(coords);
16055
16105
  const tile = document.createElement("img");
16056
- const [promise, abortFunc] = callAjax(
16057
- url,
16058
- // @ts-ignore
16059
- this.options.headers
16060
- );
16106
+ const [promise, abortFunc] = callAjax({
16107
+ src,
16108
+ withCredentials: this.options.withCredentials,
16109
+ headers: this.options.headers
16110
+ });
16061
16111
  promise.then((response) => {
16062
16112
  tile.src = response;
16063
16113
  done(null, tile);
@@ -16147,9 +16197,10 @@ var LeafletMapAdapter = (function () {
16147
16197
  tileLayerOptions.subdomains = opt.subdomains;
16148
16198
  }
16149
16199
  let layer;
16150
- if (opt.headers) {
16200
+ if (opt.headers || opt.withCredentials) {
16151
16201
  layer = new TileLayer(url, __spreadProps$2(__spreadValues$3({}, tileLayerOptions), {
16152
16202
  headers: opt.headers,
16203
+ withCredentials: opt.withCredentials,
16153
16204
  setViewDelay: opt.setViewDelay
16154
16205
  }));
16155
16206
  } else {
@@ -16159,13 +16210,12 @@ var LeafletMapAdapter = (function () {
16159
16210
  }
16160
16211
  }
16161
16212
  }
16162
- updateLayer() {
16213
+ updateLayer(options) {
16163
16214
  if (this.layer) {
16164
16215
  const currentUrl = this.layer._url;
16165
- const timestamp = (/* @__PURE__ */ new Date()).getTime();
16166
- const separator = currentUrl.includes("?") ? "&" : "?";
16167
- const newUrl = currentUrl.replace(/(\?|&)timestamp=\d*/g, "") + separator + `timestamp=${timestamp}`;
16168
- this.layer.setUrl(newUrl);
16216
+ if (options == null ? void 0 : options.params) {
16217
+ this.layer.setUrl(updateUrlParams(currentUrl, options.params));
16218
+ }
16169
16219
  this.layer.redraw();
16170
16220
  }
16171
16221
  }
@@ -16255,8 +16305,11 @@ var LeafletMapAdapter = (function () {
16255
16305
  transparent: true
16256
16306
  }, options.nativeOptions);
16257
16307
  let layer;
16258
- if (opt.headers) {
16259
- layer = new WmsLayer(url, __spreadProps(__spreadValues$1({}, layerOptions), { headers: opt.headers }));
16308
+ if (opt.headers || opt.withCredentials) {
16309
+ layer = new WmsLayer(url, __spreadProps(__spreadValues$1({}, layerOptions), {
16310
+ headers: opt.headers,
16311
+ withCredentials: opt.withCredentials
16312
+ }));
16260
16313
  } else {
16261
16314
  layer = new leafletSrcExports.TileLayer.WMS(url, layerOptions);
16262
16315
  }