@nextgis/ngw-map 1.8.0 → 1.8.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.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.8.1; author: NextGIS */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-map; version: 1.8.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.8.1; author: NextGIS */
2
2
  var events = {exports: {}};
3
3
 
4
4
  var R = typeof Reflect === 'object' ? Reflect : null;
@@ -5269,6 +5269,9 @@ class BaseProperty {
5269
5269
  getParent() {
5270
5270
  return this.item.tree.getParent();
5271
5271
  }
5272
+ getChildren() {
5273
+ return this.item.tree.getChildren();
5274
+ }
5272
5275
  isGroup() {
5273
5276
  const children = this.item.tree.getDescendants();
5274
5277
  return children.length;
@@ -5383,6 +5386,24 @@ class CheckProperty extends BaseProperty {
5383
5386
  return property && property.get();
5384
5387
  }));
5385
5388
  }
5389
+ block(options) {
5390
+ this._blocked = true;
5391
+ this._block(options);
5392
+ }
5393
+ unBlock(options) {
5394
+ this._blocked = false;
5395
+ if (this.getValue()) {
5396
+ this._unBlock(options);
5397
+ }
5398
+ }
5399
+ blockChild(options) {
5400
+ this.item.tree
5401
+ .getDescendants()
5402
+ .forEach((x) => this._blockChild(x, options));
5403
+ }
5404
+ unblockChild(options) {
5405
+ this.item.tree.getChildren().forEach((x) => this._unBlockChild(x, options));
5406
+ }
5386
5407
  _prepareValue(value) {
5387
5408
  return value;
5388
5409
  }
@@ -5404,30 +5425,12 @@ class CheckProperty extends BaseProperty {
5404
5425
  this.unblockChild(options);
5405
5426
  }
5406
5427
  }
5407
- block(options) {
5408
- this._blocked = true;
5409
- this._block(options);
5410
- }
5411
5428
  _block(options) {
5412
5429
  this._turnOff(options);
5413
5430
  }
5414
- unBlock(options) {
5415
- this._blocked = false;
5416
- if (this.getValue()) {
5417
- this._unBlock(options);
5418
- }
5419
- }
5420
5431
  _unBlock(options) {
5421
5432
  this._turnOn(options);
5422
5433
  }
