@nextgis/leaflet-map-adapter 2.1.0 → 2.2.1

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: 2.1.0; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 2.2.1; author: NextGIS */
2
2
  var domain;
3
3
 
4
4
  // This constructor is used to store event handlers. Instantiating this is
@@ -14756,18 +14756,18 @@ function createFeaturePositionOptions(features) {
14756
14756
  };
14757
14757
  }
14758
14758
 
14759
- var __defProp$b = Object.defineProperty;
14760
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14761
- var __publicField$7 = (obj, key, value) => {
14762
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
14759
+ var __defProp$c = Object.defineProperty;
14760
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14761
+ var __publicField$8 = (obj, key, value) => {
14762
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
14763
14763
  return value;
14764
14764
  };
14765
14765
  class BaseAdapter {
14766
14766
  constructor(map, options) {
14767
14767
  this.map = map;
14768
14768
  this.options = options;
14769
- __publicField$7(this, "layer");
14770
- __publicField$7(this, "pane", "order-0");
14769
+ __publicField$8(this, "layer");
14770
+ __publicField$8(this, "pane", "order-0");
14771
14771
  if (options.order !== void 0) {
14772
14772
  const pane = "order-" + options.order;
14773
14773
  let exist = map.getPane(pane);
@@ -14796,19 +14796,19 @@ function convertMapClickEvent(evt) {
14796
14796
  };
14797
14797
  }
14798
14798
 
14799
- var __defProp$a = Object.defineProperty;
14799
+ var __defProp$b = Object.defineProperty;
14800
14800
  var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
14801
14801
  var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
14802
14802
  var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
14803
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14803
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14804
14804
  var __spreadValues$8 = (a, b) => {
14805
14805
  for (var prop in b || (b = {}))
14806
14806
  if (__hasOwnProp$8.call(b, prop))
14807
- __defNormalProp$a(a, prop, b[prop]);
14807
+ __defNormalProp$b(a, prop, b[prop]);
14808
14808
  if (__getOwnPropSymbols$8)
14809
14809
  for (var prop of __getOwnPropSymbols$8(b)) {
14810
14810
  if (__propIsEnum$8.call(b, prop))
14811
- __defNormalProp$a(a, prop, b[prop]);
14811
+ __defNormalProp$b(a, prop, b[prop]);
14812
14812
  }
14813
14813
  return a;
14814
14814
  };
@@ -14827,32 +14827,32 @@ function createMouseEvent({
14827
14827
  return opt;
14828
14828
  }
14829
14829
 
14830
- var __defProp$9 = Object.defineProperty;
14830
+ var __defProp$a = Object.defineProperty;
14831
14831
  var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
14832
14832
  var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
14833
14833
  var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
14834
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14834
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14835
14835
  var __spreadValues$7 = (a, b) => {
14836
14836
  for (var prop in b || (b = {}))
14837
14837
  if (__hasOwnProp$7.call(b, prop))
14838
- __defNormalProp$9(a, prop, b[prop]);
14838
+ __defNormalProp$a(a, prop, b[prop]);
14839
14839
  if (__getOwnPropSymbols$7)
14840
14840
  for (var prop of __getOwnPropSymbols$7(b)) {
14841
14841
  if (__propIsEnum$7.call(b, prop))
14842
- __defNormalProp$9(a, prop, b[prop]);
14842
+ __defNormalProp$a(a, prop, b[prop]);
14843
14843
  }
14844
14844
  return a;
14845
14845
  };
14846
- var __publicField$6 = (obj, key, value) => {
14847
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
14846
+ var __publicField$7 = (obj, key, value) => {
14847
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
14848
14848
  return value;
14849
14849
  };
14850
14850
  class GeoJsonEvents {
14851
14851
  constructor(layer) {
14852
- __publicField$6(this, "layer");
14853
- __publicField$6(this, "_onclick");
14854
- __publicField$6(this, "_mouseout");
14855
- __publicField$6(this, "_mouseover");
14852
+ __publicField$7(this, "layer");
14853
+ __publicField$7(this, "_onclick");
14854
+ __publicField$7(this, "_mouseout");
14855
+ __publicField$7(this, "_mouseover");
14856
14856
  this.layer = layer;
14857
14857
  }
14858
14858
  handleMouseEvents(layer) {
@@ -14912,21 +14912,21 @@ function isPaintCallback(paint) {
14912
14912
  return false;
14913
14913
  }
14914
14914
 
14915
- var __defProp$8 = Object.defineProperty;
14915
+ var __defProp$9 = Object.defineProperty;
14916
14916
  var __defProps$4 = Object.defineProperties;
14917
14917
  var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
14918
14918
  var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
14919
14919
  var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
14920
14920
  var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
14921
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14921
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14922
14922
  var __spreadValues$6 = (a, b) => {
14923
14923
  for (var prop in b || (b = {}))
14924
14924
  if (__hasOwnProp$6.call(b, prop))
14925
- __defNormalProp$8(a, prop, b[prop]);
14925
+ __defNormalProp$9(a, prop, b[prop]);
14926
14926
  if (__getOwnPropSymbols$6)
14927
14927
  for (var prop of __getOwnPropSymbols$6(b)) {
14928
14928
  if (__propIsEnum$6.call(b, prop))
14929
- __defNormalProp$8(a, prop, b[prop]);
14929
+ __defNormalProp$9(a, prop, b[prop]);
14930
14930
  }
14931
14931
  return a;
14932
14932
  };
@@ -14943,13 +14943,13 @@ var __objRest$2 = (source, exclude) => {
14943
14943
  }
14944
14944
  return target;
14945
14945
  };
14946
- var __publicField$5 = (obj, key, value) => {
14947
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
14946
+ var __publicField$6 = (obj, key, value) => {
14947
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
14948
14948
  return value;
14949
14949
  };
14950
14950
  class GeoJsonPaint {
14951
14951
  constructor(layer) {
14952
- __publicField$5(this, "layer");
14952
+ __publicField$6(this, "layer");
14953
14953
  this.layer = layer;
14954
14954
  }
14955
14955
  setPaintEachLayer(paint) {
@@ -15076,27 +15076,27 @@ class GeoJsonPaint {
15076
15076
  }
15077
15077
  }
15078
15078
 
15079
- var __defProp$7 = Object.defineProperty;
15079
+ var __defProp$8 = Object.defineProperty;
15080
15080
  var __defProps$3 = Object.defineProperties;
15081
15081
  var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
15082
15082
  var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
15083
15083
  var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
15084
15084
  var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
15085
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15085
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15086
15086
  var __spreadValues$5 = (a, b) => {
15087
15087
  for (var prop in b || (b = {}))
15088
15088
  if (__hasOwnProp$5.call(b, prop))
15089
- __defNormalProp$7(a, prop, b[prop]);
15089
+ __defNormalProp$8(a, prop, b[prop]);
15090
15090
  if (__getOwnPropSymbols$5)
15091
15091
  for (var prop of __getOwnPropSymbols$5(b)) {
15092
15092
  if (__propIsEnum$5.call(b, prop))
15093
- __defNormalProp$7(a, prop, b[prop]);
15093
+ __defNormalProp$8(a, prop, b[prop]);
15094
15094
  }
15095
15095
  return a;
15096
15096
  };
15097
15097
  var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
15098
- var __publicField$4 = (obj, key, value) => {
15099
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
15098
+ var __publicField$5 = (obj, key, value) => {
15099
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
15100
15100
  return value;
15101
15101
  };
15102
15102
  var __async = (__this, __arguments, generator) => {
@@ -15122,22 +15122,22 @@ var __async = (__this, __arguments, generator) => {
15122
15122
  class GeoJsonAdapter extends BaseAdapter {
15123
15123
  constructor(map, options) {
15124
15124
  super(map, options);
15125
- __publicField$4(this, "layer");
15126
- __publicField$4(this, "selected", false);
15127
- __publicField$4(this, "type");
15128
- __publicField$4(this, "_layers", []);
15129
- __publicField$4(this, "_events");
15130
- __publicField$4(this, "paint");
15131
- __publicField$4(this, "selectedPaint");
15132
- __publicField$4(this, "_selectedLayers", []);
15133
- __publicField$4(this, "_filteredLayers", []);
15134
- __publicField$4(this, "_filterFun");
15135
- __publicField$4(this, "_openedPopup", []);
15136
- __publicField$4(this, "_paint");
15137
- __publicField$4(this, "$updateTooltip", debounce(() => {
15125
+ __publicField$5(this, "layer");
15126
+ __publicField$5(this, "selected", false);
15127
+ __publicField$5(this, "type");
15128
+ __publicField$5(this, "_layers", []);
15129
+ __publicField$5(this, "_events");
15130
+ __publicField$5(this, "paint");
15131
+ __publicField$5(this, "selectedPaint");
15132
+ __publicField$5(this, "_selectedLayers", []);
15133
+ __publicField$5(this, "_filteredLayers", []);
15134
+ __publicField$5(this, "_filterFun");
15135
+ __publicField$5(this, "_openedPopup", []);
15136
+ __publicField$5(this, "_paint");
15137
+ __publicField$5(this, "$updateTooltip", debounce(() => {
15138
15138
  this.updateTooltip();
15139
15139
  }, 300));
15140
- __publicField$4(this, "$unselect", () => {
15140
+ __publicField$5(this, "$unselect", () => {
15141
15141
  this.unselect();
15142
15142
  });
15143
15143
  this._events = new GeoJsonEvents(this);
@@ -15656,26 +15656,126 @@ class GeoJsonAdapter extends BaseAdapter {
15656
15656
  }
15657
15657
  }
15658
15658
 
15659
- function callAjax(src, callback, headers) {
15660
- const xhr = new XMLHttpRequest();
15661
- xhr.open("GET", src);
15662
- xhr.responseType = "arraybuffer";
15663
- for (const h in headers) {
15664
- xhr.setRequestHeader(h, headers[h]);
15665
- }
15666
- xhr.onload = function() {
15667
- const arrayBufferView = new Uint8Array(this.response);
15668
- const blob = new Blob([arrayBufferView], { type: "image/png" });
15669
- const urlCreator = window.URL || window.webkitURL;
15670
- const imageUrl = urlCreator.createObjectURL(blob);
15671
- callback(imageUrl);
15672
- };
15673
- xhr.send();
15674
- return () => {
15675
- xhr.abort();
15659
+ function callAjax(src, headers) {
15660
+ let abortFunc = () => {
15676
15661
  };
15662
+ const promise = new Promise((resolve, reject) => {
15663
+ const xhr = new XMLHttpRequest();
15664
+ xhr.open("GET", src);
15665
+ xhr.responseType = "arraybuffer";
15666
+ for (const h in headers) {
15667
+ xhr.setRequestHeader(h, headers[h]);
15668
+ }
15669
+ xhr.onload = function() {
15670
+ const arrayBufferView = new Uint8Array(this.response);
15671
+ const blob = new Blob([arrayBufferView], { type: "image/png" });
15672
+ const urlCreator = window.URL || window.webkitURL;
15673
+ const imageUrl = urlCreator.createObjectURL(blob);
15674
+ resolve(imageUrl);
15675
+ };
15676
+ xhr.onerror = reject;
15677
+ xhr.send();
15678
+ abortFunc = () => {
15679
+ xhr.abort();
15680
+ resolve("");
15681
+ };
15682
+ });
15683
+ return [promise, abortFunc];
15684
+ }
15685
+
15686
+ var __defProp$7 = Object.defineProperty;
15687
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15688
+ var __publicField$4 = (obj, key, value) => {
15689
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
15690
+ return value;
15691
+ };
15692
+ class Queue {
15693
+ /**
15694
+ * @param {PromiseQueueOptions} options - Configuration options for the queue.
15695
+ */
15696
+ constructor({ concurrency = 1, delay = 0 } = {}) {
15697
+ __publicField$4(this, "queue", []);
15698
+ __publicField$4(this, "concurrency");
15699
+ __publicField$4(this, "activeCount", 0);
15700
+ __publicField$4(this, "timeoutId");
15701
+ __publicField$4(this, "delay");
15702
+ __publicField$4(this, "toAbort", []);
15703
+ this.concurrency = concurrency;
15704
+ this.delay = delay;
15705
+ }
15706
+ /**
15707
+ * Adds a task to the queue, which can be either a simple asynchronous function or an array containing a function and its abort handler.
15708
+ *
15709
+ * @param {PromiseFuncOrPromiseWithAbortArray} promise - The asynchronous task function or a tuple containing the task and an abort function.
15710
+ * @param {Abort} [abort] - An optional abort function for the task.
15711
+ *
15712
+ * @example
15713
+ * ```javascript
15714
+ * // Add a task without an abort function.
15715
+ * queue.add(() => new Promise(resolve => setTimeout(resolve, 1000)));
15716
+ *
15717
+ * // Add a task with an abort function.
15718
+ * const controller = new AbortController();
15719
+ * queue.add(() => fetch('https://example.com', { signal: controller.signal }), controller.abort);
15720
+ * ```
15721
+ */
15722
+ add(promise, abort) {
15723
+ this.queue.push({ promise, abort });
15724
+ this.debouncedNext();
15725
+ }
15726
+ /**
15727
+ * Aborts all tasks in the queue that have an abort function.
15728
+ *
15729
+ * @example
15730
+ * queue.abort(); // Aborts all abortable tasks in the queue.
15731
+ */
15732
+ abort() {
15733
+ for (const abort of this.toAbort) {
15734
+ abort();
15735
+ }
15736
+ this.toAbort = [];
15737
+ this.queue = [];
15738
+ this._clearTimeout();
15739
+ }
15740
+ debouncedNext() {
15741
+ this._clearTimeout();
15742
+ this.timeoutId = setTimeout(() => this._next(), this.delay);
15743
+ }
15744
+ _clearTimeout() {
15745
+ if (this.timeoutId) {
15746
+ clearTimeout(this.timeoutId);
15747
+ }
15748
+ }
15749
+ _next() {
15750
+ while (this.activeCount < this.concurrency && this.queue.length > 0) {
15751
+ const { promise, abort } = this.queue.shift();
15752
+ this.activeCount++;
15753
+ let toAbort = abort;
15754
+ let request;
15755
+ const execute = promise();
15756
+ if (Array.isArray(execute)) {
15757
+ request = execute[0];
15758
+ toAbort = execute[1];
15759
+ } else {
15760
+ request = execute;
15761
+ }
15762
+ if (toAbort) {
15763
+ this.toAbort.push(toAbort);
15764
+ }
15765
+ request.finally(() => {
15766
+ this.activeCount--;
15767
+ if (toAbort) {
15768
+ this.toAbort = this.toAbort.filter((a) => a !== toAbort);
15769
+ }
15770
+ this.debouncedNext();
15771
+ });
15772
+ }
15773
+ }
15677
15774
  }
15678
15775
 
15776
+ const imageQueue = new Queue({ concurrency: 6, delay: 200 });
15777
+ var imageQueue$1 = imageQueue;
15778
+
15679
15779
  var __defProp$6 = Object.defineProperty;
15680
15780
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15681
15781
  var __publicField$3 = (obj, key, value) => {
@@ -15685,31 +15785,27 @@ var __publicField$3 = (obj, key, value) => {
15685
15785
  class ImageOverlay extends leafletSrcExports.ImageOverlay {
15686
15786
  constructor(imageUrl, bounds, options) {
15687
15787
  super(imageUrl, bounds, options);
15688
- __publicField$3(this, "_abort", []);
15788
+ __publicField$3(this, "_aborter");
15689
15789
  }
15690
15790
  cancelLoad() {
15691
- if (this._abort) {
15692
- this._abort.forEach((x) => x());
15693
- this._abort = [];
15791
+ if (this._aborter) {
15792
+ this._aborter();
15793
+ this._aborter = void 0;
15694
15794
  }
15695
15795
  }
15696
15796
  _initImage() {
15697
15797
  super._initImage();
15698
15798
  const headers = this.options.headers;
15699
- if (headers) {
15700
- const img = this._image;
15701
- const src = img.src;
15702
- img.src = "";
15703
- this._abort.push(
15704
- callAjax(
15705
- src,
15706
- (response) => {
15707
- img.src = response;
15708
- },
15709
- headers
15710
- )
15711
- );
15712
- }
15799
+ const img = this._image;
15800
+ img.src = "";
15801
+ imageQueue$1.add(() => {
15802
+ const [promise, abortFunc] = callAjax(img.src, headers);
15803
+ promise.then((imgUrl) => {
15804
+ img.src = imgUrl;
15805
+ });
15806
+ this._aborter = abortFunc;
15807
+ return promise;
15808
+ });
15713
15809
  }
15714
15810
  }
15715
15811
 
@@ -15747,6 +15843,7 @@ class ImageLayer extends leafletSrcExports.Layer {
15747
15843
  __publicField$2(this, "_url");
15748
15844
  __publicField$2(this, "_currentUrl");
15749
15845
  __publicField$2(this, "_currentOverlay");
15846
+ __publicField$2(this, "_loadedOverlay");
15750
15847
  this._url = url;
15751
15848
  const params = {};
15752
15849
  const opts = {};
@@ -15800,15 +15897,18 @@ class ImageLayer extends leafletSrcExports.Layer {
15800
15897
  this._currentUrl = url;
15801
15898
  const viewPortBuffer = this.options.viewPortBuffer || 0;
15802
15899
  const bounds = this._map.getBounds().pad(viewPortBuffer);
15900
+ if (this._loadedOverlay) {
15901
+ this._loadedOverlay.cancelLoad();
15902
+ this._loadedOverlay.off("load");
15903
+ this._loadedOverlay = void 0;
15904
+ }
15803
15905
  const overlay = new ImageOverlay(url, bounds, {
15804
15906
  opacity: 0,
15805
15907
  pane: this.options.pane,
15806
15908
  headers: this.options.headers
15807
15909
  });
15808
15910
  overlay.addTo(this._map);
15809
- if (this._currentOverlay) {
15810
- this._currentOverlay.cancelLoad();
15811
- }
15911
+ this._loadedOverlay = overlay;
15812
15912
  overlay.once(
15813
15913
  "load",
15814
15914
  () => {
@@ -15821,6 +15921,7 @@ class ImageLayer extends leafletSrcExports.Layer {
15821
15921
  } else if (this._currentOverlay) {
15822
15922
  this._map.removeLayer(this._currentOverlay);
15823
15923
  }
15924
+ this._loadedOverlay = void 0;
15824
15925
  this._currentOverlay = overlay;
15825
15926
  overlay.setOpacity(
15826
15927
  this.options.opacity !== void 0 ? this.options.opacity : 1
@@ -15947,6 +16048,7 @@ class ImageAdapter extends BaseAdapter {
15947
16048
  }
15948
16049
  }
15949
16050
  }
16051
+ __publicField$1(ImageAdapter, "queue", imageQueue$1);
15950
16052
 
15951
16053
  function makeRemote(Base) {
15952
16054
  return class RemoteTileLayer extends Base {
@@ -15961,15 +16063,16 @@ function makeRemote(Base) {
15961
16063
  createTile(coords, done) {
15962
16064
  const url = this.getTileUrl(coords);
15963
16065
  const tile = document.createElement("img");
15964
- tile.abort = callAjax(
16066
+ const [promise, abortFunc] = callAjax(
15965
16067
  url,
15966
- (response) => {
15967
- tile.src = response;
15968
- done(null, tile);
15969
- },
15970
16068
  // @ts-ignore
15971
16069
  this.options.headers
15972
16070
  );
16071
+ promise.then((response) => {
16072
+ tile.src = response;
16073
+ done(null, tile);
16074
+ });
16075
+ tile.abort = abortFunc;
15973
16076
  if (this.options.crossOrigin || this.options.crossOrigin === "") {
15974
16077
  tile.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
15975
16078
  }
@@ -16478,6 +16581,12 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
16478
16581
  for (const e of this._universalEvents) {
16479
16582
  map.on(e, () => this.emitter.emit(e, this), map);
16480
16583
  }
16584
+ map.on("movestart", () => {
16585
+ ImageAdapter.queue.abort();
16586
+ });
16587
+ map.on("zoomstart", () => {
16588
+ ImageAdapter.queue.abort();
16589
+ });
16481
16590
  for (const e of this._positionEvents) {
16482
16591
  map.on(
16483
16592
  e,