@nextgis/leaflet-map-adapter 3.0.0-alpha.0 → 3.0.0-alpha.3

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: 3.0.0-alpha.0; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 3.0.0-alpha.3; 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';
@@ -1086,7 +1086,11 @@ class GeoJsonAdapter extends BaseAdapter {
1086
1086
  }
1087
1087
  }
1088
1088
 
1089
- function callAjax(src, headers) {
1089
+ function callAjax({
1090
+ src,
1091
+ headers,
1092
+ withCredentials
1093
+ }) {
1090
1094
  let abortFunc = () => {
1091
1095
  };
1092
1096
  const promise = new Promise((resolve, reject) => {
@@ -1096,6 +1100,9 @@ function callAjax(src, headers) {
1096
1100
  for (const h in headers) {
1097
1101
  xhr.setRequestHeader(h, headers[h]);
1098
1102
  }
1103
+ if (withCredentials) {
1104
+ xhr.withCredentials = withCredentials;
1105
+ }
1099
1106
  xhr.onload = function() {
1100
1107
  const arrayBufferView = new Uint8Array(this.response);
1101
1108
  const blob = new Blob([arrayBufferView], { type: "image/png" });
@@ -1131,12 +1138,16 @@ class ImageOverlay extends ImageOverlay$1 {
1131
1138
  }
1132
1139
  _initImage() {
1133
1140
  super._initImage();
1134
- const headers = this.options.headers;
1141
+ const { headers, withCredentials } = this.options;
1135
1142
  const img = this._image;
1136
1143
  const src = img.src;
1137
1144
  img.src = "";
1138
1145
  imageQueue.add(() => {
1139
- const [promise, abortFunc] = callAjax(src, headers);
1146
+ const [promise, abortFunc] = callAjax({
1147
+ src,
1148
+ headers,
1149
+ withCredentials
1150
+ });
1140
1151
  promise.then((imgUrl) => {
1141
1152
  img.src = imgUrl;
1142
1153
  });
@@ -1170,6 +1181,7 @@ class ImageLayer extends Layer {
1170
1181
  minZoom: 0,
1171
1182
  pane: "tilePane",
1172
1183
  headers: null,
1184
+ withCredentials: false,
1173
1185
  viewPortBuffer: 0,
1174
1186
  setViewDelay: 100
1175
1187
  });
@@ -1239,7 +1251,8 @@ class ImageLayer extends Layer {
1239
1251
  const overlay = new ImageOverlay(url, bounds, {
1240
1252
  opacity: 0,
1241
1253
  pane: this.options.pane,
1242
- headers: this.options.headers
1254
+ headers: this.options.headers,
1255
+ withCredentials: this.options.withCredentials
1243
1256
  });
1244
1257
  overlay.addTo(this._map);
1245
1258
  this._loadedOverlay = overlay;
@@ -1410,13 +1423,13 @@ function makeRemote(Base) {
1410
1423
  }
1411
1424
  }
1412
1425
  createTile(coords, done) {
1413
- const url = this.getTileUrl(coords);
1426
+ const src = this.getTileUrl(coords);
1414
1427
  const tile = document.createElement("img");
1415
- const [promise, abortFunc] = callAjax(
1416
- url,
1417
- // @ts-ignore
1418
- this.options.headers
1419
- );
1428
+ const [promise, abortFunc] = callAjax({
1429
+ src,
1430
+ withCredentials: this.options.withCredentials,
1431
+ headers: this.options.headers
1432
+ });
1420
1433
  promise.then((response) => {
1421
1434
  tile.src = response;
1422
1435
  done(null, tile);
@@ -1506,9 +1519,10 @@ class TileAdapter extends BaseAdapter {
1506
1519
  tileLayerOptions.subdomains = opt.subdomains;
1507
1520
  }
1508
1521
  let layer;
1509
- if (opt.headers) {
1522
+ if (opt.headers || opt.withCredentials) {
1510
1523
  layer = new TileLayer(url, __spreadProps$2(__spreadValues$3({}, tileLayerOptions), {
1511
1524
  headers: opt.headers,
1525
+ withCredentials: opt.withCredentials,
1512
1526
  setViewDelay: opt.setViewDelay
1513
1527
  }));
1514
1528
  } else {
@@ -1614,8 +1628,11 @@ class WmsAdapter extends BaseAdapter {
1614
1628
  transparent: true
1615
1629
  }, options.nativeOptions);
1616
1630
  let layer;
1617
- if (opt.headers) {
1618
- 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
+ }));
1619
1636
  } else {
1620
1637
  layer = new TileLayer$1.WMS(url, layerOptions);
1621
1638
  }