@nextgis/ngw-leaflet 1.7.0 → 1.8.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/ngw-leaflet; version: 1.7.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.8.0; author: NextGIS */
2
2
  function styleInject(css, ref) {
3
3
  if ( ref === void 0 ) ref = {};
4
4
  var insertAt = ref.insertAt;
@@ -16674,11 +16674,11 @@ class WebMapLayers extends WebMapMain {
16674
16674
  const order = l.options.baselayer ? 0 : l.options.order;
16675
16675
  // do not show baselayer if another on the map
16676
16676
  if (l.options.baselayer && this._baselayers.length) {
16677
- const anotherVisibleLayerBaseLayer = this._baselayers.find((x) => {
16677
+ const anotherVisibleBaselayers = this._baselayers.filter((x) => {
16678
16678
  return x !== l.id && this.isLayerVisible(x);
16679
16679
  });
16680
- if (anotherVisibleLayerBaseLayer) {
16681
- await this.hideLayer(anotherVisibleLayerBaseLayer);
16680
+ for (const bl of anotherVisibleBaselayers) {
16681
+ await this.hideLayer(bl);
16682
16682
  }
16683
16683
  }
16684
16684
  if (l.showLayer) {
@@ -21788,7 +21788,8 @@ class BaseAdapter {
21788
21788
  this.pane = pane;
21789
21789
  }
21790
21790
  }
21791
- addLayer(_options) {
21791
+ addLayer(options) {
21792
+ Object.assign(this.options, options);
21792
21793
  return undefined;
21793
21794
  }
21794
21795
  }
@@ -21807,11 +21808,14 @@ class GeoJsonAdapter extends BaseAdapter {
21807
21808
  this.$unselect = () => {
21808
21809
  this.unselect();
21809
21810
  };
21810
- this.layer = new leafletSrc.exports.FeatureGroup([], { pane: this.pane });
21811
21811
  }
21812
21812
  addLayer(options) {
21813
- this.options = options;
21813
+ Object.assign(this.options, options);
21814
21814
  this.paint = options.paint;
21815
+ this.layer = new leafletSrc.exports.FeatureGroup([], {
21816
+ ...options.nativeOptions,
21817
+ pane: this.pane,
21818
+ });
21815
21819
  this.selectedPaint = options.selectedPaint;
21816
21820
  options.paint = this.paint;
21817
21821
  if (options.data) {
@@ -21871,39 +21875,37 @@ class GeoJsonAdapter extends BaseAdapter {
21871
21875
  filter(fun) {
21872
21876
  // Some optimization
21873
21877
  this._filterFun = fun;
21874
- // @ts-ignore
21875
- const _map = this.layer._map;
21876
- if (_map) {
21877
- this.layer.remove();
21878
- }
21879
- const filteredLayers = [];
21880
- this._layers.forEach(({ feature, layer }) => {
21881
- if (layer) {
21882
- const ok = fun
21883
- ? fun({
21884
- target: this,
21885
- feature,
21886
- layer,
21887
- ...createFeaturePositionOptions(feature),
21888
- })
21889
- : true;
21890
- if (ok) {
21891
- this.layer.addLayer(layer);
21892
- filteredLayers.push({
21893
- target: this,
21894
- feature,
21895
- layer,
21896
- ...createFeaturePositionOptions(feature),
21897
- });
21898
- }
21899
- else {
21900
- this.layer.removeLayer(layer);
21878
+ const layer_ = this.layer;
21879
+ const map = layer_ && layer_._map;
21880
+ if (layer_ && map) {
21881
+ layer_.remove();
21882
+ const filteredLayers = [];
21883
+ this._layers.forEach(({ feature, layer }) => {
21884
+ if (layer) {
21885
+ const ok = fun
21886
+ ? fun({
21887
+ target: this,
21888
+ feature,
21889
+ layer,
21890
+ ...createFeaturePositionOptions(feature),
21891
+ })
21892
+ : true;
21893
+ if (ok) {
21894
+ layer_.addLayer(layer);
21895
+ filteredLayers.push({
21896
+ target: this,
21897
+ feature,
21898
+ layer,
21899
+ ...createFeaturePositionOptions(feature),
21900
+ });
21901
+ }
21902
+ else {
21903
+ layer_.removeLayer(layer);
21904
+ }
21901
21905
  }
21902
- }
21903
- });
21904
- this._filteredLayers = filteredLayers;
21905
- if (_map) {
21906
- this.layer.addTo(_map);
21906
+ });
21907
+ this._filteredLayers = filteredLayers;
21908
+ layer_.addTo(map);
21907
21909
  }
21908
21910
  return this._filteredLayers;
21909
21911
  }
@@ -21924,24 +21926,27 @@ class GeoJsonAdapter extends BaseAdapter {
21924
21926
  }
21925
21927
  clearLayer(cb) {
21926
21928
  this.unselect();
21927
- if (cb) {
21928
- for (let fry = this._layers.length; fry--;) {
21929
- const def = this._layers[fry];
21930
- if (def) {
21931
- const { feature, layer } = def;
21932
- if (feature && layer) {
21933
- const exist = cb(feature);
21934
- if (exist) {
21935
- this.layer.removeLayer(layer);
21936
- this._layers.splice(fry, 1);
21929
+ const layer_ = this.layer;
21930
+ if (layer_) {
21931
+ if (cb) {
21932
+ for (let fry = this._layers.length; fry--;) {
21933
+ const def = this._layers[fry];
21934
+ if (def) {
21935
+ const { feature, layer } = def;
21936
+ if (feature && layer) {
21937
+ const exist = cb(feature);
21938
+ if (exist) {
21939
+ layer_.removeLayer(layer);
21940
+ this._layers.splice(fry, 1);
21941
+ }
21937
21942
  }
21938
21943
  }
21939
21944
  }
21940
21945
  }
21941
- }
21942
- else {
21943
- this.layer.clearLayers();
21944
- this._layers = [];
21946
+ else {
21947
+ layer_.clearLayers();
21948
+ this._layers = [];
21949
+ }
21945
21950
  }
21946
21951
  }
21947
21952
  setData(data) {
@@ -22003,8 +22008,10 @@ class GeoJsonAdapter extends BaseAdapter {
22003
22008
  return this.getBounds();
22004
22009
  }
22005
22010
  getBounds() {
22006
- const bounds = this.layer.getBounds();
22007
- return boundsToArray(bounds);
22011
+ if (this.layer) {
22012
+ const bounds = this.layer.getBounds();
22013
+ return boundsToArray(bounds);
22014
+ }
22008
22015
  }
22009
22016
  setOpacity(value) {
22010
22017
  this.options.opacity = value;
@@ -22219,6 +22226,13 @@ class GeoJsonAdapter extends BaseAdapter {
22219
22226
  lopt = this._createPaintOptions(paint, type);
22220
22227
  }
22221
22228
  lopt.onEachFeature = (feature, layer) => {
22229
+ this._onEachFeature(feature, layer);
22230
+ };
22231
+ return lopt;
22232
+ }
22233
+ _onEachFeature(feature, layer) {
22234
+ const layer_ = this.layer;
22235
+ if (layer_) {
22222
22236
  const def = {
22223
22237
  target: this,
22224
22238
  feature,
@@ -22236,7 +22250,7 @@ class GeoJsonAdapter extends BaseAdapter {
22236
22250
  const { popup, popupOptions, selectable, interactive, selectOnHover } = this.options;
22237
22251
  // @ts-ignore
22238
22252
  layer.options.interactive = defined(interactive) ? interactive : true;
22239
- this.layer.addLayer(layer);
22253
+ layer_.addLayer(layer);
22240
22254
  if (selectable) {
22241
22255
  if (selectOnHover) {
22242
22256
  layer.on('mouseover', () => {
@@ -22261,8 +22275,7 @@ class GeoJsonAdapter extends BaseAdapter {
22261
22275
  }
22262
22276
  this._updateTooltip({ layer, feature });
22263
22277
  }
22264
- };
22265
- return lopt;
22278
+ }
22266
22279
  }
22267
22280
  _handleMouseEvents(layer) {
22268
22281
  const isSelected = (l) => this._selectedLayers.indexOf(l) !== -1;
@@ -22666,7 +22679,6 @@ class ImageLayer extends leafletSrc.exports.Layer {
22666
22679
  }
22667
22680
  }
22668
22681
 
22669
- // @ts-ignore
22670
22682
  class ImageAdapter extends BaseAdapter {
22671
22683
  addLayer(options) {
22672
22684
  const url = options && options.url;
@@ -22678,10 +22690,11 @@ class ImageAdapter extends BaseAdapter {
22678
22690
  headers: options.headers,
22679
22691
  setViewDelay: options.setViewDelay,
22680
22692
  /**
22681
- * TODO: safe remove, use only options.params
22693
+ * TODO: safe remove, use only options.nativeOptions
22682
22694
  */
22683
22695
  ...options,
22684
22696
  ...options.params,
22697
+ ...options.nativeOptions,
22685
22698
  });
22686
22699
  if (updateWmsParamsFromOpt) {
22687
22700
  const updateWmsParams = this.layer.updateWmsParams;
@@ -22800,33 +22813,33 @@ const WmsLayer = makeRemote(WmsLayerBase);
22800
22813
 
22801
22814
  class WmsAdapter extends BaseAdapter {
22802
22815
  addLayer(options) {
22803
- if (options) {
22804
- const { url, ...opt } = options;
22805
- if (url) {
22806
- const layerOptions = {
22807
- pane: this.pane,
22808
- attribution: opt.attribution,
22809
- minZoom: opt.minZoom,
22810
- maxZoom: opt.maxZoom,
22811
- layers: options.layers,
22812
- format: options.format,
22813
- };
22814
- let layer;
22815
- if (opt.headers) {
22816
- layer = new WmsLayer(url, { ...layerOptions, headers: opt.headers });
22817
- }
22818
- else {
22819
- layer = new leafletSrc.exports.TileLayer.WMS(url, layerOptions);
22820
- }
22821
- return layer;
22816
+ Object.assign(this.options, options);
22817
+ const { url, ...opt } = options;
22818
+ if (url) {
22819
+ const layerOptions = {
22820
+ pane: this.pane,
22821
+ attribution: opt.attribution,
22822
+ minZoom: opt.minZoom,
22823
+ maxZoom: opt.maxZoom,
22824
+ layers: options.layers,
22825
+ format: options.format,
22826
+ ...options.nativeOptions,
22827
+ };
22828
+ let layer;
22829
+ if (opt.headers) {
22830
+ layer = new WmsLayer(url, { ...layerOptions, headers: opt.headers });
22822
22831
  }
22832
+ else {
22833
+ layer = new leafletSrc.exports.TileLayer.WMS(url, layerOptions);
22834
+ }
22835
+ return layer;
22823
22836
  }
22824
22837
  }
22825
22838
  }
22826
22839
 
22827
22840
  class OsmAdapter extends TileAdapter {
22828
22841
  addLayer(options) {
22829
- const url = options.url || 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
22842
+ const url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
22830
22843
  return super.addLayer({
22831
22844
  name: 'OpenStreetMap',
22832
22845
  attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',