@nextgis/leaflet-map-adapter 4.0.0-alpha.0 → 4.0.0-alpha.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 +215 -158
- 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 +48 -38
- 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 +215 -158
- 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 -3
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
/** Bundle of @nextgis/leaflet-map-adapter; version: 4.0.0-alpha.
|
|
1
|
+
/** Bundle of @nextgis/leaflet-map-adapter; version: 4.0.0-alpha.1; author: NextGIS */
|
|
2
2
|
import { LeafletControlContainer, createControl, createButtonControl, createToggleControl } from '@nextgis/leaflet-control-container';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { Control, GeoJSON, DomEvent, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1, Layer, Util, GridLayer, DomUtil, TileLayer as TileLayer$1, Map, latLngBounds, latLng } from 'leaflet';
|
|
5
5
|
import { defined, debounce as debounce$1, isObject, updateUrlParams } from '@nextgis/utils';
|
|
6
6
|
import { isPaintCallback, isPaint } from '@nextgis/paint';
|
|
7
|
+
import { getLayerRequestOptions } from '@nextgis/webmap';
|
|
7
8
|
import Queue from '@nextgis/queue';
|
|
8
9
|
|
|
9
10
|
class AttributionControl extends Control.Attribution {
|
|
@@ -1017,34 +1018,38 @@ class GeoJsonAdapter extends BaseAdapter {
|
|
|
1017
1018
|
function callAjax({
|
|
1018
1019
|
src,
|
|
1019
1020
|
headers,
|
|
1020
|
-
withCredentials
|
|
1021
|
+
withCredentials,
|
|
1022
|
+
request
|
|
1021
1023
|
}) {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
xhr.open("GET", src);
|
|
1027
|
-
xhr.responseType = "arraybuffer";
|
|
1028
|
-
for (const h in headers) {
|
|
1029
|
-
xhr.setRequestHeader(h, headers[h]);
|
|
1030
|
-
}
|
|
1031
|
-
if (withCredentials) {
|
|
1032
|
-
xhr.withCredentials = withCredentials;
|
|
1033
|
-
}
|
|
1034
|
-
xhr.onload = function() {
|
|
1035
|
-
const arrayBufferView = new Uint8Array(this.response);
|
|
1036
|
-
const blob = new Blob([arrayBufferView], { type: "image/png" });
|
|
1037
|
-
const urlCreator = window.URL || window.webkitURL;
|
|
1038
|
-
const imageUrl = urlCreator.createObjectURL(blob);
|
|
1039
|
-
resolve(imageUrl);
|
|
1040
|
-
};
|
|
1041
|
-
xhr.onerror = reject;
|
|
1042
|
-
xhr.send();
|
|
1043
|
-
abortFunc = () => {
|
|
1044
|
-
xhr.abort();
|
|
1045
|
-
resolve("");
|
|
1046
|
-
};
|
|
1024
|
+
const layerRequest = getLayerRequestOptions({
|
|
1025
|
+
headers,
|
|
1026
|
+
request,
|
|
1027
|
+
withCredentials
|
|
1047
1028
|
});
|
|
1029
|
+
const requestHeaders = (layerRequest == null ? void 0 : layerRequest.headers) || {};
|
|
1030
|
+
const controller = new AbortController();
|
|
1031
|
+
const promise = fetch(src, {
|
|
1032
|
+
cache: layerRequest == null ? void 0 : layerRequest.cache,
|
|
1033
|
+
credentials: layerRequest == null ? void 0 : layerRequest.credentials,
|
|
1034
|
+
headers: requestHeaders,
|
|
1035
|
+
signal: controller.signal
|
|
1036
|
+
}).then((response) => {
|
|
1037
|
+
if (!response.ok) {
|
|
1038
|
+
throw new Error(response.statusText);
|
|
1039
|
+
}
|
|
1040
|
+
return response.blob();
|
|
1041
|
+
}).then((blob) => {
|
|
1042
|
+
const urlCreator = window.URL || window.webkitURL;
|
|
1043
|
+
return urlCreator.createObjectURL(blob);
|
|
1044
|
+
}).catch((er) => {
|
|
1045
|
+
if (er.name === "AbortError") {
|
|
1046
|
+
return "";
|
|
1047
|
+
}
|
|
1048
|
+
throw er;
|
|
1049
|
+
});
|
|
1050
|
+
const abortFunc = () => {
|
|
1051
|
+
controller.abort();
|
|
1052
|
+
};
|
|
1048
1053
|
return [promise, abortFunc];
|
|
1049
1054
|
}
|
|
1050
1055
|
|
|
@@ -1066,7 +1071,7 @@ class ImageOverlay extends ImageOverlay$1 {
|
|
|
1066
1071
|
}
|
|
1067
1072
|
_initImage() {
|
|
1068
1073
|
super._initImage();
|
|
1069
|
-
const { headers, withCredentials } = this.options;
|
|
1074
|
+
const { headers, request, withCredentials } = this.options;
|
|
1070
1075
|
const img = this._image;
|
|
1071
1076
|
const src = img.src;
|
|
1072
1077
|
img.src = "";
|
|
@@ -1074,6 +1079,7 @@ class ImageOverlay extends ImageOverlay$1 {
|
|
|
1074
1079
|
const [promise, abortFunc] = callAjax({
|
|
1075
1080
|
src,
|
|
1076
1081
|
headers,
|
|
1082
|
+
request,
|
|
1077
1083
|
withCredentials
|
|
1078
1084
|
});
|
|
1079
1085
|
promise.then((imgUrl) => {
|
|
@@ -1182,6 +1188,7 @@ class ImageLayer extends Layer {
|
|
|
1182
1188
|
opacity: 0,
|
|
1183
1189
|
pane: this.options.pane,
|
|
1184
1190
|
headers: this.options.headers,
|
|
1191
|
+
request: this.options.request,
|
|
1185
1192
|
withCredentials: this.options.withCredentials
|
|
1186
1193
|
});
|
|
1187
1194
|
overlay.addTo(this._map);
|
|
@@ -1306,15 +1313,17 @@ class ImageAdapter extends BaseAdapter {
|
|
|
1306
1313
|
const url = options && options.url;
|
|
1307
1314
|
if (url) {
|
|
1308
1315
|
const updateWmsParamsFromOpt = options.updateWmsParams;
|
|
1309
|
-
|
|
1316
|
+
const request = getLayerRequestOptions(options);
|
|
1317
|
+
this.layer = new ImageLayer(url, __spreadProps$3(__spreadValues$4(__spreadValues$4(__spreadValues$4({
|
|
1310
1318
|
pane: this.pane,
|
|
1311
|
-
headers: options.headers,
|
|
1312
1319
|
setViewDelay: options.setViewDelay
|
|
1313
1320
|
}, __spreadProps$3(__spreadValues$4({
|
|
1314
1321
|
transparent: true
|
|
1315
1322
|
}, options), {
|
|
1316
1323
|
opacity: (_a = options.opacity) != null ? _a : void 0
|
|
1317
|
-
})), options.params), options.nativeOptions)
|
|
1324
|
+
})), options.params), options.nativeOptions), {
|
|
1325
|
+
request
|
|
1326
|
+
}));
|
|
1318
1327
|
if (updateWmsParamsFromOpt) {
|
|
1319
1328
|
const updateWmsParams = this.layer.updateWmsParams;
|
|
1320
1329
|
this.layer.updateWmsParams = function(map) {
|
|
@@ -1369,7 +1378,8 @@ function makeRemote(Base) {
|
|
|
1369
1378
|
const [promise, abortFunc] = callAjax({
|
|
1370
1379
|
src,
|
|
1371
1380
|
withCredentials: this.options.withCredentials,
|
|
1372
|
-
headers: this.options.headers
|
|
1381
|
+
headers: this.options.headers,
|
|
1382
|
+
request: this.options.request
|
|
1373
1383
|
});
|
|
1374
1384
|
promise.then((response) => {
|
|
1375
1385
|
tile.src = response;
|
|
@@ -1460,10 +1470,10 @@ class TileAdapter extends BaseAdapter {
|
|
|
1460
1470
|
tileLayerOptions.subdomains = opt.subdomains;
|
|
1461
1471
|
}
|
|
1462
1472
|
let layer;
|
|
1463
|
-
|
|
1473
|
+
const request = getLayerRequestOptions(opt);
|
|
1474
|
+
if (request) {
|
|
1464
1475
|
layer = new TileLayer(url, __spreadProps$2(__spreadValues$3({}, tileLayerOptions), {
|
|
1465
|
-
|
|
1466
|
-
withCredentials: opt.withCredentials,
|
|
1476
|
+
request,
|
|
1467
1477
|
setViewDelay: opt.setViewDelay
|
|
1468
1478
|
}));
|
|
1469
1479
|
} else {
|
|
@@ -1568,10 +1578,10 @@ class WmsAdapter extends BaseAdapter {
|
|
|
1568
1578
|
transparent: true
|
|
1569
1579
|
}, options.nativeOptions);
|
|
1570
1580
|
let layer;
|
|
1571
|
-
|
|
1581
|
+
const request = getLayerRequestOptions(opt);
|
|
1582
|
+
if (request) {
|
|
1572
1583
|
layer = new WmsLayer(url, __spreadProps(__spreadValues$1({}, layerOptions), {
|
|
1573
|
-
|
|
1574
|
-
withCredentials: opt.withCredentials
|
|
1584
|
+
request
|
|
1575
1585
|
}));
|
|
1576
1586
|
} else {
|
|
1577
1587
|
layer = new TileLayer$1.WMS(url, layerOptions);
|