@nextgis/ngw-map 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/ngw-map; version: 1.8.4; 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
@@ -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,26 +4812,26 @@ 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;
@@ -4830,10 +4841,32 @@ async function createGeoJsonAdapter(props) {
4830
4841
  ...filterArgs.options,
4831
4842
  srs: this.options.srs,
4832
4843
  });
4844
+ let newData = data;
4833
4845
  const count = await this.getCount();
4834
- _fullDataLoad = count === data.features.length;
4835
- await webMap.setLayerData(this, data);
4836
- 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
+ });
4837
4870
  }
4838
4871
  catch (er) {
4839
4872
  if (er instanceof Error && er.name !== 'CancelError') {
@@ -5738,8 +5771,6 @@ class NgwWebmapItem extends Item {
5738
5771
  return setScaleRatio(scale);
5739
5772
  }
5740
5773
  _getZoomRange(item) {
5741
- const minZoomMap = this.webMap.options.minZoom;
5742
- const maxZoomMap = this.webMap.options.maxZoom;
5743
5774
  const minZoomWebmap = this.options.minZoom;
5744
5775
  const maxZoomWebmap = this.options.maxZoom;
5745
5776
  const minZoomLayer = item.layer_min_scale_denom
@@ -5748,8 +5779,8 @@ class NgwWebmapItem extends Item {
5748
5779
  const maxZoomLayer = item.layer_max_scale_denom
5749
5780
  ? this._mapScaleToZoomLevel(item.layer_max_scale_denom)
5750
5781
  : undefined;
5751
- const minZooms = [minZoomMap, minZoomWebmap, minZoomLayer].filter(Boolean);
5752
- const maxZooms = [maxZoomMap, maxZoomWebmap, maxZoomLayer].filter(Boolean);
5782
+ const minZooms = [minZoomWebmap, minZoomLayer].filter(Boolean);
5783
+ const maxZooms = [maxZoomWebmap, maxZoomLayer].filter(Boolean);
5753
5784
  const minZoom = Math.max(...minZooms);
5754
5785
  const maxZoom = Math.min(...maxZooms);
5755
5786
  return { minZoom, maxZoom };