@nextgis/leaflet-map-adapter 2.2.3 → 2.5.0

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.2.3; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 2.5.0; 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';
@@ -202,10 +202,7 @@ function createFeaturePositionOptions(features) {
202
202
 
203
203
  var __defProp$b = Object.defineProperty;
204
204
  var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
205
- var __publicField$7 = (obj, key, value) => {
206
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
207
- return value;
208
- };
205
+ var __publicField$7 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
209
206
  class BaseAdapter {
210
207
  constructor(map, options) {
211
208
  this.map = map;
@@ -287,10 +284,7 @@ var __spreadValues$7 = (a, b) => {
287
284
  }
288
285
  return a;
289
286
  };
290
- var __publicField$6 = (obj, key, value) => {
291
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
292
- return value;
293
- };
287
+ var __publicField$6 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
294
288
  class GeoJsonEvents {
295
289
  constructor(layer) {
296
290
  __publicField$6(this, "layer");
@@ -385,10 +379,7 @@ var __objRest$2 = (source, exclude) => {
385
379
  }
386
380
  return target;
387
381
  };
388
- var __publicField$5 = (obj, key, value) => {
389
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
390
- return value;
391
- };
382
+ var __publicField$5 = (obj, key, value) => __defNormalProp$8(obj, key + "" , value);
392
383
  class GeoJsonPaint {
393
384
  constructor(layer) {
394
385
  __publicField$5(this, "layer");
@@ -537,10 +528,7 @@ var __spreadValues$5 = (a, b) => {
537
528
  return a;
538
529
  };
539
530
  var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
540
- var __publicField$4 = (obj, key, value) => {
541
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
542
- return value;
543
- };
531
+ var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
544
532
  var __async = (__this, __arguments, generator) => {
545
533
  return new Promise((resolve, reject) => {
546
534
  var fulfilled = (value) => {
@@ -1098,7 +1086,11 @@ class GeoJsonAdapter extends BaseAdapter {
1098
1086
  }
1099
1087
  }
1100
1088
 
1101
- function callAjax(src, headers) {
1089
+ function callAjax({
1090
+ src,
1091
+ headers,
1092
+ withCredentials
1093
+ }) {
1102
1094
  let abortFunc = () => {
1103
1095
  };
1104
1096
  const promise = new Promise((resolve, reject) => {
@@ -1108,6 +1100,9 @@ function callAjax(src, headers) {
1108
1100
  for (const h in headers) {
1109
1101
  xhr.setRequestHeader(h, headers[h]);
1110
1102
  }
1103
+ if (withCredentials) {
1104
+ xhr.withCredentials = withCredentials;
1105
+ }
1111
1106
  xhr.onload = function() {
1112
1107
  const arrayBufferView = new Uint8Array(this.response);
1113
1108
  const blob = new Blob([arrayBufferView], { type: "image/png" });
@@ -1126,14 +1121,10 @@ function callAjax(src, headers) {
1126
1121
  }
1127
1122
 
1128
1123
  const imageQueue = new Queue({ concurrency: 6, delay: 200 });
1129
- var imageQueue$1 = imageQueue;
1130
1124
 
1131
1125
  var __defProp$6 = Object.defineProperty;
1132
1126
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1133
- var __publicField$3 = (obj, key, value) => {
1134
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1135
- return value;
1136
- };
1127
+ var __publicField$3 = (obj, key, value) => __defNormalProp$6(obj, key + "" , value);
1137
1128
  class ImageOverlay extends ImageOverlay$1 {
1138
1129
  constructor(imageUrl, bounds, options) {
1139
1130
  super(imageUrl, bounds, options);
@@ -1147,12 +1138,16 @@ class ImageOverlay extends ImageOverlay$1 {
1147
1138
  }
1148
1139
  _initImage() {
1149
1140
  super._initImage();
1150
- const headers = this.options.headers;
1141
+ const { headers, withCredentials } = this.options;
1151
1142
  const img = this._image;
1152
1143
  const src = img.src;
1153
1144
  img.src = "";
1154
- imageQueue$1.add(() => {
1155
- const [promise, abortFunc] = callAjax(src, headers);
1145
+ imageQueue.add(() => {
1146
+ const [promise, abortFunc] = callAjax({
1147
+ src,
1148
+ headers,
1149
+ withCredentials
1150
+ });
1156
1151
  promise.then((imgUrl) => {
1157
1152
  img.src = imgUrl;
1158
1153
  });
@@ -1164,10 +1159,7 @@ class ImageOverlay extends ImageOverlay$1 {
1164
1159
 
1165
1160
  var __defProp$5 = Object.defineProperty;
1166
1161
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1167
- var __publicField$2 = (obj, key, value) => {
1168
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1169
- return value;
1170
- };
1162
+ var __publicField$2 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1171
1163
  class ImageLayer extends Layer {
1172
1164
  constructor(url, options) {
1173
1165
  super(options);
@@ -1189,6 +1181,7 @@ class ImageLayer extends Layer {
1189
1181
  minZoom: 0,
1190
1182
  pane: "tilePane",
1191
1183
  headers: null,
1184
+ withCredentials: false,
1192
1185
  viewPortBuffer: 0,
1193
1186
  setViewDelay: 100
1194
1187
  });
@@ -1258,7 +1251,8 @@ class ImageLayer extends Layer {
1258
1251
  const overlay = new ImageOverlay(url, bounds, {
1259
1252
  opacity: 0,
1260
1253
  pane: this.options.pane,
1261
- headers: this.options.headers
1254
+ headers: this.options.headers,
1255
+ withCredentials: this.options.withCredentials
1262
1256
  });
1263
1257
  overlay.addTo(this._map);
1264
1258
  this._loadedOverlay = overlay;
@@ -1371,10 +1365,7 @@ var __spreadValues$4 = (a, b) => {
1371
1365
  }
1372
1366
  return a;
1373
1367
  };
1374
- var __publicField$1 = (obj, key, value) => {
1375
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1376
- return value;
1377
- };
1368
+ var __publicField$1 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1378
1369
  class ImageAdapter extends BaseAdapter {
1379
1370
  constructor() {
1380
1371
  super(...arguments);
@@ -1401,7 +1392,7 @@ class ImageAdapter extends BaseAdapter {
1401
1392
  }
1402
1393
  }
1403
1394
  }
1404
- __publicField$1(ImageAdapter, "queue", imageQueue$1);
1395
+ __publicField$1(ImageAdapter, "queue", imageQueue);
1405
1396
 
1406
1397
  function debounce(cb, wait = 10) {
1407
1398
  let timeoutId;
@@ -1432,13 +1423,13 @@ function makeRemote(Base) {
1432
1423
  }
1433
1424
  }
1434
1425
  createTile(coords, done) {
1435
- const url = this.getTileUrl(coords);
1426
+ const src = this.getTileUrl(coords);
1436
1427
  const tile = document.createElement("img");
1437
- const [promise, abortFunc] = callAjax(
1438
- url,
1439
- // @ts-ignore
1440
- this.options.headers
1441
- );
1428
+ const [promise, abortFunc] = callAjax({
1429
+ src,
1430
+ withCredentials: this.options.withCredentials,
1431
+ headers: this.options.headers
1432
+ });
1442
1433
  promise.then((response) => {
1443
1434
  tile.src = response;
1444
1435
  done(null, tile);
@@ -1528,9 +1519,10 @@ class TileAdapter extends BaseAdapter {
1528
1519
  tileLayerOptions.subdomains = opt.subdomains;
1529
1520
  }
1530
1521
  let layer;
1531
- if (opt.headers) {
1522
+ if (opt.headers || opt.withCredentials) {
1532
1523
  layer = new TileLayer(url, __spreadProps$2(__spreadValues$3({}, tileLayerOptions), {
1533
1524
  headers: opt.headers,
1525
+ withCredentials: opt.withCredentials,
1534
1526
  setViewDelay: opt.setViewDelay
1535
1527
  }));
1536
1528
  } else {
@@ -1636,8 +1628,11 @@ class WmsAdapter extends BaseAdapter {
1636
1628
  transparent: true
1637
1629
  }, options.nativeOptions);
1638
1630
  let layer;
1639
- if (opt.headers) {
1640
- layer = new WmsLayer(url, __spreadProps(__spreadValues$1({}, layerOptions), { headers: opt.headers }));
1631
+ if (opt.headers || opt.withCredentials) {
1632
+ layer = new WmsLayer(url, __spreadProps(__spreadValues$1({}, layerOptions), {
1633
+ headers: opt.headers,
1634
+ withCredentials: opt.withCredentials
1635
+ }));
1641
1636
  } else {
1642
1637
  layer = new TileLayer$1.WMS(url, layerOptions);
1643
1638
  }
@@ -1670,10 +1665,7 @@ var __spreadValues = (a, b) => {
1670
1665
  }
1671
1666
  return a;
1672
1667
  };
1673
- var __publicField = (obj, key, value) => {
1674
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1675
- return value;
1676
- };
1668
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1677
1669
  const _LeafletMapAdapter = class _LeafletMapAdapter {
1678
1670
  constructor() {
1679
1671
  __publicField(this, "options", { target: "map" });
@@ -1751,8 +1743,7 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
1751
1743
  }
1752
1744
  setView(lngLatOrOpt, zoom) {
1753
1745
  const map = this.map;
1754
- if (!map)
1755
- return;
1746
+ if (!map) return;
1756
1747
  if (Array.isArray(lngLatOrOpt)) {
1757
1748
  const lngLat = lngLatOrOpt;
1758
1749
  const [lng, lat] = lngLat;
@@ -1820,8 +1811,7 @@ const _LeafletMapAdapter = class _LeafletMapAdapter {
1820
1811
  return (_a = this.map && this.map.getZoom()) != null ? _a : void 0;
1821
1812
  }
1822
1813
  getBounds() {
1823
- if (!this.map)
1824
- return void 0;
1814
+ if (!this.map) return void 0;
1825
1815
  const b = this.map.getBounds();
1826
1816
  const sw = b.getSouthWest();
1827
1817
  const ne = b.getNorthEast();