@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.
- package/lib/leaflet-map-adapter.esm-browser.js +200 -91
- package/lib/leaflet-map-adapter.esm-browser.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-browser.prod.js +1 -1
- package/lib/leaflet-map-adapter.esm-browser.prod.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.js +64 -44
- package/lib/leaflet-map-adapter.esm-bundler.js.map +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.prod.js +1 -1
- package/lib/leaflet-map-adapter.esm-bundler.prod.js.map +1 -1
- package/lib/leaflet-map-adapter.global.js +200 -91
- package/lib/leaflet-map-adapter.global.js.map +1 -1
- package/lib/leaflet-map-adapter.global.prod.js +1 -1
- package/lib/leaflet-map-adapter.global.prod.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/** Bundle of @nextgis/leaflet-map-adapter; version: 2.1
|
|
1
|
+
/** Bundle of @nextgis/leaflet-map-adapter; version: 2.2.1; author: NextGIS */
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
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,
|
|
1090
|
-
|
|
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) => {
|
|
@@ -1115,31 +1126,27 @@ var __publicField$3 = (obj, key, value) => {
|
|
|
1115
1126
|
class ImageOverlay extends ImageOverlay$1 {
|
|
1116
1127
|
constructor(imageUrl, bounds, options) {
|
|
1117
1128
|
super(imageUrl, bounds, options);
|
|
1118
|
-
__publicField$3(this, "
|
|
1129
|
+
__publicField$3(this, "_aborter");
|
|
1119
1130
|
}
|
|
1120
1131
|
cancelLoad() {
|
|
1121
|
-
if (this.
|
|
1122
|
-
this.
|
|
1123
|
-
this.
|
|
1132
|
+
if (this._aborter) {
|
|
1133
|
+
this._aborter();
|
|
1134
|
+
this._aborter = void 0;
|
|
1124
1135
|
}
|
|
1125
1136
|
}
|
|
1126
1137
|
_initImage() {
|
|
1127
1138
|
super._initImage();
|
|
1128
1139
|
const headers = this.options.headers;
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
img.src
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
headers
|
|
1140
|
-
)
|
|
1141
|
-
);
|
|
1142
|
-
}
|
|
1140
|
+
const img = this._image;
|
|
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
|
+
});
|
|
1143
1150
|
}
|
|
1144
1151
|
}
|
|
1145
1152
|
|
|
@@ -1177,6 +1184,7 @@ class ImageLayer extends Layer {
|
|
|
1177
1184
|
__publicField$2(this, "_url");
|
|
1178
1185
|
__publicField$2(this, "_currentUrl");
|
|
1179
1186
|
__publicField$2(this, "_currentOverlay");
|
|
1187
|
+
__publicField$2(this, "_loadedOverlay");
|
|
1180
1188
|
this._url = url;
|
|
1181
1189
|
const params = {};
|
|
1182
1190
|
const opts = {};
|
|
@@ -1230,15 +1238,18 @@ class ImageLayer extends Layer {
|
|
|
1230
1238
|
this._currentUrl = url;
|
|
1231
1239
|
const viewPortBuffer = this.options.viewPortBuffer || 0;
|
|
1232
1240
|
const bounds = this._map.getBounds().pad(viewPortBuffer);
|
|
1241
|
+
if (this._loadedOverlay) {
|
|
1242
|
+
this._loadedOverlay.cancelLoad();
|
|
1243
|
+
this._loadedOverlay.off("load");
|
|
1244
|
+
this._loadedOverlay = void 0;
|
|
1245
|
+
}
|
|
1233
1246
|
const overlay = new ImageOverlay(url, bounds, {
|
|
1234
1247
|
opacity: 0,
|
|
1235
1248
|
pane: this.options.pane,
|
|
1236
1249
|
headers: this.options.headers
|
|
1237
1250
|
});
|
|
1238
1251
|
overlay.addTo(this._map);
|
|
1239
|
-
|
|
1240
|
-
this._currentOverlay.cancelLoad();
|
|
1241
|
-
}
|
|
1252
|
+
this._loadedOverlay = overlay;
|
|
1242
1253
|
overlay.once(
|
|
1243
1254
|
"load",
|
|
1244
1255
|
() => {
|
|
@@ -1251,6 +1262,7 @@ class ImageLayer extends Layer {
|
|
|
1251
1262
|
} else if (this._currentOverlay) {
|
|
1252
1263
|
this._map.removeLayer(this._currentOverlay);
|
|
1253
1264
|
}
|
|
1265
|
+
this._loadedOverlay = void 0;
|
|
1254
1266
|
this._currentOverlay = overlay;
|
|
1255
1267
|
overlay.setOpacity(
|
|
1256
1268
|
this.options.opacity !== void 0 ? this.options.opacity : 1
|
|
@@ -1377,6 +1389,7 @@ class ImageAdapter extends BaseAdapter {
|
|
|
1377
1389
|
}
|
|
1378
1390
|
}
|
|
1379
1391
|
}
|
|
1392
|
+
__publicField$1(ImageAdapter, "queue", imageQueue$1);
|
|
1380
1393
|
|
|
1381
1394
|
function debounce(cb, wait = 10) {
|
|
1382
1395
|
let timeoutId;
|
|
@@ -1409,15 +1422,16 @@ function makeRemote(Base) {
|
|
|
1409
1422
|
createTile(coords, done) {
|
|
1410
1423
|
const url = this.getTileUrl(coords);
|
|
1411
1424
|
const tile = document.createElement("img");
|
|
1412
|
-
|
|
1425
|
+
const [promise, abortFunc] = callAjax(
|
|
1413
1426
|
url,
|
|
1414
|
-
(response) => {
|
|
1415
|
-
tile.src = response;
|
|
1416
|
-
done(null, tile);
|
|
1417
|
-
},
|
|
1418
1427
|
// @ts-ignore
|
|
1419
1428
|
this.options.headers
|
|
1420
1429
|
);
|
|
1430
|
+
promise.then((response) => {
|
|
1431
|
+
tile.src = response;
|
|
1432
|
+
done(null, tile);
|
|
1433
|
+
});
|
|
1434
|
+
tile.abort = abortFunc;
|
|
1421
1435
|
if (this.options.crossOrigin || this.options.crossOrigin === "") {
|
|
1422
1436
|
tile.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
|
|
1423
1437
|
}
|
|
@@ -1926,6 +1940,12 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
|
|
|
1926
1940
|
for (const e of this._universalEvents) {
|
|
1927
1941
|
map.on(e, () => this.emitter.emit(e, this), map);
|
|
1928
1942
|
}
|
|
1943
|
+
map.on("movestart", () => {
|
|
1944
|
+
ImageAdapter.queue.abort();
|
|
1945
|
+
});
|
|
1946
|
+
map.on("zoomstart", () => {
|
|
1947
|
+
ImageAdapter.queue.abort();
|
|
1948
|
+
});
|
|
1929
1949
|
for (const e of this._positionEvents) {
|
|
1930
1950
|
map.on(
|
|
1931
1951
|
e,
|