5423
- blockChild(options) {
5424
- this.item.tree
5425
- .getDescendants()
5426
- .forEach((x) => this._blockChild(x, options));
5427
- }
5428
- unblockChild(options) {
5429
- this.item.tree.getChildren().forEach((x) => this._unBlockChild(x, options));
5430
- }
5431
5434
  _blockChild(item, options) {
5432
5435
  const prop = item.properties &&
5433
5436
  item.properties.property(this.name);
@@ -5485,22 +5488,22 @@ class ItemProperties {
5485
5488
  }
5486
5489
  _setPropertyHandler(propOpt) {
5487
5490
  const handlers = ItemProperties.handlers;
5488
- let handler = propOpt.handler;
5489
- if (!handler && propOpt.type) {
5491
+ let Handler = propOpt.handler;
5492
+ if (!Handler && propOpt.type) {
5490
5493
  switch (propOpt.type) {
5491
5494
  case 'boolean':
5492
- handler = handlers.CheckProperty;
5495
+ Handler = handlers.CheckProperty;
5493
5496
  break;
5494
5497
  case 'string':
5495
- handler = handlers.BaseProperty;
5498
+ Handler = handlers.BaseProperty;
5496
5499
  break;
5497
5500
  default:
5498
- handler = handlers.BaseProperty;
5501
+ Handler = handlers.BaseProperty;
5499
5502
  }
5500
5503
  }
5501
- if (handler && propOpt.name) {
5504
+ if (Handler && propOpt.name) {
5502
5505
  const options = { ...(propOpt || {}) };
5503
- this._properties[propOpt.name] = new handler(propOpt.name, this.item, options);
5506
+ this._properties[propOpt.name] = new Handler(propOpt.name, this.item, options);
5504
5507
  this._propertiesList.push(propOpt.name);
5505
5508
  }
5506
5509
  }
@@ -5556,6 +5559,55 @@ class Item {
5556
5559
  }
5557
5560
  }
5558
5561
 
5562
+ class WebmapLayerOpacityPropertyHandler extends BaseProperty {
5563
+ getProperty() {
5564
+ const layer = this.item.layer;
5565
+ if (layer) {
5566
+ return layer && layer.options && layer.options.opacity !== undefined
5567
+ ? layer.options.opacity
5568
+ : 1;
5569
+ }
5570
+ return 1;
5571
+ }
5572
+ update(value, options) {
5573
+ options = options || {};
5574
+ if (this.isGroup()) {
5575
+ this._value = this._prepareValue(value, options);
5576
+ const children = this.getChildren();
5577
+ for (const child of children) {
5578
+ const property = child.properties.property(this.name);
5579
+ if (property) {
5580
+ if (options.propagation) {
5581
+ property.set(value, options);
5582
+ }
5583
+ else {
5584
+ property.update(property.get(), options);
5585
+ }
5586
+ }
5587
+ }
5588
+ }
5589
+ const layer = this.item.layer;
5590
+ if (layer) {
5591
+ const parents = this.getParents();
5592
+ const coef = parents.reduce((s, x) => {
5593
+ const prop = x.properties.property(this.name);
5594
+ const multiplier = prop ? prop.getValue() : 1;
5595
+ return s * multiplier;
5596
+ }, 1);
5597
+ const val = value * coef;
5598
+ this.item.webMap.setLayerOpacity(layer, this._prepareValue(val));
5599
+ }
5600
+ }
5601
+ _prepareValue(value, options) {
5602
+ if (options && options.propagation && this.isGroup()) {
5603
+ return 1;
5604
+ }
5605
+ // value = Number(value);
5606
+ // return value < 0.1 ? 0.1 : value;
5607
+ return Number(value);
5608
+ }
5609
+ }
5610
+
5559
5611
  class NgwWebmapItem extends Item {
5560
5612
  constructor(webMap, item, options, connector, parent, noInit) {
5561
5613
  super({ ...NgwWebmapItem.options, ...options });
@@ -5637,6 +5689,9 @@ class NgwWebmapItem extends Item {
5637
5689
  fit() {
5638
5690
  if (this.item.item_type === 'layer') ;
5639
5691
  }
5692
+ getLayer() {
5693
+ return this.layer;
5694
+ }
5640
5695
  getItemOptions(item) {
5641
5696
  const transparency = item.item_type === 'layer' && item.layer_transparency;
5642
5697
  const opacity = typeof transparency === 'number' ? (100 - transparency) / 100 : undefined;
@@ -5738,6 +5793,10 @@ NgwWebmapItem.options = {
5738
5793
  }
5739
5794
  },
5740
5795
  },
5796
+ {
5797
+ name: 'opacity',
5798
+ handler: WebmapLayerOpacityPropertyHandler,
5799
+ },
5741
5800
  ],
5742
5801
  };
5743
5802
 
@@ -5924,14 +5983,19 @@ class NgwWebmapLayerAdapter {
5924
5983
  delete this.response;
5925
5984
  delete this._webmapLayersIds;
5926
5985
  }
5927
- showLayer() {
5986
+ async showLayer() {
5987
+ if (this.layer && this.layer.properties) {
5988
+ return this.layer.properties.property('visibility').set(true);
5989
+ }
5990
+ }
5991
+ async hideLayer() {
5928
5992
  if (this.layer && this.layer.properties) {
5929
- this.layer.properties.property('visibility').set(true);
5993
+ return this.layer.properties.property('visibility').set(false);
5930
5994
  }
5931
5995
  }
5932
- hideLayer() {
5996
+ async setOpacity(val) {
5933
5997
  if (this.layer && this.layer.properties) {
5934
- this.layer.properties.property('visibility').set(false);
5998
+ return this.layer.properties.property('opacity').set(val);
5935
5999
  }
5936
6000
  }
5937
6001
  /** @deprecated use {@link NgwWebmapLayerAdapter.getBounds} instead */