@nextgis/leaflet-map-adapter 2.2.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,8 +1,9 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 2.2.0; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 2.2.1; author: NextGIS */
2
2
  import { EventEmitter } from 'events';
3
- import { Control, DomEvent, GeoJSON, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1, Util, Layer, CRS, GridLayer, DomUtil, TileLayer as TileLayer$1, Map, latLngBounds, latLng } from 'leaflet';
3
+ import { Control, DomEvent, GeoJSON, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1, Layer, Util, CRS, GridLayer, DomUtil, TileLayer as TileLayer$1, Map, latLngBounds, latLng } from 'leaflet';
4
4
  import { defined, debounce as debounce$1 } from '@nextgis/utils';
5
5
  import { isPaintCallback, isPaint } from '@nextgis/paint';
6
+ import Queue from '@nextgis/queue';
6
7
 
7
8
  class AttributionControl extends Control.Attribution {
8
9
  // options: AttributionControlOptions
@@ -1086,26 +1087,36 @@ class GeoJsonAdapter extends BaseAdapter {
1086
1087
  }
1087
1088
  }
1088
1089
 
1089
- function callAjax(src, callback, headers) {
1090
- const xhr = new XMLHttpRequest();
1091
- xhr.open("GET", src);
1092
- xhr.responseType = "arraybuffer";
1093
- for (const h in headers) {
1094
- xhr.setRequestHeader(h, headers[h]);
1095
- }
1096
- xhr.onload = function() {
1097
- const arrayBufferView = new Uint8Array(this.response);
1098
- const blob = new Blob([arrayBufferView], { type: "image/png" });
1099
- const urlCreator = window.URL || window.webkitURL;
1100
- const imageUrl = urlCreator.createObjectURL(blob);
1101
- callback(imageUrl);
1102
- };
1103
- xhr.send();
1104
- return () => {
1105
- xhr.abort();
1090
+ function callAjax(src, headers) {
1091
+ let abortFunc = () => {
1106
1092
  };
1093
+ const promise = new Promise((resolve, reject) => {
1094
+ const xhr = new XMLHttpRequest();
1095
+ xhr.open("GET", src);
1096
+ xhr.responseType = "arraybuffer";
1097
+ for (const h in headers) {
1098
+ xhr.setRequestHeader(h, headers[h]);
1099
+ }
1100
+ xhr.onload = function() {
1101
+ const arrayBufferView = new Uint8Array(this.response);
1102
+ const blob = new Blob([arrayBufferView], { type: "image/png" });
1103
+ const urlCreator = window.URL || window.webkitURL;
1104
+ const imageUrl = urlCreator.createObjectURL(blob);
1105
+ resolve(imageUrl);
1106
+ };
1107
+ xhr.onerror = reject;
1108
+ xhr.send();
1109
+ abortFunc = () => {
1110
+ xhr.abort();
1111
+ resolve("");
1112
+ };
1113
+ });
1114
+ return [promise, abortFunc];
1107
1115
  }
1108
1116
 
1117
+ const imageQueue = new Queue({ concurrency: 6, delay: 200 });
1118
+ var imageQueue$1 = imageQueue;
1119
+
1109
1120
  var __defProp$6 = Object.defineProperty;
1110
1121
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1111
1122
  var __publicField$3 = (obj, key, value) => {
@@ -1127,21 +1138,15 @@ class ImageOverlay extends ImageOverlay$1 {
1127
1138
  super._initImage();
1128
1139
  const headers = this.options.headers;
1129
1140
  const img = this._image;
1130
- const src = img.src;
1131
- if (headers) {
1132
- img.src = "";
1133
- this._aborter = callAjax(
1134
- src,
1135
- (response) => {
1136
- img.src = response;
1137
- },
1138
- headers
1139
- );
1140
- } else {
1141
- this._aborter = () => {
1142
- img.setAttribute("src", Util.emptyImageUrl);
1143
- };
1144
- }
1141
+ img.src = "";
1142
+ imageQueue$1.add(() => {
1143
+ const [promise, abortFunc] = callAjax(img.src, headers);
1144
+ promise.then((imgUrl) => {
1145
+ img.src = imgUrl;
1146
+ });
1147
+ this._aborter = abortFunc;
1148
+ return promise;
1149
+ });
1145
1150
  }
1146
1151
  }
1147
1152
 
@@ -1384,6 +1389,7 @@ class ImageAdapter extends BaseAdapter {
1384
1389
  }
1385
1390
  }
1386
1391
  }
1392
+ __publicField$1(ImageAdapter, "queue", imageQueue$1);
1387
1393
 
1388
1394
  function debounce(cb, wait = 10) {
1389
1395
  let timeoutId;
@@ -1416,15 +1422,16 @@ function makeRemote(Base) {
1416
1422
  createTile(coords, done) {
1417
1423
  const url = this.getTileUrl(coords);
1418
1424
  const tile = document.createElement("img");
1419
- tile.abort = callAjax(
1425
+ const [promise, abortFunc] = callAjax(
1420
1426
  url,
1421
- (response) => {
1422
- tile.src = response;
1423
- done(null, tile);
1424
- },
1425
1427
  // @ts-ignore
1426
1428
  this.options.headers
1427
1429
  );
1430
+ promise.then((response) => {
1431
+ tile.src = response;
1432
+ done(null, tile);
1433
+ });
1434
+ tile.abort = abortFunc;
1428
1435
  if (this.options.crossOrigin || this.options.crossOrigin === "") {
1429
1436
  tile.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
1430
1437
  }
@@ -1933,6 +1940,12 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
1933
1940
  for (const e of this._universalEvents) {
1934
1941
  map.on(e, () => this.emitter.emit(e, this), map);
1935
1942
  }
1943
+ map.on("movestart", () => {
1944
+ ImageAdapter.queue.abort();
1945
+ });
1946
+ map.on("zoomstart", () => {
1947
+ ImageAdapter.queue.abort();
1948
+ });
1936
1949
  for (const e of this._positionEvents) {
1937
1950
  map.on(
1938
1951
  e,