@nextgis/ngw-map 1.8.2 → 1.9.1

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.2; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.9.1; 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) {
@@ -2865,6 +2860,17 @@ class WebMapLayers extends WebMapMain {
2865
2860
  attribution: tileJson.attribution,
2866
2861
  });
2867
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
+ }
2868
2874
  async _onLayerClick(options) {
2869
2875
  const id = options.layer.id;
2870
2876
  this._emitLayerEvent('layer:click', id || '', options);
@@ -2914,14 +2920,6 @@ class WebMapLayers extends WebMapMain {
2914
2920
  }
2915
2921
  }
2916
2922
  }
2917
- _emitLayerEvent(name, id, options) {
2918
- if (defined(id) && name.startsWith('layer:')) {
2919
- const specificLayerName = name.replace('layer:', 'layer-' + id + ':');
2920
- // @ts-ignore can't paste template literal key for interface
2921
- this.emitter.emit(specificLayerName, options);
2922
- }
2923
- this.emitter.emit(name, options);
2924
- }
2925
2923
  }
2926
2924
 
2927
2925
  /**
@@ -4524,7 +4522,7 @@ function createFeatureFieldFilterQueries(opt, _queries = [], _parentAllParams =
4524
4522
  };
4525
4523
  if (logic === 'any') {
4526
4524
  filters_.forEach((f) => {
4527
- if (checkIfPropertyFilter(f)) {
4525
+ if (isPropertyFilter(f)) {
4528
4526
  _queries.push(fetchNgwLayerItemsRequest({
4529
4527
  ...opt,
4530
4528
  paramList: [..._parentAllParams, createParam(f)],
@@ -4542,7 +4540,7 @@ function createFeatureFieldFilterQueries(opt, _queries = [], _parentAllParams =
4542
4540
  const filters = [];
4543
4541
  const propertiesFilterList = [];
4544
4542
  for (const f of filters_) {
4545
- if (checkIfPropertyFilter(f)) {
4543
+ if (isPropertyFilter(f)) {
4546
4544
  filters.push(createParam(f));
4547
4545
  }
4548
4546
  else {
@@ -4687,12 +4685,23 @@ function fetchNgwLayerFeatureCollection(options) {
4687
4685
  });
4688
4686
  }
4689
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
+
4690
4698
  async function createGeoJsonAdapter(props) {
4691
4699
  var _a, _b;
4692
4700
  const { item, webMap, Adapter, connector, layerOptions, addLayerOptionsPriority: alop, } = props;
4693
4701
  const addLayerOptionsPriority = alop !== null && alop !== void 0 ? alop : true;
4694
4702
  const options = layerOptions;
4695
4703
  const GeoJsonAdapter = Adapter || webMap.mapAdapter.layerAdapters.GEOJSON;
4704
+ const _loadedIds = [];
4696
4705
  let _fullDataLoad = false;
4697
4706
  let _lastFilterArgs;
4698
4707
  let _dataPromise;
@@ -4757,8 +4766,9 @@ async function createGeoJsonAdapter(props) {
4757
4766
  opt.data = undefined;
4758
4767
  needUpdate = false;
4759
4768
  }
4769
+ const strategy = opt.strategy || undefined;
4770
+ this.options.strategy = strategy;
4760
4771
  const layer = super.addLayer(opt);
4761
- this.options.strategy = opt.strategy || undefined;
4762
4772
  _lastFilterArgs = {
4763
4773
  filters: opt.propertiesFilter,
4764
4774
  options: getLayerFilterOptions(opt),
@@ -4770,7 +4780,7 @@ async function createGeoJsonAdapter(props) {
4770
4780
  if (waitFullLoad && updatePromise) {
4771
4781
  await updatePromise;
4772
4782
  }
4773
- if (this.options.strategy === 'BBOX' && !_fullDataLoad) {
4783
+ if (strategy && strategy.startsWith('BBOX') && !_fullDataLoad) {
4774
4784
  this._addBboxEventListener();
4775
4785
  }
4776
4786
  return layer;
@@ -4781,7 +4791,8 @@ async function createGeoJsonAdapter(props) {
4781
4791
  }
4782
4792
  async getBounds() {
4783
4793
  const hasData = this.getLayers && this.getLayers().length;
4784
- 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) {
4785
4796
  return fetchNgwResourceExtent(item, connector);
4786
4797
  }
4787
4798
  else {
@@ -4801,39 +4812,63 @@ async function createGeoJsonAdapter(props) {
4801
4812
  abort();
4802
4813
  }
4803
4814
  getCount() {
4804
- if (this._count !== undefined) {
4805
- return this._count;
4806
- }
4807
- return connector
4808
- .get('feature_layer.feature.count', { cache: true }, {
4809
- id: resourceId,
4810
- })
4811
- .then((resp) => {
4812
- if (resp) {
4813
- this._count = resp.total_count;
4814
- return this._count;
4815
- }
4816
- });
4815
+ return fetchNgwLayerCount({ connector, resourceId, cache: true });
4817
4816
  }
4818
4817
  async updateLayer(filterArgs) {
4818
+ var _a;
4819
4819
  filterArgs = filterArgs || _lastFilterArgs || {};
4820
- if (this.options.strategy === 'BBOX') {
4820
+ if ((_a = this.options.strategy) === null || _a === void 0 ? void 0 : _a.startsWith('BBOX')) {
4821
4821
  await webMap.onLoad('create');
4822
4822
  filterArgs.options = filterArgs.options || {};
4823
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
+ }
4824
4835
  }
4825
4836
  if (removed) {
4826
4837
  return;
4827
4838
  }
4828
4839
  try {
4840
+ this.emitter.emit('preupdate', filterArgs);
4841
+ webMap._emitLayerEvent('layer:preupdate', options.id || '', filterArgs);
4829
4842
  const data = await getData(filterArgs.filters, {
4830
4843
  ...filterArgs.options,
4831
4844
  srs: this.options.srs,
4832
4845
  });
4846
+ let newData = data;
4833
4847
  const count = await this.getCount();
4834
- _fullDataLoad = count === data.features.length;
4835
- await webMap.setLayerData(this, data);
4836
- this.emitter.emit('updated');
4848
+ if (this.options.strategy === 'BBOX+') {
4849
+ newData = {
4850
+ type: 'FeatureCollection',
4851
+ features: [],
4852
+ };
4853
+ for (const f of data.features) {
4854
+ if (_loadedIds.indexOf(String(f.id)) === -1) {
4855
+ _loadedIds.push(String(f.id));
4856
+ newData.features.push(f);
4857
+ }
4858
+ }
4859
+ _fullDataLoad = count !== undefined && _loadedIds.length >= count;
4860
+ await webMap.addLayerData(this, newData);
4861
+ }
4862
+ else {
4863
+ _fullDataLoad = count !== undefined && data.features.length >= count;
4864
+ await webMap.setLayerData(this, data);
4865
+ }
4866
+ this.emitter.emit('updated', data);
4867
+ webMap._emitLayerEvent('layer:updated', options.id || '', {
4868
+ data,
4869
+ newData,
4870
+ isFull: _fullDataLoad,
4871
+ });
4837
4872
  }
4838
4873
  catch (er) {
4839
4874
  if (er instanceof Error && er.name !== 'CancelError') {
@@ -5714,12 +5749,7 @@ class NgwWebmapItem extends Item {
5714
5749
  options.order = Number((this.options.order | 0) + '.' + subLevel);
5715
5750
  }
5716
5751
  if (item.item_type === 'layer') {
5717
- const maxZoom = item.layer_max_scale_denom
5718
- ? this._mapScaleToZoomLevel(item.layer_max_scale_denom)
5719
- : this.webMap.options.maxZoom;
5720
- const minZoom = item.layer_min_scale_denom
5721
- ? this._mapScaleToZoomLevel(item.layer_min_scale_denom)
5722
- : this.webMap.options.minZoom;
5752
+ const { maxZoom, minZoom } = this._getZoomRange(item);
5723
5753
  objectAssign(options, {
5724
5754
  updateWmsParams: item.updateWmsParams,
5725
5755
  url: item.url,
@@ -5742,6 +5772,21 @@ class NgwWebmapItem extends Item {
5742
5772
  _mapScaleToZoomLevel(scale) {
5743
5773
  return setScaleRatio(scale);
5744
5774
  }
5775
+ _getZoomRange(item) {
5776
+ const minZoomWebmap = this.options.minZoom;
5777
+ const maxZoomWebmap = this.options.maxZoom;
5778
+ const minZoomLayer = item.layer_min_scale_denom
5779
+ ? this._mapScaleToZoomLevel(item.layer_min_scale_denom)
5780
+ : undefined;
5781
+ const maxZoomLayer = item.layer_max_scale_denom
5782
+ ? this._mapScaleToZoomLevel(item.layer_max_scale_denom)
5783
+ : undefined;
5784
+ const minZooms = [minZoomWebmap, minZoomLayer].filter(Boolean);
5785
+ const maxZooms = [maxZoomWebmap, maxZoomLayer].filter(Boolean);
5786
+ const minZoom = Math.max(...minZooms);
5787
+ const maxZoom = Math.min(...maxZooms);
5788
+ return { minZoom, maxZoom };
5789
+ }
5745
5790
  _init(item) {
5746
5791
  this.initItem(item).then(() => {
5747
5792
  this.emitter.emit('init');
@@ -5820,15 +5865,23 @@ async function createOnFirstShowAdapter({ webMap, adapterOptions = {}, onLayerAd
5820
5865
  destroyed() {
5821
5866
  return this._removed;
5822
5867
  }
5823
- showLayer() {
5868
+ async showLayer() {
5824
5869
  this.options.visibility = true;
5825
5870
  if (this.layer.length) {
5826
- this.layer.forEach((x) => {
5827
- webMap.showLayer(x);
5828
- });
5871
+ for (const x of this.layer) {
5872
+ await webMap.showLayer(x);
5873
+ }
5829
5874
  }
5830
5875
  else {
5831
- this.loadLayer();
5876
+ await this.loadLayer();
5877
+ }
5878
+ }
5879
+ async hideLayer() {
5880
+ this.options.visibility = false;
5881
+ if (this.layer) {
5882
+ for (const x of this.layer) {
5883
+ await webMap.hideLayer(x);
5884
+ }
5832
5885
  }
5833
5886
  }
5834
5887
  async loadLayer() {
@@ -5852,21 +5905,15 @@ async function createOnFirstShowAdapter({ webMap, adapterOptions = {}, onLayerAd
5852
5905
  if (this._removed) {
5853
5906
  webMap.removeLayer(adapter);
5854
5907
  }
5908
+ this.layer.push(adapter);
5855
5909
  if (this.options.visibility) {
5856
5910
  await webMap.showLayer(adapter);
5857
5911
  }
5858
- this.layer.push(adapter);
5859
5912
  this._creatingInProgress = false;
5860
5913
  }
5861
5914
  }
5862
5915
  return this.layer;
5863
5916
  }
5864
- hideLayer() {
5865
- this.options.visibility = false;
5866
- if (this.layer) {
5867
- this.layer.forEach((x) => webMap.hideLayer(x));
5868
- }
5869
- }
5870
5917
  }
5871
5918
  return OnFirstShowAdapter;
5872
5919
  }
@@ -6089,6 +6136,8 @@ class NgwWebmapLayerAdapter {
6089
6136
  options.order = this.options.order;
6090
6137
  options.ratio = this.options.ratio;
6091
6138
  options.crossOrigin = this.options.crossOrigin;
6139
+ options.minZoom = this.options.minZoom;
6140
+ options.maxZoom = this.options.maxZoom;
6092
6141
  options.drawOrderEnabled = webmap.draw_order_enabled;
6093
6142
  const layer = new this.NgwWebmapItem(this.options.webMap, webmap.root_item, options, this.options.connector);
6094
6143
  layer.emitter.on('init', () => resolve(layer));