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