@nextgis/leaflet-map-adapter 2.1.0 → 2.2.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,6 +1,6 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 2.1.0; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 2.2.0; author: NextGIS */
2
2
  import { EventEmitter } from 'events';
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';
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';
4
4
  import { defined, debounce as debounce$1 } from '@nextgis/utils';
5
5
  import { isPaintCallback, isPaint } from '@nextgis/paint';
6
6
 
@@ -1115,30 +1115,32 @@ var __publicField$3 = (obj, key, value) => {
1115
1115
  class ImageOverlay extends ImageOverlay$1 {
1116
1116
  constructor(imageUrl, bounds, options) {
1117
1117
  super(imageUrl, bounds, options);
1118
- __publicField$3(this, "_abort", []);
1118
+ __publicField$3(this, "_aborter");
1119
1119
  }
1120
1120
  cancelLoad() {
1121
- if (this._abort) {
1122
- this._abort.forEach((x) => x());
1123
- this._abort = [];
1121
+ if (this._aborter) {
1122
+ this._aborter();
1123
+ this._aborter = void 0;
1124
1124
  }
1125
1125
  }
1126
1126
  _initImage() {
1127
1127
  super._initImage();
1128
1128
  const headers = this.options.headers;
1129
+ const img = this._image;
1130
+ const src = img.src;
1129
1131
  if (headers) {
1130
- const img = this._image;
1131
- const src = img.src;
1132
1132
  img.src = "";
1133
- this._abort.push(
1134
- callAjax(
1135
- src,
1136
- (response) => {
1137
- img.src = response;
1138
- },
1139
- headers
1140
- )
1133
+ this._aborter = callAjax(
1134
+ src,
1135
+ (response) => {
1136
+ img.src = response;
1137
+ },
1138
+ headers
1141
1139
  );
1140
+ } else {
1141
+ this._aborter = () => {
1142
+ img.setAttribute("src", Util.emptyImageUrl);
1143
+ };
1142
1144
  }
1143
1145
  }
1144
1146
  }
@@ -1177,6 +1179,7 @@ class ImageLayer extends Layer {
1177
1179
  __publicField$2(this, "_url");
1178
1180
  __publicField$2(this, "_currentUrl");
1179
1181
  __publicField$2(this, "_currentOverlay");
1182
+ __publicField$2(this, "_loadedOverlay");
1180
1183
  this._url = url;
1181
1184
  const params = {};
1182
1185
  const opts = {};
@@ -1230,15 +1233,18 @@ class ImageLayer extends Layer {
1230
1233
  this._currentUrl = url;
1231
1234
  const viewPortBuffer = this.options.viewPortBuffer || 0;
1232
1235
  const bounds = this._map.getBounds().pad(viewPortBuffer);
1236
+ if (this._loadedOverlay) {
1237
+ this._loadedOverlay.cancelLoad();
1238
+ this._loadedOverlay.off("load");
1239
+ this._loadedOverlay = void 0;
1240
+ }
1233
1241
  const overlay = new ImageOverlay(url, bounds, {
1234
1242
  opacity: 0,
1235
1243
  pane: this.options.pane,
1236
1244
  headers: this.options.headers
1237
1245
  });
1238
1246
  overlay.addTo(this._map);
1239
- if (this._currentOverlay) {
1240
- this._currentOverlay.cancelLoad();
1241
- }
1247
+ this._loadedOverlay = overlay;
1242
1248
  overlay.once(
1243
1249
  "load",
1244
1250
  () => {
@@ -1251,6 +1257,7 @@ class ImageLayer extends Layer {
1251
1257
  } else if (this._currentOverlay) {
1252
1258
  this._map.removeLayer(this._currentOverlay);
1253
1259
  }
1260
+ this._loadedOverlay = void 0;
1254
1261
  this._currentOverlay = overlay;
1255
1262
  overlay.setOpacity(
1256
1263
  this.options.opacity !== void 0 ? this.options.opacity : 1