@nextgis/leaflet-map-adapter 1.8.1 → 1.9.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: 1.8.1; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 1.9.0; author: NextGIS */
2
2
  var LeafletMapAdapter = (function () {
3
3
  'use strict';
4
4
 
@@ -15140,7 +15140,9 @@ var LeafletMapAdapter = (function () {
15140
15140
  GeoJsonAdapter.prototype.getBounds = function () {
15141
15141
  if (this.layer) {
15142
15142
  var bounds = this.layer.getBounds();
15143
- return boundsToArray(bounds);
15143
+ if (bounds.isValid()) {
15144
+ return boundsToArray(bounds);
15145
+ }
15144
15146
  }
15145
15147
  };
15146
15148
  GeoJsonAdapter.prototype.setOpacity = function (value) {
@@ -15191,14 +15193,14 @@ var LeafletMapAdapter = (function () {
15191
15193
  }
15192
15194
  }
15193
15195
  };
15194
- GeoJsonAdapter.prototype._openPopup = function (def, options, type, latlng) {
15196
+ GeoJsonAdapter.prototype._openPopup = function (def, options, type, latLng) {
15195
15197
  var _a, _b;
15196
15198
  if (options === void 0) { options = {}; }
15197
15199
  return __awaiter(this, void 0, void 0, function () {
15198
- var feature, layer, _c, minWidth, autoPan, maxWidth, closeButton_, closeButton, popup, _closeHandlers, onClose, close, content, _d, unselectOnClose, p;
15200
+ var feature, layer, _c, minWidth, autoPan, maxWidth, closeButton_, closeButton, popup, _closeHandlers, onClose, close, content, popupOptions, unselectOnClose, p;
15199
15201
  var _this = this;
15200
- return __generator(this, function (_e) {
15201
- switch (_e.label) {
15202
+ return __generator(this, function (_d) {
15203
+ switch (_d.label) {
15202
15204
  case 0:
15203
15205
  feature = def.feature, layer = def.layer;
15204
15206
  _c = __assign({ minWidth: 300 }, options), minWidth = _c.minWidth, autoPan = _c.autoPan, maxWidth = _c.maxWidth, closeButton_ = _c.closeButton;
@@ -15215,22 +15217,25 @@ var LeafletMapAdapter = (function () {
15215
15217
  if (!options.createPopupContent) return [3 /*break*/, 2];
15216
15218
  return [4 /*yield*/, options.createPopupContent(__assign({ layer: layer, feature: feature, target: this, type: type, close: close, onClose: onClose }, createFeaturePositionOptions(feature)))];
15217
15219
  case 1:
15218
- _d = _e.sent();
15220
+ content = _d.sent();
15219
15221
  return [3 /*break*/, 3];
15220
15222
  case 2:
15221
- _d = options.popupContent;
15222
- _e.label = 3;
15223
+ content = options.popupContent;
15224
+ _d.label = 3;
15223
15225
  case 3:
15224
- content = _d;
15225
15226
  if (content && layer) {
15226
- popup = layer.bindPopup(content, {
15227
+ popupOptions = {
15227
15228
  minWidth: minWidth,
15228
15229
  autoPan: autoPan,
15229
- maxWidth: maxWidth,
15230
+ // maxWidth,
15230
15231
  closeButton: closeButton,
15231
15232
  closeOnClick: false,
15232
15233
  autoClose: false,
15233
- });
15234
+ };
15235
+ if (defined(maxWidth)) {
15236
+ popupOptions.maxWidth = maxWidth;
15237
+ }
15238
+ popup = layer.bindPopup(content, popupOptions);
15234
15239
  unselectOnClose = (_b = (_a = this.options.popupOptions) === null || _a === void 0 ? void 0 : _a.unselectOnClose) !== null && _b !== void 0 ? _b : true;
15235
15240
  if (unselectOnClose) {
15236
15241
  p = layer.getPopup();
@@ -15240,9 +15245,7 @@ var LeafletMapAdapter = (function () {
15240
15245
  }, this);
15241
15246
  }
15242
15247
  this._openedPopup.push([popup, _closeHandlers, def]);
15243
- setTimeout(function () {
15244
- popup.openPopup(latlng);
15245
- }, 0);
15248
+ popup.openPopup(latLng);
15246
15249
  }
15247
15250
  return [2 /*return*/];
15248
15251
  }
@@ -15390,7 +15393,7 @@ var LeafletMapAdapter = (function () {
15390
15393
  ok = this._filterFun(def_1);
15391
15394
  }
15392
15395
  if (ok) {
15393
- var _a = this.options, popup = _a.popup, popupOptions = _a.popupOptions, selectable = _a.selectable, interactive = _a.interactive, selectOnHover = _a.selectOnHover;
15396
+ var _a = this.options, popup_1 = _a.popup, popupOptions_1 = _a.popupOptions, selectable = _a.selectable, interactive = _a.interactive, selectOnHover = _a.selectOnHover;
15394
15397
  // @ts-ignore
15395
15398
  layer.options.interactive = defined(interactive) ? interactive : true;
15396
15399
  layer_.addLayer(layer);
@@ -15408,10 +15411,14 @@ var LeafletMapAdapter = (function () {
15408
15411
  }
15409
15412
  }
15410
15413
  this._handleMouseEvents(layer);
15411
- if (popup) {
15412
- this._openPopup(__assign({ target: this, layer: layer, feature: feature }, createFeaturePositionOptions(feature)), popupOptions, 'api');
15413
- }
15414
- this._updateTooltip({ layer: layer, feature: feature });
15414
+ // The timeout is needed to display the popup immediately when adding a layer to the map.
15415
+ // Without a timeout, the layer may not yet have a _map object
15416
+ setTimeout(function () {
15417
+ if (popup_1) {
15418
+ _this._openPopup(__assign({ target: _this, layer: layer, feature: feature }, createFeaturePositionOptions(feature)), popupOptions_1, 'api');
15419
+ }
15420
+ _this._updateTooltip({ layer: layer, feature: feature });
15421
+ });
15415
15422
  }
15416
15423
  }
15417
15424
  };
@@ -15989,6 +15996,15 @@ var LeafletMapAdapter = (function () {
15989
15996
  return OsmAdapter;
15990
15997
  }(TileAdapter));
15991
15998
 
15999
+ function arrayToBoundsExpression(bounds) {
16000
+ var e = bounds;
16001
+ // top, left, bottom, right
16002
+ return [
16003
+ [e[3], e[0]],
16004
+ [e[1], e[2]],
16005
+ ];
16006
+ }
16007
+
15992
16008
  var LeafletMapAdapter$1 = /** @class */ (function () {
15993
16009
  function LeafletMapAdapter() {
15994
16010
  this.options = { target: 'map' };
@@ -16010,10 +16026,7 @@ var LeafletMapAdapter = (function () {
16010
16026
  this.options = __assign({}, options);
16011
16027
  if (this.options.target) {
16012
16028
  var _a = this.options, zoom = _a.zoom, center = _a.center, maxZoom = _a.maxZoom, minZoom = _a.minZoom, mb = _a.maxBounds, mapAdapterOptions = _a.mapAdapterOptions;
16013
- this.map = new leafletSrc.exports.Map(this.options.target, __assign({ attributionControl: false, zoomControl: false, maxBounds: mb && [
16014
- [mb[1], mb[0]],
16015
- [mb[3], mb[2]],
16016
- ], maxZoom: maxZoom, minZoom: minZoom, center: center && [center[1], center[0]], zoom: zoom }, mapAdapterOptions));
16029
+ this.map = new leafletSrc.exports.Map(this.options.target, __assign({ attributionControl: false, zoomControl: false, maxBounds: mb ? arrayToBoundsExpression(mb) : undefined, maxZoom: maxZoom, minZoom: minZoom, center: center && [center[1], center[0]], zoom: zoom }, mapAdapterOptions));
16017
16030
  // create default pane
16018
16031
  var defPane = this.map.createPane('order-0');
16019
16032
  this.map._addUnselectCb = function (def) {
@@ -16044,14 +16057,52 @@ var LeafletMapAdapter = (function () {
16044
16057
  this.map.getContainer().style.cursor = cursor;
16045
16058
  }
16046
16059
  };
16047
- LeafletMapAdapter.prototype.setView = function (lngLat, zoom) {
16048
- var lng = lngLat[0], lat = lngLat[1];
16049
- if (this.map) {
16050
- if (typeof zoom === 'number') {
16051
- this.map.setView([lat, lng], zoom, { animate: false });
16060
+ LeafletMapAdapter.prototype.setView = function (lngLatOrOpt, zoom) {
16061
+ var map = this.map;
16062
+ if (!map)
16063
+ return;
16064
+ if (Array.isArray(lngLatOrOpt)) {
16065
+ var lngLat = lngLatOrOpt;
16066
+ var lng = lngLat[0], lat = lngLat[1];
16067
+ if (this.map) {
16068
+ if (typeof zoom === 'number') {
16069
+ this.map.setView([lat, lng], zoom, { animate: false });
16070
+ }
16071
+ else {
16072
+ this.setCenter([lng, lat]);
16073
+ }
16074
+ }
16075
+ }
16076
+ else {
16077
+ var zoom_1 = lngLatOrOpt.zoom, center = lngLatOrOpt.center, maxBounds = lngLatOrOpt.maxBounds, bounds = lngLatOrOpt.bounds, minZoom = lngLatOrOpt.minZoom, maxZoom = lngLatOrOpt.maxZoom;
16078
+ if (center && zoom_1 !== undefined) {
16079
+ this.setView(center, zoom_1);
16052
16080
  }
16053
16081
  else {
16054
- this.setCenter([lng, lat]);
16082
+ if (zoom_1 !== undefined) {
16083
+ this.setZoom(zoom_1);
16084
+ }
16085
+ if (center) {
16086
+ this.setCenter(center);
16087
+ }
16088
+ }
16089
+ if (bounds) {
16090
+ this.fitBounds(bounds);
16091
+ }
16092
+ if (maxBounds !== undefined) {
16093
+ if (maxBounds) {
16094
+ map.setMaxBounds(arrayToBoundsExpression(maxBounds));
16095
+ }
16096
+ else {
16097
+ // @ts-ignore `null` works for unset maxBounds, but not in typing
16098
+ map.setMaxBounds(null);
16099
+ }
16100
+ }
16101
+ if (maxZoom !== undefined) {
16102
+ map.setMaxZoom(maxZoom);
16103
+ }
16104
+ if (minZoom !== undefined) {
16105
+ map.setMinZoom(minZoom);
16055
16106
  }
16056
16107
  }
16057
16108
  };
@@ -16086,7 +16137,7 @@ var LeafletMapAdapter = (function () {
16086
16137
  return [sw.lng, sw.lat, ne.lng, ne.lat];
16087
16138
  };
16088
16139
  // [west, south, east, north]
16089
- LeafletMapAdapter.prototype.fitBounds = function (e, options) {
16140
+ LeafletMapAdapter.prototype.fitBounds = function (bounds, options) {
16090
16141
  if (options === void 0) { options = {}; }
16091
16142
  if (this.map) {
16092
16143
  var maxZoom = options.maxZoom, offset = options.offset, padding = options.padding;
@@ -16100,11 +16151,7 @@ var LeafletMapAdapter = (function () {
16100
16151
  if (offset) {
16101
16152
  opt.padding = offset;
16102
16153
  }
16103
- // top, left, bottom, right
16104
- this.map.fitBounds([
16105
- [e[3], e[0]],
16106
- [e[1], e[2]],
16107
- ], opt);
16154
+ this.map.fitBounds(arrayToBoundsExpression(bounds), opt);
16108
16155
  }
16109
16156
  };
16110
16157
  LeafletMapAdapter.prototype.getLayerAdapter = function (name) {
@@ -16226,5 +16273,5 @@ var LeafletMapAdapter = (function () {
16226
16273
 
16227
16274
  return LeafletMapAdapter;
16228
16275
 
16229
- }());
16276
+ })();
16230
16277
  //# sourceMappingURL=leaflet-map-adapter.global.js.map