@nextgis/ngw-leaflet 1.15.1 → 1.16.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-leaflet; version: 1.15.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.16.0; author: NextGIS */
2
2
  import 'leaflet/dist/leaflet.css';
3
3
  import { Icon } from 'leaflet';
4
4
  import { NgwMap } from '@nextgis/ngw-map';
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-leaflet; version: 1.15.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.16.0; author: NextGIS */
2
2
  var NgwLeaflet = (function () {
3
3
  'use strict';
4
4
 
@@ -15616,6 +15616,24 @@ var NgwLeaflet = (function () {
15616
15616
  return mask;
15617
15617
  };
15618
15618
  }
15619
+ function expressionCallback(paint, defaultPaint, getPaintFunctions) {
15620
+ var expressionCallback = createExpressionCallback(paint);
15621
+ if (expressionCallback) {
15622
+ var expressionPaintCb = function (feature) {
15623
+ return preparePaint(expressionCallback(feature), defaultPaint, getPaintFunctions);
15624
+ };
15625
+ expressionPaintCb.paint = paint;
15626
+ return expressionPaintCb;
15627
+ }
15628
+ var newPaint = __assign({}, defaultPaint);
15629
+ newPaint = __assign(__assign({}, newPaint), paint);
15630
+ newPaint.fill = newPaint.fill !== undefined ? newPaint.fill : true;
15631
+ newPaint.stroke =
15632
+ newPaint.stroke !== undefined
15633
+ ? newPaint.stroke
15634
+ : !newPaint.fill || !!(newPaint.strokeColor || newPaint.strokeOpacity);
15635
+ return newPaint;
15636
+ }
15619
15637
  function preparePaint(paint, defaultPaint, getPaintFunctions) {
15620
15638
  if (!paint) {
15621
15639
  throw new Error('paint is empty');
@@ -15645,20 +15663,7 @@ var NgwLeaflet = (function () {
15645
15663
  return paint;
15646
15664
  }
15647
15665
  else {
15648
- var expressionCallback_1 = createExpressionCallback(paint);
15649
- if (expressionCallback_1) {
15650
- var expressionPaintCb = function (feature) {
15651
- return preparePaint(expressionCallback_1(feature), defaultPaint, getPaintFunctions);
15652
- };
15653
- expressionPaintCb.paint = paint;
15654
- return expressionPaintCb;
15655
- }
15656
- newPaint = __assign(__assign({}, newPaint), paint);
15657
- newPaint.fill = newPaint.fill !== undefined ? newPaint.fill : true;
15658
- newPaint.stroke =
15659
- newPaint.stroke !== undefined
15660
- ? newPaint.stroke
15661
- : !newPaint.fill || !!(newPaint.strokeColor || newPaint.strokeOpacity);
15666
+ newPaint = expressionCallback(paint, defaultPaint, getPaintFunctions);
15662
15667
  }
15663
15668
  if (isPaintCallback(newPaint)) {
15664
15669
  return newPaint;
@@ -20706,10 +20711,12 @@ var NgwLeaflet = (function () {
20706
20711
  };
20707
20712
  if (item.item_type === 'group' || item.item_type === 'root') {
20708
20713
  if (item.children && item.children.length) {
20709
- this.getChildren(item).forEach(function (x) {
20710
- var children = new NgwWebmapItem(_this.webMap, x, _this.options, _this.connector, _this);
20711
- _this.tree.addChild(children);
20712
- });
20714
+ var children = this.getChildren(item);
20715
+ for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
20716
+ var x = children_1[_i];
20717
+ var children_2 = new this.constructor(this.webMap, x, this.options, this.connector, this);
20718
+ this.tree.addChild(children_2);
20719
+ }
20713
20720
  }
20714
20721
  return Promise.resolve();
20715
20722
  }
@@ -20750,7 +20757,7 @@ var NgwLeaflet = (function () {
20750
20757
  headers: this.options.headers,
20751
20758
  crossOrigin: this.options.crossOrigin,
20752
20759
  setViewDelay: this.options.setViewDelay,
20753
- params: { resource: this.item.resourceId },
20760
+ params: { resource: this.item.resourceId, item: this.item },
20754
20761
  };
20755
20762
  if (this.options.order) {
20756
20763
  var subOrder = this.options.drawOrderEnabled && 'draw_order_position' in item
@@ -20761,6 +20768,9 @@ var NgwLeaflet = (function () {
20761
20768
  var subLevel = String(subOrder).padStart(4, '0');
20762
20769
  options.order = Number((this.options.order | 0) + '.' + subLevel);
20763
20770
  }
20771
+ if (this.options.popupOptions) {
20772
+ options.popupOptions = this.options.popupOptions;
20773
+ }
20764
20774
  if (item.item_type === 'layer') {
20765
20775
  var _a = this._getZoomRange(item), maxZoom = _a.maxZoom, minZoom = _a.minZoom;
20766
20776
  objectAssign(options, {
@@ -20808,8 +20818,8 @@ var NgwLeaflet = (function () {
20808
20818
  };
20809
20819
  NgwWebmapItem.prototype._sumUp = function (children, totalValue) {
20810
20820
  if (totalValue === void 0) { totalValue = 0; }
20811
- for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
20812
- var child = children_1[_i];
20821
+ for (var _i = 0, children_3 = children; _i < children_3.length; _i++) {
20822
+ var child = children_3[_i];
20813
20823
  if (child.item_type === 'layer') {
20814
20824
  totalValue += 1;
20815
20825
  child.draw_order_position = child.draw_order_position || totalValue;
@@ -21116,8 +21126,6 @@ var NgwLeaflet = (function () {
21116
21126
  this._extent &&
21117
21127
  extentConstrained) {
21118
21128
  this.options.webMap.setView({ maxBounds: this._extent });
21119
- // @ts-ignore
21120
- window.webmap = this.options.webMap;
21121
21129
  }
21122
21130
  return [2 /*return*/, this.layer];
21123
21131
  }
@@ -21290,6 +21298,7 @@ var NgwLeaflet = (function () {
21290
21298
  options.minZoom = _this.options.minZoom;
21291
21299
  options.maxZoom = _this.options.maxZoom;
21292
21300
  options.drawOrderEnabled = webmap_1.draw_order_enabled;
21301
+ options.popupOptions = _this.options.popupOptions;
21293
21302
  var layer = new _this.NgwWebmapItem(_this.options.webMap, webmap_1.root_item, options, _this.options.connector);
21294
21303
  layer.emitter.on('init', function () { return resolve(layer); });
21295
21304
  })];
@@ -21420,30 +21429,34 @@ var NgwLeaflet = (function () {
21420
21429
  };
21421
21430
  NgwWebmapLayerAdapter.prototype._getWebMapIds = function () {
21422
21431
  return __awaiter(this, void 0, void 0, function () {
21423
- var webMapItem, layers, promises_1, ids;
21424
- var _this = this;
21432
+ var webMapItem, layers, promises, _loop_2, this_2, _i, layers_1, x, ids;
21425
21433
  return __generator(this, function (_a) {
21426
21434
  switch (_a.label) {
21427
21435
  case 0:
21428
21436
  webMapItem = this.layer;
21429
21437
  if (!(webMapItem && webMapItem.item.item_type === 'root')) return [3 /*break*/, 2];
21430
21438
  layers = webMapItem.tree.getDescendants();
21431
- promises_1 = [];
21432
- layers.forEach(function (x) {
21439
+ promises = [];
21440
+ _loop_2 = function (x) {
21433
21441
  var item = x.item;
21434
21442
  if (item.item_type === 'layer') {
21435
21443
  var id = item.layer_style_id;
21436
- var promise = _this.options.connector.getResource(id).then(function (y) {
21444
+ var promise = this_2.options.connector.getResource(id).then(function (y) {
21437
21445
  if (y) {
21438
21446
  var parentId = Number(y.resource.parent.id);
21439
21447
  item.parentId = parentId;
21440
21448
  return parentId;
21441
21449
  }
21442
21450
  });
21443
- promises_1.push(promise);
21451
+ promises.push(promise);
21444
21452
  }
21445
- });
21446
- return [4 /*yield*/, Promise.all(promises_1)];
21453
+ };
21454
+ this_2 = this;
21455
+ for (_i = 0, layers_1 = layers; _i < layers_1.length; _i++) {
21456
+ x = layers_1[_i];
21457
+ _loop_2(x);
21458
+ }
21459
+ return [4 /*yield*/, Promise.all(promises)];
21447
21460
  case 1:
21448
21461
  ids = _a.sent();
21449
21462
  return [2 /*return*/, ids.filter(function (x) { return x !== undefined; })];
@@ -23309,12 +23322,13 @@ var NgwLeaflet = (function () {
23309
23322
  this._removeMapListener();
23310
23323
  };
23311
23324
  GeoJsonAdapter.prototype.select = function (findFeatureFun) {
23312
- var _this = this;
23325
+ this.unselect();
23313
23326
  if (findFeatureFun) {
23314
23327
  var def = this._layers.filter(findFeatureFun);
23315
- def.forEach(function (x) {
23316
- _this._selectLayer(x, 'api');
23317
- });
23328
+ for (var _i = 0, def_1 = def; _i < def_1.length; _i++) {
23329
+ var x = def_1[_i];
23330
+ this._selectLayer(x, 'api');
23331
+ }
23318
23332
  }
23319
23333
  else if (!this.selected) {
23320
23334
  this.selected = true;
@@ -23727,13 +23741,13 @@ var NgwLeaflet = (function () {
23727
23741
  var _this = this;
23728
23742
  var layer_ = this.layer;
23729
23743
  if (layer_) {
23730
- var def_1 = __assign({ target: this, feature: feature, layer: layer }, createFeaturePositionOptions(feature));
23744
+ var def_2 = __assign({ target: this, feature: feature, layer: layer }, createFeaturePositionOptions(feature));
23731
23745
  // @ts-ignore
23732
23746
  layer.options.pane = this.pane;
23733
- this._layers.push(def_1);
23747
+ this._layers.push(def_2);
23734
23748
  var ok = true;
23735
23749
  if (this._filterFun) {
23736
- ok = this._filterFun(def_1);
23750
+ ok = this._filterFun(def_2);
23737
23751
  }
23738
23752
  if (ok) {
23739
23753
  var _a = this.options, popup_1 = _a.popup, popupOptions_1 = _a.popupOptions, selectable = _a.selectable, interactive = _a.interactive, selectOnHover = _a.selectOnHover;
@@ -23743,10 +23757,10 @@ var NgwLeaflet = (function () {
23743
23757
  if (selectable) {
23744
23758
  if (selectOnHover) {
23745
23759
  layer.on('mouseover', function () {
23746
- _this._selectLayer(def_1, 'hover');
23760
+ _this._selectLayer(def_2, 'hover');
23747
23761
  });
23748
23762
  layer.on('mouseout', function () {
23749
- _this._unSelectLayer(def_1);
23763
+ _this._unSelectLayer(def_2);
23750
23764
  });
23751
23765
  }
23752
23766
  else {
@@ -23813,10 +23827,12 @@ var NgwLeaflet = (function () {
23813
23827
  };
23814
23828
  GeoJsonAdapter.prototype._selectLayer = function (def, type, latlng) {
23815
23829
  var _this = this;
23816
- this.map._addUnselectCb(function () {
23817
- _this._unSelectLayer(def);
23818
- });
23819
- if (this.options && !this.options.multiselect) {
23830
+ var multiselect = this.options.multiselect;
23831
+ if (!multiselect) {
23832
+ // To unselect layer on another layer click
23833
+ this.map._addUnselectCb(function () {
23834
+ _this._unSelectLayer(def);
23835
+ });
23820
23836
  this._selectedLayers.forEach(function (x) { return _this._unSelectLayer(x); });
23821
23837
  }
23822
23838
  this._selectedLayers.push(def);
@@ -23893,14 +23909,26 @@ var NgwLeaflet = (function () {
23893
23909
  }
23894
23910
  return geoJsonOptions;
23895
23911
  };
23896
- GeoJsonAdapter.prototype._addMapListener = function () {
23912
+ GeoJsonAdapter.prototype._addMapClickListener = function () {
23897
23913
  var map = this.map;
23898
23914
  if (map) {
23899
- var _a = this.options, labelField = _a.labelField, labelOnHover = _a.labelOnHover, unselectOnClick = _a.unselectOnClick;
23915
+ var unselectOnClick = this.options.unselectOnClick;
23900
23916
  var uoc = unselectOnClick !== null && unselectOnClick !== void 0 ? unselectOnClick : true;
23901
23917
  if (uoc) {
23902
23918
  map.on('click', this.$unselect);
23903
23919
  }
23920
+ }
23921
+ };
23922
+ GeoJsonAdapter.prototype._removeMapClickListener = function () {
23923
+ this.map.off('zoomend', this.$updateTooltip);
23924
+ this.map.off('moveend', this.$updateTooltip);
23925
+ this.map.off('click', this.$unselect);
23926
+ };
23927
+ GeoJsonAdapter.prototype._addMapListener = function () {
23928
+ var map = this.map;
23929
+ if (map) {
23930
+ var _a = this.options, labelField = _a.labelField, labelOnHover = _a.labelOnHover;
23931
+ this._addMapClickListener();
23904
23932
  if (labelField && !labelOnHover) {
23905
23933
  map.on('zoomend', this.$updateTooltip);
23906
23934
  map.on('moveend', this.$updateTooltip);
@@ -23908,9 +23936,9 @@ var NgwLeaflet = (function () {
23908
23936
  }
23909
23937
  };
23910
23938
  GeoJsonAdapter.prototype._removeMapListener = function () {
23939
+ this._removeMapClickListener();
23911
23940
  this.map.off('zoomend', this.$updateTooltip);
23912
23941
  this.map.off('moveend', this.$updateTooltip);
23913
- this.map.off('click', this.$unselect);
23914
23942
  };
23915
23943
  return GeoJsonAdapter;
23916
23944
  }(BaseAdapter));