@nextgis/ngw-map 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/ngw-map; version: 1.8.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.9.0; author: NextGIS */
2
2
  var events = {exports: {}};
3
3
 
4
4
  var R = typeof Reflect === 'object' ? Reflect : null;
@@ -1264,10 +1264,6 @@ function isPropertyFilter(filter) {
1264
1264
  }
1265
1265
  return false;
1266
1266
  }
1267
- /** @deprecated use {@link isPropertyFilter} instead */
1268
- function checkIfPropertyFilter(filter) {
1269
- return isPropertyFilter(filter);
1270
- }
1271
1267
  function featureFilter(feature, filters) {
1272
1268
  const properties = { ...feature.properties };
1273
1269
  if (properties) {
@@ -1865,7 +1861,11 @@ class WebMapMain {
1865
1861
  * @returns The map's current zoom level (0-24).
1866
1862
  */
1867
1863
  getZoom() {
1868
- return this.mapAdapter.getZoom();
1864
+ const zoom = this.mapAdapter.getZoom();
1865
+ if (typeof zoom === 'number') {
1866
+ return zoom;
1867
+ }
1868
+ throw Error('Unable to get zoom level. Perhaps the map is not have been initialized yet');
1869
1869
  }
1870
1870
  zoomIn() {
1871
1871
  if (this.mapAdapter.zoomIn) {
@@ -1891,27 +1891,25 @@ class WebMapMain {
1891
1891
  }
1892
1892
  }
1893
1893
  }
1894
- /**
1895
- * Sets the view of the map geographical center and zoom
1896
- * @param lngLat - Array of two numbers representing longitude and latitude of the center of the map view.
1897
- * @param zoom - The zoom level to set (0-24).
1898
- *
1899
- * @example
1900
- * ```javascript
1901
- * // Mount Everest 27° 59′ 17″ N, 86° 55′ 31″ E
1902
- * webMap.setView([86.925278, 27.988056], 12)
1903
- * ```
1904
- */
1905
- setView(lngLat, zoom) {
1906
- if (this.mapAdapter.setView && lngLat && defined(zoom)) {
1907
- this.mapAdapter.setView(lngLat, zoom);
1894
+ setView(lngLatOrOpt, zoom) {
1895
+ if (Array.isArray(lngLatOrOpt)) {
1896
+ const lngLat = lngLatOrOpt;
1897
+ if (this.mapAdapter.setView && lngLat && defined(zoom)) {
1898
+ this.mapAdapter.setView(lngLat, zoom);
1899
+ }
1900
+ else {
1901
+ if (lngLat) {
1902
+ this.mapAdapter.setCenter(lngLat);
1903
+ }
1904
+ if (defined(zoom)) {
1905
+ this.mapAdapter.setZoom(zoom);
1906
+ }
1907
+ }
1908
1908
  }
1909
1909
  else {
1910
- if (lngLat) {
1911
- this.mapAdapter.setCenter(lngLat);
1912
- }
1913
- if (defined(zoom)) {
1914
- this.mapAdapter.setZoom(zoom);
1910
+ const viewOpt = lngLatOrOpt;
1911
+ if (this.mapAdapter.setView) {
1912
+ this.mapAdapter.setView(viewOpt);
1915
1913
  }
1916
1914
  }
1917
1915
  }
@@ -2325,12 +2323,9 @@ class WebMapLayers extends WebMapMain {
2325
2323
  }
2326
2324
  const geoJsonOptions = options;
2327
2325
  this._updateGeoJsonOptions(geoJsonOptions);
2328
- const { maxZoom, minZoom } = this.options;
2329
2326
  options = {
2330
2327
  id: String(id),
2331
2328
  order: _order,
2332
- maxZoom,
2333
- minZoom,
2334
2329
  ...options,
2335
2330
  };
2336
2331
  // options.visibility is a layer global state
@@ -2591,10 +2586,10 @@ class WebMapLayers extends WebMapMain {
2591
2586
  }
2592
2587
  }
2593
2588
  if (l.showLayer) {
2594
- l.showLayer.call(l, l.layer);
2589
+ await l.showLayer.call(l, l.layer);
2595
2590
  }
2596
2591
  else if (l.layer !== undefined) {
2597
- this.mapAdapter.showLayer(l.layer);
2592
+ await this.mapAdapter.showLayer(l.layer);
2598
2593
  }
2599
2594
  if (order !== undefined) {
2600
2595
  this.mapAdapter.setLayerOrder(l.layer, order, this._layers);
@@ -2602,10 +2597,10 @@ class WebMapLayers extends WebMapMain {
2602
2597
  }
2603
2598
  else {
2604
2599
  if (l.hideLayer) {
2605
- l.hideLayer.call(l, l.layer);
2600
+ await l.hideLayer.call(l, l.layer);
2606
2601
  }
2607
2602
  else if (l.layer !== undefined) {
2608
- this.mapAdapter.hideLayer(l.layer);
2603
+ await this.mapAdapter.hideLayer(l.layer);
2609
2604
  }
2610
2605
  }
2611
2606
  if (!silent) {
@@ -2623,13 +2618,15 @@ class WebMapLayers extends WebMapMain {
2623
2618
  const layer = this.getLayer(layerDef);
2624
2619
  if (layer) {
2625
2620
  if (layer.updateLayer) {
2626
- layer.updateLayer();
2621
+ return Promise.resolve(layer.updateLayer());
2627
2622
  }
2628
2623
  else if (this.isLayerVisible(layer)) {
2629
- this.hideLayer(layer, { silent: true });
2630
- this.showLayer(layer, { silent: true });
2624
+ return this.hideLayer(layer, { silent: true }).then(() => {
2625
+ return this.showLayer(layer, { silent: true });
2626
+ });
2631
2627
  }
2632
2628
  }
2629
+ return Promise.resolve();
2633
2630
  }
2634
2631
  /**
2635
2632
  * Set transparency for a given layer by number from 0 to 1
@@ -2863,6 +2860,17 @@ class WebMapLayers extends WebMapMain {
2863
2860
  attribution: tileJson.attribution,
2864
2861
  });
2865
2862
  }
2863
+ /** @internal */
2864
+ _emitLayerEvent(name, id, options) {
2865
+ const name_ = String(name);
2866
+ if (defined(id) && name_.startsWith('layer:')) {
2867
+ const specificLayerName = name_.replace('layer:', 'layer-' + id + ':');
2868
+ // @ts-ignore can't paste template literal key for interface
2869
+ this.emitter.emit(specificLayerName, options);
2870
+ }
2871
+ // @ts-ignore
2872
+ this.emitter.emit(name, options);
2873
+ }
2866
2874
  async _onLayerClick(options) {
2867
2875
  const id = options.layer.id;
2868
2876
  this._emitLayerEvent('layer:click', id || '', options);
@@ -2912,14 +2920,6 @@ class WebMapLayers extends WebMapMain {
2912
2920
  }
2913
2921
  }
2914
2922
  }
2915
- _emitLayerEvent(name, id, options) {
2916
- if (defined(id) && name.startsWith('layer:')) {
2917
- const specificLayerName = name.replace('layer:', 'layer-' + id + ':');
2918
- // @ts-ignore can't paste template literal key for interface
2919
- this.emitter.emit(specificLayerName, options);
2920
- }
2921
- this.emitter.emit(name, options);
2922
- }
2923
2923
  }
2924
2924
 
2925
2925
  /**
@@ -4522,7 +4522,7 @@ function createFeatureFieldFilterQueries(opt, _queries = [], _parentAllParams =
4522
4522
  };
4523
4523
  if (logic === 'any') {
4524
4524
  filters_.forEach((f) => {
4525
- if (checkIfPropertyFilter(f)) {
4525
+ if (isPropertyFilter(f)) {
4526
4526
  _queries.push(fetchNgwLayerItemsRequest({
4527
4527
  ...opt,
4528
4528
  paramList: [..._parentAllParams, createParam(f)],
@@ -4540,7 +4540,7 @@ function createFeatureFieldFilterQueries(opt, _queries = [], _parentAllParams =
4540
4540
  const filters = [];
4541
4541
  const propertiesFilterList = [];
4542
4542
  for (const f of filters_) {
4543
- if (checkIfPropertyFilter(f)) {
4543
+ if (isPropertyFilter(f)) {
4544
4544
  filters.push(createParam(f));
4545
4545
  }
4546
4546
  else {
@@ -4685,12 +4685,23 @@ function fetchNgwLayerFeatureCollection(options) {
4685
4685
  });
4686
4686
  }
4687
4687
 
4688
+ function fetchNgwLayerCount({ connector, resourceId, cache = true, }) {
4689
+ return connector
4690
+ .get('feature_layer.feature.count', { cache }, {
4691
+ id: resourceId,
4692
+ })
4693
+ .then((resp) => {
4694
+ return resp.total_count;
4695
+ });
4696
+ }
4697
+
4688
4698
  async function createGeoJsonAdapter(props) {
4689
4699
  var _a, _b;
4690
4700
  const { item, webMap, Adapter, connector, layerOptions, addLayerOptionsPriority: alop, } = props;
4691
4701
  const addLayerOptionsPriority = alop !== null && alop !== void 0 ? alop : true;
4692
4702
  const options = layerOptions;
4693
4703
  const GeoJsonAdapter = Adapter || webMap.mapAdapter.layerAdapters.GEOJSON;
4704
+ const _loadedIds = [];
4694
4705
  let _fullDataLoad = false;
4695
4706
  let _lastFilterArgs;
4696
4707
  let _dataPromise;
@@ -4755,8 +4766,9 @@ async function createGeoJsonAdapter(props) {
4755
4766
  opt.data = undefined;
4756
4767
  needUpdate = false;
4757
4768
  }
4769
+ const strategy = opt.strategy || undefined;
4770
+ this.options.strategy = strategy;
4758
4771
  const layer = super.addLayer(opt);
4759
- this.options.strategy = opt.strategy || undefined;
4760
4772
  _lastFilterArgs = {
4761
4773
  filters: opt.propertiesFilter,
4762
4774
  options: getLayerFilterOptions(opt),
@@ -4768,7 +4780,7 @@ async function createGeoJsonAdapter(props) {
4768
4780
  if (waitFullLoad && updatePromise) {
4769
4781
  await updatePromise;
4770
4782
  }
4771
- if (this.options.strategy === 'BBOX' && !_fullDataLoad) {
4783
+ if (strategy && strategy.startsWith('BBOX') && !_fullDataLoad) {
4772
4784
  this._addBboxEventListener();
4773
4785
  }
4774
4786
  return layer;
@@ -4779,7 +4791,8 @@ async function createGeoJsonAdapter(props) {
4779
4791
  }
4780
4792
  async getBounds() {
4781
4793
  const hasData = this.getLayers && this.getLayers().length;
4782
- if (this.options.strategy === 'BBOX' || hasData) {
4794
+ const strategy = this.options.strategy;
4795
+ if ((strategy === null || strategy === void 0 ? void 0 : strategy.startsWith('BBOX')) || hasData) {
4783
4796
  return fetchNgwResourceExtent(item, connector);
4784
4797
  }
4785
4798
  else {
@@ -4799,26 +4812,26 @@ async function createGeoJsonAdapter(props) {
4799
4812
  abort();
4800
4813
  }
4801
4814
  getCount() {
4802
- if (this._count !== undefined) {
4803
- return this._count;
4804
- }
4805
- return connector
4806
- .get('feature_layer.feature.count', { cache: true }, {
4807
- id: resourceId,
4808
- })
4809
- .then((resp) => {
4810
- if (resp) {
4811
- this._count = resp.total_count;
4812
- return this._count;
4813
- }
4814
- });
4815
+ return fetchNgwLayerCount({ connector, resourceId, cache: true });
4815
4816
  }
4816
4817
  async updateLayer(filterArgs) {
4818
+ var _a;
4817
4819
  filterArgs = filterArgs || _lastFilterArgs || {};
4818
- if (this.options.strategy === 'BBOX') {
4820
+ if ((_a = this.options.strategy) === null || _a === void 0 ? void 0 : _a.startsWith('BBOX')) {
4819
4821
  await webMap.onLoad('create');
4820
4822
  filterArgs.options = filterArgs.options || {};
4821
4823
  filterArgs.options.intersects = webMap.getBounds();
4824
+ const { minZoom, maxZoom } = this.options;
4825
+ const zoom = webMap.getZoom();
4826
+ if (minZoom !== undefined && zoom < minZoom) {
4827
+ return;
4828
+ }
4829
+ if (maxZoom !== undefined && zoom > maxZoom) {
4830
+ return;
4831
+ }
4832
+ if (_fullDataLoad) {
4833
+ return;
4834
+ }
4822
4835
  }
4823
4836
  if (removed) {
4824
4837
  return;
@@ -4828,10 +4841,32 @@ async function createGeoJsonAdapter(props) {
4828
4841
  ...filterArgs.options,
4829
4842
  srs: this.options.srs,
4830
4843
  });
4844
+ let newData = data;
4831
4845
  const count = await this.getCount();
4832
- _fullDataLoad = count === data.features.length;
4833
- await webMap.setLayerData(this, data);
4834
- this.emitter.emit('updated');
4846
+ if (this.options.strategy === 'BBOX+') {
4847
+ newData = {
4848
+ type: 'FeatureCollection',
4849
+ features: [],
4850
+ };
4851
+ for (const f of data.features) {
4852
+ if (_loadedIds.indexOf(String(f.id)) === -1) {
4853
+ _loadedIds.push(String(f.id));
4854
+ newData.features.push(f);
4855
+ }
4856
+ }
4857
+ _fullDataLoad = count !== undefined && _loadedIds.length >= count;
4858
+ await webMap.addLayerData(this, newData);
4859
+ }
4860
+ else {
4861
+ _fullDataLoad = count !== undefined && data.features.length >= count;
4862
+ await webMap.setLayerData(this, data);
4863
+ }
4864
+ this.emitter.emit('updated', data);
4865
+ webMap._emitLayerEvent('layer:updated', options.id || '', {
4866
+ data,
4867
+ newData,
4868
+ isFull: _fullDataLoad,
4869
+ });
4835
4870
  }
4836
4871
  catch (er) {
4837
4872
  if (er instanceof Error && er.name !== 'CancelError') {
@@ -5712,12 +5747,7 @@ class NgwWebmapItem extends Item {
5712
5747
  options.order = Number((this.options.order | 0) + '.' + subLevel);
5713
5748
  }
5714
5749
  if (item.item_type === 'layer') {
5715
- const maxZoom = item.layer_max_scale_denom
5716
- ? this._mapScaleToZoomLevel(item.layer_max_scale_denom)
5717
- : this.webMap.options.maxZoom;
5718
- const minZoom = item.layer_min_scale_denom
5719
- ? this._mapScaleToZoomLevel(item.layer_min_scale_denom)
5720
- : this.webMap.options.minZoom;
5750
+ const { maxZoom, minZoom } = this._getZoomRange(item);
5721
5751
  objectAssign(options, {
5722
5752
  updateWmsParams: item.updateWmsParams,
5723
5753
  url: item.url,
@@ -5740,6 +5770,21 @@ class NgwWebmapItem extends Item {
5740
5770
  _mapScaleToZoomLevel(scale) {
5741
5771
  return setScaleRatio(scale);
5742
5772
  }
5773
+ _getZoomRange(item) {
5774
+ const minZoomWebmap = this.options.minZoom;
5775
+ const maxZoomWebmap = this.options.maxZoom;
5776
+ const minZoomLayer = item.layer_min_scale_denom
5777
+ ? this._mapScaleToZoomLevel(item.layer_min_scale_denom)
5778
+ : undefined;
5779
+ const maxZoomLayer = item.layer_max_scale_denom
5780
+ ? this._mapScaleToZoomLevel(item.layer_max_scale_denom)
5781
+ : undefined;
5782
+ const minZooms = [minZoomWebmap, minZoomLayer].filter(Boolean);
5783
+ const maxZooms = [maxZoomWebmap, maxZoomLayer].filter(Boolean);
5784
+ const minZoom = Math.max(...minZooms);
5785
+ const maxZoom = Math.min(...maxZooms);
5786
+ return { minZoom, maxZoom };
5787
+ }
5743
5788
  _init(item) {
5744
5789
  this.initItem(item).then(() => {
5745
5790
  this.emitter.emit('init');
@@ -5818,15 +5863,23 @@ async function createOnFirstShowAdapter({ webMap, adapterOptions = {}, onLayerAd
5818
5863
  destroyed() {
5819
5864
  return this._removed;
5820
5865
  }
5821
- showLayer() {
5866
+ async showLayer() {
5822
5867
  this.options.visibility = true;
5823
5868
  if (this.layer.length) {
5824
- this.layer.forEach((x) => {
5825
- webMap.showLayer(x);
5826
- });
5869
+ for (const x of this.layer) {
5870
+ await webMap.showLayer(x);
5871
+ }
5827
5872
  }
5828
5873
  else {
5829
- this.loadLayer();
5874
+ await this.loadLayer();
5875
+ }
5876
+ }
5877
+ async hideLayer() {
5878
+ this.options.visibility = false;
5879
+ if (this.layer) {
5880
+ for (const x of this.layer) {
5881
+ await webMap.hideLayer(x);
5882
+ }
5830
5883
  }
5831
5884
  }
5832
5885
  async loadLayer() {
@@ -5850,21 +5903,15 @@ async function createOnFirstShowAdapter({ webMap, adapterOptions = {}, onLayerAd
5850
5903
  if (this._removed) {
5851
5904
  webMap.removeLayer(adapter);
5852
5905
  }
5906
+ this.layer.push(adapter);
5853
5907
  if (this.options.visibility) {
5854
5908
  await webMap.showLayer(adapter);
5855
5909
  }
5856
- this.layer.push(adapter);
5857
5910
  this._creatingInProgress = false;
5858
5911
  }
5859
5912
  }
5860
5913
  return this.layer;
5861
5914
  }
5862
- hideLayer() {
5863
- this.options.visibility = false;
5864
- if (this.layer) {
5865
- this.layer.forEach((x) => webMap.hideLayer(x));
5866
- }
5867
- }
5868
5915
  }
5869
5916
  return OnFirstShowAdapter;
5870
5917
  }
@@ -6087,6 +6134,8 @@ class NgwWebmapLayerAdapter {
6087
6134
  options.order = this.options.order;
6088
6135
  options.ratio = this.options.ratio;
6089
6136
  options.crossOrigin = this.options.crossOrigin;
6137
+ options.minZoom = this.options.minZoom;
6138
+ options.maxZoom = this.options.maxZoom;
6090
6139
  options.drawOrderEnabled = webmap.draw_order_enabled;
6091
6140
  const layer = new this.NgwWebmapItem(this.options.webMap, webmap.root_item, options, this.options.connector);
6092
6141
  layer.emitter.on('init', () => resolve(layer));