@nextgis/ngw-map 1.6.0 → 1.8.2

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.6.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.8.2; author: NextGIS */
2
2
  var events = {exports: {}};
3
3
 
4
4
  var R = typeof Reflect === 'object' ? Reflect : null;
@@ -2197,8 +2197,10 @@ class WebMapLayers extends WebMapMain {
2197
2197
  */
2198
2198
  async fitLayer(layerDef, options) {
2199
2199
  const layer = this.getLayer(layerDef);
2200
- if (layer && layer.getExtent) {
2201
- const extent = await layer.getExtent();
2200
+ // TODO: remove backward compatibility for `getExtent`
2201
+ const getBounds = layer && (layer.getBounds || layer.getExtent);
2202
+ if (getBounds) {
2203
+ const extent = await getBounds.call(layer);
2202
2204
  if (extent) {
2203
2205
  this.fitBounds(extent, options);
2204
2206
  }
@@ -2401,8 +2403,10 @@ class WebMapLayers extends WebMapMain {
2401
2403
  if (opacity !== undefined && opacity <= 1) {
2402
2404
  this.setLayerOpacity(_adapter, opacity);
2403
2405
  }
2404
- if (options.fit && _adapter.getExtent) {
2405
- const extent = await _adapter.getExtent();
2406
+ // TODO: remove backward compatibility for `getExtent`
2407
+ const getBounds = layer && (_adapter.getBounds || _adapter.getExtent);
2408
+ if (options.fit && getBounds) {
2409
+ const extent = await getBounds.call(_adapter);
2406
2410
  if (extent) {
2407
2411
  await this.fitBounds(extent);
2408
2412
  }
@@ -2579,11 +2583,11 @@ class WebMapLayers extends WebMapMain {
2579
2583
  const order = l.options.baselayer ? 0 : l.options.order;
2580
2584
  // do not show baselayer if another on the map
2581
2585
  if (l.options.baselayer && this._baselayers.length) {
2582
- const anotherVisibleLayerBaseLayer = this._baselayers.find((x) => {
2586
+ const anotherVisibleBaselayers = this._baselayers.filter((x) => {
2583
2587
  return x !== l.id && this.isLayerVisible(x);
2584
2588
  });
2585
- if (anotherVisibleLayerBaseLayer) {
2586
- await this.hideLayer(anotherVisibleLayerBaseLayer);
2589
+ for (const bl of anotherVisibleBaselayers) {
2590
+ await this.hideLayer(bl);
2587
2591
  }
2588
2592
  }
2589
2593
  if (l.showLayer) {
@@ -2619,13 +2623,15 @@ class WebMapLayers extends WebMapMain {
2619
2623
  const layer = this.getLayer(layerDef);
2620
2624
  if (layer) {
2621
2625
  if (layer.updateLayer) {
2622
- layer.updateLayer();
2626
+ return Promise.resolve(layer.updateLayer());
2623
2627
  }
2624
2628
  else if (this.isLayerVisible(layer)) {
2625
- this.hideLayer(layer, { silent: true });
2626
- this.showLayer(layer, { silent: true });
2629
+ return this.hideLayer(layer, { silent: true }).then(() => {
2630
+ return this.showLayer(layer, { silent: true });
2631
+ });
2627
2632
  }
2628
2633
  }
2634
+ return Promise.resolve();
2629
2635
  }
2630
2636
  /**
2631
2637
  * Set transparency for a given layer by number from 0 to 1
@@ -4410,6 +4416,17 @@ function fetchNgwLayerExtent({ resourceId, connector, cache = true, }) {
4410
4416
  }
4411
4417
  });
4412
4418
  }
4419
+ function fetchNgwLayerItemExtent({ resourceId, featureId, connector, cache = true, }) {
4420
+ return connector
4421
+ .get('feature_layer.feature.item_extent', { cache }, { id: resourceId, fid: featureId })
4422
+ .then((resp) => {
4423
+ if (resp) {
4424
+ const { maxLat, maxLon, minLat, minLon } = resp.extent;
4425
+ const extentArray = [minLon, minLat, maxLon, maxLat];
4426
+ return extentArray;
4427
+ }
4428
+ });
4429
+ }
4413
4430
  function fetchNgwResourceExtent(item, connector) {
4414
4431
  if (item.webmap) {
4415
4432
  return CancelablePromise.resolve(getNgwWebmapExtent(item.webmap));
@@ -4758,14 +4775,18 @@ async function createGeoJsonAdapter(props) {
4758
4775
  }
4759
4776
  return layer;
4760
4777
  }
4778
+ /** @deprecated use {@link NgwGeoJsonAdapter.getBounds} instead */
4761
4779
  getExtent() {
4780
+ return this.getBounds();
4781
+ }
4782
+ async getBounds() {
4762
4783
  const hasData = this.getLayers && this.getLayers().length;
4763
4784
  if (this.options.strategy === 'BBOX' || hasData) {
4764
4785
  return fetchNgwResourceExtent(item, connector);
4765
4786
  }
4766
4787
  else {
4767
- if (super.getExtent) {
4768
- return super.getExtent();
4788
+ if (super.getBounds) {
4789
+ return super.getBounds();
4769
4790
  }
4770
4791
  }
4771
4792
  }
@@ -5250,6 +5271,9 @@ class BaseProperty {
5250
5271
  getParent() {
5251
5272
  return this.item.tree.getParent();
5252
5273
  }
5274
+ getChildren() {
5275
+ return this.item.tree.getChildren();
5276
+ }
5253
5277
  isGroup() {
5254
5278
  const children = this.item.tree.getDescendants();
5255
5279
  return children.length;
@@ -5364,6 +5388,24 @@ class CheckProperty extends BaseProperty {
5364
5388
  return property && property.get();
5365
5389
  }));
5366
5390
  }
5391
+ block(options) {
5392
+ this._blocked = true;
5393
+ this._block(options);
5394
+ }
5395
+ unBlock(options) {
5396
+ this._blocked = false;
5397
+ if (this.getValue()) {
5398
+ this._unBlock(options);
5399
+ }
5400
+ }
5401
+ blockChild(options) {
5402
+ this.item.tree
5403
+ .getDescendants()
5404
+ .forEach((x) => this._blockChild(x, options));
5405
+ }
5406
+ unblockChild(options) {
5407
+ this.item.tree.getChildren().forEach((x) => this._unBlockChild(x, options));
5408
+ }
5367
5409
  _prepareValue(value) {
5368
5410
  return value;
5369
5411
  }
@@ -5385,30 +5427,12 @@ class CheckProperty extends BaseProperty {
5385
5427
  this.unblockChild(options);
5386
5428
  }
5387
5429
  }
5388
- block(options) {
5389
- this._blocked = true;
5390
- this._block(options);
5391
- }
5392
5430
  _block(options) {
5393
5431
  this._turnOff(options);
5394
5432
  }
5395
- unBlock(options) {
5396
- this._blocked = false;
5397
- if (this.getValue()) {
5398
- this._unBlock(options);
5399
- }
5400
- }
5401
5433
  _unBlock(options) {
5402
5434
  this._turnOn(options);
5403
5435
  }
5404
- blockChild(options) {
5405
- this.item.tree
5406
- .getDescendants()
5407
- .forEach((x) => this._blockChild(x, options));
5408
- }
5409
- unblockChild(options) {
5410
- this.item.tree.getChildren().forEach((x) => this._unBlockChild(x, options));
5411
- }
5412
5436
  _blockChild(item, options) {
5413
5437
  const prop = item.properties &&
5414
5438
  item.properties.property(this.name);
@@ -5466,22 +5490,22 @@ class ItemProperties {
5466
5490
  }
5467
5491
  _setPropertyHandler(propOpt) {
5468
5492
  const handlers = ItemProperties.handlers;
5469
- let handler = propOpt.handler;
5470
- if (!handler && propOpt.type) {
5493
+ let Handler = propOpt.handler;
5494
+ if (!Handler && propOpt.type) {
5471
5495
  switch (propOpt.type) {
5472
5496
  case 'boolean':
5473
- handler = handlers.CheckProperty;
5497
+ Handler = handlers.CheckProperty;
5474
5498
  break;
5475
5499
  case 'string':
5476
- handler = handlers.BaseProperty;
5500
+ Handler = handlers.BaseProperty;
5477
5501
  break;
5478
5502
  default:
5479
- handler = handlers.BaseProperty;
5503
+ Handler = handlers.BaseProperty;
5480
5504
  }
5481
5505
  }
5482
- if (handler && propOpt.name) {
5506
+ if (Handler && propOpt.name) {
5483
5507
  const options = { ...(propOpt || {}) };
5484
- this._properties[propOpt.name] = new handler(propOpt.name, this.item, options);
5508
+ this._properties[propOpt.name] = new Handler(propOpt.name, this.item, options);
5485
5509
  this._propertiesList.push(propOpt.name);
5486
5510
  }
5487
5511
  }
@@ -5537,6 +5561,55 @@ class Item {
5537
5561
  }
5538
5562
  }
5539
5563
 
5564
+ class WebmapLayerOpacityPropertyHandler extends BaseProperty {
5565
+ getProperty() {
5566
+ const layer = this.item.layer;
5567
+ if (layer) {
5568
+ return layer && layer.options && layer.options.opacity !== undefined
5569
+ ? layer.options.opacity
5570
+ : 1;
5571
+ }
5572
+ return 1;
5573
+ }
5574
+ update(value, options) {
5575
+ options = options || {};
5576
+ if (this.isGroup()) {
5577
+ this._value = this._prepareValue(value, options);
5578
+ const children = this.getChildren();
5579
+ for (const child of children) {
5580
+ const property = child.properties.property(this.name);
5581
+ if (property) {
5582
+ if (options.propagation) {
5583
+ property.set(value, options);
5584
+ }
5585
+ else {
5586
+ property.update(property.get(), options);
5587
+ }
5588
+ }
5589
+ }
5590
+ }
5591
+ const layer = this.item.layer;
5592
+ if (layer) {
5593
+ const parents = this.getParents();
5594
+ const coef = parents.reduce((s, x) => {
5595
+ const prop = x.properties.property(this.name);
5596
+ const multiplier = prop ? prop.getValue() : 1;
5597
+ return s * multiplier;
5598
+ }, 1);
5599
+ const val = value * coef;
5600
+ this.item.webMap.setLayerOpacity(layer, this._prepareValue(val));
5601
+ }
5602
+ }
5603
+ _prepareValue(value, options) {
5604
+ if (options && options.propagation && this.isGroup()) {
5605
+ return 1;
5606
+ }
5607
+ // value = Number(value);
5608
+ // return value < 0.1 ? 0.1 : value;
5609
+ return Number(value);
5610
+ }
5611
+ }
5612
+
5540
5613
  class NgwWebmapItem extends Item {
5541
5614
  constructor(webMap, item, options, connector, parent, noInit) {
5542
5615
  super({ ...NgwWebmapItem.options, ...options });
@@ -5618,6 +5691,9 @@ class NgwWebmapItem extends Item {
5618
5691
  fit() {
5619
5692
  if (this.item.item_type === 'layer') ;
5620
5693
  }
5694
+ getLayer() {
5695
+ return this.layer;
5696
+ }
5621
5697
  getItemOptions(item) {
5622
5698
  const transparency = item.item_type === 'layer' && item.layer_transparency;
5623
5699
  const opacity = typeof transparency === 'number' ? (100 - transparency) / 100 : undefined;
@@ -5719,6 +5795,10 @@ NgwWebmapItem.options = {
5719
5795
  }
5720
5796
  },
5721
5797
  },
5798
+ {
5799
+ name: 'opacity',
5800
+ handler: WebmapLayerOpacityPropertyHandler,
5801
+ },
5722
5802
  ],
5723
5803
  };
5724
5804
 
@@ -5905,17 +5985,26 @@ class NgwWebmapLayerAdapter {
5905
5985
  delete this.response;
5906
5986
  delete this._webmapLayersIds;
5907
5987
  }
5908
- showLayer() {
5988
+ async showLayer() {
5989
+ if (this.layer && this.layer.properties) {
5990
+ return this.layer.properties.property('visibility').set(true);
5991
+ }
5992
+ }
5993
+ async hideLayer() {
5909
5994
  if (this.layer && this.layer.properties) {
5910
- this.layer.properties.property('visibility').set(true);
5995
+ return this.layer.properties.property('visibility').set(false);
5911
5996
  }
5912
5997
  }
5913
- hideLayer() {
5998
+ async setOpacity(val) {
5914
5999
  if (this.layer && this.layer.properties) {
5915
- this.layer.properties.property('visibility').set(false);
6000
+ return this.layer.properties.property('opacity').set(val);
5916
6001
  }
5917
6002
  }
6003
+ /** @deprecated use {@link NgwWebmapLayerAdapter.getBounds} instead */
5918
6004
  getExtent() {
6005
+ return this.getBounds();
6006
+ }
6007
+ getBounds() {
5919
6008
  const webmap = this.response && this.response.webmap;
5920
6009
  if (webmap) {
5921
6010
  return getNgwWebmapExtent(webmap);
@@ -6133,12 +6222,16 @@ async function createWebMapAdapter({ layerOptions: options, webMap, connector, }
6133
6222
  }
6134
6223
 
6135
6224
  class NgwResource {
6225
+ /** @deprecated use {@link NgwResource.getBounds} instead */
6136
6226
  async getExtent() {
6227
+ return this.getBounds();
6228
+ }
6229
+ async getBounds() {
6137
6230
  if (this._extent) {
6138
6231
  return this._extent;
6139
6232
  }
6140
6233
  if (this.item) {
6141
- this._extent = await fetchNgwResourceExtent(this.item, this.connector).then();
6234
+ this._extent = await fetchNgwResourceExtent(this.item, this.connector);
6142
6235
  return this._extent;
6143
6236
  }
6144
6237
  }
@@ -6574,11 +6667,11 @@ class IdentifyItem {
6574
6667
  constructor(options) {
6575
6668
  const f = options.feature;
6576
6669
  this.id = f.id;
6670
+ this.geom = f.geom;
6577
6671
  this.label = f.label;
6578
- this.layerId = f.layerId;
6579
6672
  this.parent = f.parent;
6580
6673
  this.fields = f.fields;
6581
- this.geom = f.geom;
6674
+ this.layerId = f.layerId;
6582
6675
  this.connector = options.connector;
6583
6676
  }
6584
6677
  identify(options = {}) {
@@ -6608,6 +6701,16 @@ class IdentifyItem {
6608
6701
  return this._resource.feature_layer;
6609
6702
  });
6610
6703
  }
6704
+ getBounds() {
6705
+ if (this._extent) {
6706
+ return CancelablePromise.resolve(this._extent);
6707
+ }
6708
+ return fetchNgwLayerItemExtent({
6709
+ connector: this.connector,
6710
+ featureId: this.id,
6711
+ resourceId: this.layerId,
6712
+ });
6713
+ }
6611
6714
  geojson() {
6612
6715
  if (this._geojson) {
6613
6716
  return CancelablePromise.resolve(this._geojson);
@@ -7200,10 +7303,10 @@ class NgwMap extends WebMap {
7200
7303
  }
7201
7304
  const ngwLayer = id && this._ngwLayers[id];
7202
7305
  if (ngwLayer) {
7203
- if (ngwLayer.layer.getExtent) {
7204
- const extent = await ngwLayer.layer.getExtent();
7205
- if (extent) {
7206
- this.fitBounds(extent, options);
7306
+ if (ngwLayer.layer.getBounds) {
7307
+ const bounds = await ngwLayer.layer.getBounds();
7308
+ if (bounds) {
7309
+ this.fitBounds(bounds, options);
7207
7310
  }
7208
7311
  }
7209
7312
  else {