@nextgis/leaflet-map-adapter 1.8.4 → 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.4; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 1.9.0; author: NextGIS */
2
2
  import { EventEmitter } from 'events';
3
3
  import { Control, DomEvent, GeoJSON, FeatureGroup, DivIcon, Marker, CircleMarker, ImageOverlay as ImageOverlay$1, Layer, Util, CRS, GridLayer, DomUtil, TileLayer as TileLayer$1, Map } from 'leaflet';
4
4
  import { debounce as debounce$1, defined } from '@nextgis/utils';
@@ -499,7 +499,7 @@ class GeoJsonAdapter extends BaseAdapter {
499
499
  }
500
500
  }
501
501
  }
502
- async _openPopup(def, options = {}, type, latlng) {
502
+ async _openPopup(def, options = {}, type, latLng) {
503
503
  var _a, _b;
504
504
  const { feature, layer } = def;
505
505
  const { minWidth, autoPan, maxWidth, closeButton: closeButton_, } = { minWidth: 300, ...options };
@@ -551,7 +551,7 @@ class GeoJsonAdapter extends BaseAdapter {
551
551
  }, this);
552
552
  }
553
553
  this._openedPopup.push([popup, _closeHandlers, def]);
554
- popup.openPopup(latlng);
554
+ popup.openPopup(latLng);
555
555
  }
556
556
  }
557
557
  _removePopup(popup) {
@@ -713,15 +713,19 @@ class GeoJsonAdapter extends BaseAdapter {
713
713
  }
714
714
  }
715
715
  this._handleMouseEvents(layer);
716
- if (popup) {
717
- this._openPopup({
718
- target: this,
719
- layer,
720
- feature,
721
- ...createFeaturePositionOptions(feature),
722
- }, popupOptions, 'api');
723
- }
724
- this._updateTooltip({ layer, feature });
716
+ // The timeout is needed to display the popup immediately when adding a layer to the map.
717
+ // Without a timeout, the layer may not yet have a _map object
718
+ setTimeout(() => {
719
+ if (popup) {
720
+ this._openPopup({
721
+ target: this,
722
+ layer,
723
+ feature,
724
+ ...createFeaturePositionOptions(feature),
725
+ }, popupOptions, 'api');
726
+ }
727
+ this._updateTooltip({ layer, feature });
728
+ });
725
729
  }
726
730
  }
727
731
  }
@@ -1316,6 +1320,15 @@ class OsmAdapter extends TileAdapter {
1316
1320
  }
1317
1321
  }
1318
1322
 
1323
+ function arrayToBoundsExpression(bounds) {
1324
+ const e = bounds;
1325
+ // top, left, bottom, right
1326
+ return [
1327
+ [e[3], e[0]],
1328
+ [e[1], e[2]],
1329
+ ];
1330
+ }
1331
+
1319
1332
  class LeafletMapAdapter$1 {
1320
1333
  constructor() {
1321
1334
  this.options = { target: 'map' };
@@ -1339,10 +1352,7 @@ class LeafletMapAdapter$1 {
1339
1352
  this.map = new Map(this.options.target, {
1340
1353
  attributionControl: false,
1341
1354
  zoomControl: false,
1342
- maxBounds: mb && [
1343
- [mb[1], mb[0]],
1344
- [mb[3], mb[2]],
1345
- ],
1355
+ maxBounds: mb ? arrayToBoundsExpression(mb) : undefined,
1346
1356
  maxZoom,
1347
1357
  minZoom,
1348
1358
  center: center && [center[1], center[0]],
@@ -1379,14 +1389,52 @@ class LeafletMapAdapter$1 {
1379
1389
  this.map.getContainer().style.cursor = cursor;
1380
1390
  }
1381
1391
  }
1382
- setView(lngLat, zoom) {
1383
- const [lng, lat] = lngLat;
1384
- if (this.map) {
1385
- if (typeof zoom === 'number') {
1386
- this.map.setView([lat, lng], zoom, { animate: false });
1392
+ setView(lngLatOrOpt, zoom) {
1393
+ const map = this.map;
1394
+ if (!map)
1395
+ return;
1396
+ if (Array.isArray(lngLatOrOpt)) {
1397
+ const lngLat = lngLatOrOpt;
1398
+ const [lng, lat] = lngLat;
1399
+ if (this.map) {
1400
+ if (typeof zoom === 'number') {
1401
+ this.map.setView([lat, lng], zoom, { animate: false });
1402
+ }
1403
+ else {
1404
+ this.setCenter([lng, lat]);
1405
+ }
1406
+ }
1407
+ }
1408
+ else {
1409
+ const { zoom, center, maxBounds, bounds, minZoom, maxZoom } = lngLatOrOpt;
1410
+ if (center && zoom !== undefined) {
1411
+ this.setView(center, zoom);
1387
1412
  }
1388
1413
  else {
1389
- this.setCenter([lng, lat]);
1414
+ if (zoom !== undefined) {
1415
+ this.setZoom(zoom);
1416
+ }
1417
+ if (center) {
1418
+ this.setCenter(center);
1419
+ }
1420
+ }
1421
+ if (bounds) {
1422
+ this.fitBounds(bounds);
1423
+ }
1424
+ if (maxBounds !== undefined) {
1425
+ if (maxBounds) {
1426
+ map.setMaxBounds(arrayToBoundsExpression(maxBounds));
1427
+ }
1428
+ else {
1429
+ // @ts-ignore `null` works for unset maxBounds, but not in typing
1430
+ map.setMaxBounds(null);
1431
+ }
1432
+ }
1433
+ if (maxZoom !== undefined) {
1434
+ map.setMaxZoom(maxZoom);
1435
+ }
1436
+ if (minZoom !== undefined) {
1437
+ map.setMinZoom(minZoom);
1390
1438
  }
1391
1439
  }
1392
1440
  }
@@ -1421,7 +1469,7 @@ class LeafletMapAdapter$1 {
1421
1469
  return [sw.lng, sw.lat, ne.lng, ne.lat];
1422
1470
  }
1423
1471
  // [west, south, east, north]
1424
- fitBounds(e, options = {}) {
1472
+ fitBounds(bounds, options = {}) {
1425
1473
  if (this.map) {
1426
1474
  const { maxZoom, offset, padding } = options;
1427
1475
  const opt = {};
@@ -1434,11 +1482,7 @@ class LeafletMapAdapter$1 {
1434
1482
  if (offset) {
1435
1483
  opt.padding = offset;
1436
1484
  }
1437
- // top, left, bottom, right
1438
- this.map.fitBounds([
1439
- [e[3], e[0]],
1440
- [e[1], e[2]],
1441
- ], opt);
1485
+ this.map.fitBounds(arrayToBoundsExpression(bounds), opt);
1442
1486
  }
1443
1487
  }
1444
1488
  getLayerAdapter(name) {