@nextgis/ngw-map 1.14.0 → 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,5 +1,5 @@
1
- /** Bundle of @nextgis/ngw-map; version: 1.14.0; author: NextGIS */
2
- /*! *****************************************************************************
1
+ /** Bundle of @nextgis/ngw-map; version: 1.16.0; author: NextGIS */
2
+ /******************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
@@ -1522,6 +1522,24 @@ function createPropertiesPaint(propertiesPaint) {
1522
1522
  return mask;
1523
1523
  };
1524
1524
  }
1525
+ function expressionCallback(paint, defaultPaint, getPaintFunctions) {
1526
+ var expressionCallback = createExpressionCallback(paint);
1527
+ if (expressionCallback) {
1528
+ var expressionPaintCb = function (feature) {
1529
+ return preparePaint(expressionCallback(feature), defaultPaint, getPaintFunctions);
1530
+ };
1531
+ expressionPaintCb.paint = paint;
1532
+ return expressionPaintCb;
1533
+ }
1534
+ var newPaint = __assign({}, defaultPaint);
1535
+ newPaint = __assign(__assign({}, newPaint), paint);
1536
+ newPaint.fill = newPaint.fill !== undefined ? newPaint.fill : true;
1537
+ newPaint.stroke =
1538
+ newPaint.stroke !== undefined
1539
+ ? newPaint.stroke
1540
+ : !newPaint.fill || !!(newPaint.strokeColor || newPaint.strokeOpacity);
1541
+ return newPaint;
1542
+ }
1525
1543
  function preparePaint(paint, defaultPaint, getPaintFunctions) {
1526
1544
  if (!paint) {
1527
1545
  throw new Error('paint is empty');
@@ -1551,20 +1569,7 @@ function preparePaint(paint, defaultPaint, getPaintFunctions) {
1551
1569
  return paint;
1552
1570
  }
1553
1571
  else {
1554
- var expressionCallback_1 = createExpressionCallback(paint);
1555
- if (expressionCallback_1) {
1556
- var expressionPaintCb = function (feature) {
1557
- return preparePaint(expressionCallback_1(feature), defaultPaint, getPaintFunctions);
1558
- };
1559
- expressionPaintCb.paint = paint;
1560
- return expressionPaintCb;
1561
- }
1562
- newPaint = __assign(__assign({}, newPaint), paint);
1563
- newPaint.fill = newPaint.fill !== undefined ? newPaint.fill : true;
1564
- newPaint.stroke =
1565
- newPaint.stroke !== undefined
1566
- ? newPaint.stroke
1567
- : !newPaint.fill || !!(newPaint.strokeColor || newPaint.strokeOpacity);
1572
+ newPaint = expressionCallback(paint, defaultPaint, getPaintFunctions);
1568
1573
  }
1569
1574
  if (isPaintCallback(newPaint)) {
1570
1575
  return newPaint;
@@ -4437,6 +4442,29 @@ var ResourcesControl = /** @class */ (function () {
4437
4442
  return _this._getChildrenOf(parent, requestOptions);
4438
4443
  });
4439
4444
  };
4445
+ ResourcesControl.prototype.update = function (resource, data) {
4446
+ var _this = this;
4447
+ return this.getId(resource).then(function (id) {
4448
+ if (id !== undefined) {
4449
+ return _this.connector.put('resource.item', { data: data }, { id: id });
4450
+ }
4451
+ });
4452
+ };
4453
+ /**
4454
+ * Fast way to delete resource from NGW and clean cache.
4455
+ * @param resource - Resource definition
4456
+ */
4457
+ ResourcesControl.prototype.delete = function (resource) {
4458
+ var _this = this;
4459
+ return this.getId(resource).then(function (id) {
4460
+ if (id !== undefined) {
4461
+ return _this.connector.delete('resource.item', null, { id: id }).then(function () {
4462
+ _this._cleanResourceItemCache(id);
4463
+ return undefined;
4464
+ });
4465
+ }
4466
+ });
4467
+ };
4440
4468
  ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
4441
4469
  var _this = this;
4442
4470
  if (_items === void 0) { _items = []; }
@@ -4464,29 +4492,6 @@ var ResourcesControl = /** @class */ (function () {
4464
4492
  return _items;
4465
4493
  });
4466
4494
  };
4467
- ResourcesControl.prototype.update = function (resource, data) {
4468
- var _this = this;
4469
- return this.getId(resource).then(function (id) {
4470
- if (id !== undefined) {
4471
- return _this.connector.put('resource.item', { data: data }, { id: id });
4472
- }
4473
- });
4474
- };
4475
- /**
4476
- * Fast way to delete resource from NGW and clean cache.
4477
- * @param resource - Resource definition
4478
- */
4479
- ResourcesControl.prototype.delete = function (resource) {
4480
- var _this = this;
4481
- return this.getId(resource).then(function (id) {
4482
- if (id !== undefined) {
4483
- return _this.connector.delete('resource.item', null, { id: id }).then(function () {
4484
- _this._cleanResourceItemCache(id);
4485
- return undefined;
4486
- });
4487
- }
4488
- });
4489
- };
4490
4495
  ResourcesControl.prototype._cleanResourceItemCache = function (id) {
4491
4496
  return __awaiter(this, void 0, void 0, function () {
4492
4497
  var all, toDelete, _i, all_1, c, cid, rid, _a, toDelete_1, d;
@@ -4644,6 +4649,9 @@ var NgwConnector$1 = /** @class */ (function () {
4644
4649
  if (this.options.route) {
4645
4650
  this.routeStr = this.options.route;
4646
4651
  }
4652
+ if (this.options.requestTransform) {
4653
+ this.requestTransform = this.options.requestTransform;
4654
+ }
4647
4655
  this.resources = new ResourcesControl(this);
4648
4656
  addConnector(this);
4649
4657
  }
@@ -4651,6 +4659,9 @@ var NgwConnector$1 = /** @class */ (function () {
4651
4659
  NgwConnector.create = function (options) {
4652
4660
  return new this(options);
4653
4661
  };
4662
+ NgwConnector.prototype.setRequestTransform = function (requestTransform) {
4663
+ this.requestTransform = requestTransform;
4664
+ };
4654
4665
  /**
4655
4666
  * Fast way to specify the connection address to NextGIS Web.
4656
4667
  * The current connection will be severed.
@@ -4910,9 +4921,8 @@ var NgwConnector$1 = /** @class */ (function () {
4910
4921
  if (params) {
4911
4922
  url = template(url, params);
4912
4923
  }
4913
- // remove double slash
4914
- url = fixUrlStr(url);
4915
- return this._loadData(encodeURI(url), options);
4924
+ url = encodeURI(fixUrlStr(url));
4925
+ return this._loadData(url, options);
4916
4926
  }
4917
4927
  else {
4918
4928
  throw new Error('Empty `url` not allowed');
@@ -5005,6 +5015,11 @@ var NgwConnector$1 = /** @class */ (function () {
5005
5015
  // options.withCredentials = true;
5006
5016
  options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
5007
5017
  }
5018
+ if (_this.requestTransform) {
5019
+ var _a = _this.requestTransform(url, options), transUrl = _a[0], transOptions = _a[1];
5020
+ url = transUrl;
5021
+ options = transOptions;
5022
+ }
5008
5023
  loadData(url, resolve, options, reject, onCancel);
5009
5024
  })
5010
5025
  .then(function (resp) {
@@ -5029,6 +5044,7 @@ var NgwConnector$1 = /** @class */ (function () {
5029
5044
  typeof options.signal.addEventListener === 'function') {
5030
5045
  options.signal.addEventListener('abort', function () {
5031
5046
  request.cancel();
5047
+ _this._cleanActiveRequests(request);
5032
5048
  });
5033
5049
  }
5034
5050
  this.activeRequests.push(request);
@@ -6631,10 +6647,12 @@ var NgwWebmapItem = /** @class */ (function (_super) {
6631
6647
  };
6632
6648
  if (item.item_type === 'group' || item.item_type === 'root') {
6633
6649
  if (item.children && item.children.length) {
6634
- this.getChildren(item).forEach(function (x) {
6635
- var children = new NgwWebmapItem(_this.webMap, x, _this.options, _this.connector, _this);
6636
- _this.tree.addChild(children);
6637
- });
6650
+ var children = this.getChildren(item);
6651
+ for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
6652
+ var x = children_1[_i];
6653
+ var children_2 = new this.constructor(this.webMap, x, this.options, this.connector, this);
6654
+ this.tree.addChild(children_2);
6655
+ }
6638
6656
  }
6639
6657
  return Promise.resolve();
6640
6658
  }
@@ -6675,7 +6693,7 @@ var NgwWebmapItem = /** @class */ (function (_super) {
6675
6693
  headers: this.options.headers,
6676
6694
  crossOrigin: this.options.crossOrigin,
6677
6695
  setViewDelay: this.options.setViewDelay,
6678
- params: { resource: this.item.resourceId },
6696
+ params: { resource: this.item.resourceId, item: this.item },
6679
6697
  };
6680
6698
  if (this.options.order) {
6681
6699
  var subOrder = this.options.drawOrderEnabled && 'draw_order_position' in item
@@ -6686,6 +6704,9 @@ var NgwWebmapItem = /** @class */ (function (_super) {
6686
6704
  var subLevel = String(subOrder).padStart(4, '0');
6687
6705
  options.order = Number((this.options.order | 0) + '.' + subLevel);
6688
6706
  }
6707
+ if (this.options.popupOptions) {
6708
+ options.popupOptions = this.options.popupOptions;
6709
+ }
6689
6710
  if (item.item_type === 'layer') {
6690
6711
  var _a = this._getZoomRange(item), maxZoom = _a.maxZoom, minZoom = _a.minZoom;
6691
6712
  objectAssign(options, {
@@ -6733,8 +6754,8 @@ var NgwWebmapItem = /** @class */ (function (_super) {
6733
6754
  };
6734
6755
  NgwWebmapItem.prototype._sumUp = function (children, totalValue) {
6735
6756
  if (totalValue === void 0) { totalValue = 0; }
6736
- for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
6737
- var child = children_1[_i];
6757
+ for (var _i = 0, children_3 = children; _i < children_3.length; _i++) {
6758
+ var child = children_3[_i];
6738
6759
  if (child.item_type === 'layer') {
6739
6760
  totalValue += 1;
6740
6761
  child.draw_order_position = child.draw_order_position || totalValue;
@@ -7041,8 +7062,6 @@ var NgwWebmapLayerAdapter = /** @class */ (function () {
7041
7062
  this._extent &&
7042
7063
  extentConstrained) {
7043
7064
  this.options.webMap.setView({ maxBounds: this._extent });
7044
- // @ts-ignore
7045
- window.webmap = this.options.webMap;
7046
7065
  }
7047
7066
  return [2 /*return*/, this.layer];
7048
7067
  }
@@ -7215,6 +7234,7 @@ var NgwWebmapLayerAdapter = /** @class */ (function () {
7215
7234
  options.minZoom = _this.options.minZoom;
7216
7235
  options.maxZoom = _this.options.maxZoom;
7217
7236
  options.drawOrderEnabled = webmap_1.draw_order_enabled;
7237
+ options.popupOptions = _this.options.popupOptions;
7218
7238
  var layer = new _this.NgwWebmapItem(_this.options.webMap, webmap_1.root_item, options, _this.options.connector);
7219
7239
  layer.emitter.on('init', function () { return resolve(layer); });
7220
7240
  })];
@@ -7345,30 +7365,34 @@ var NgwWebmapLayerAdapter = /** @class */ (function () {
7345
7365
  };
7346
7366
  NgwWebmapLayerAdapter.prototype._getWebMapIds = function () {
7347
7367
  return __awaiter(this, void 0, void 0, function () {
7348
- var webMapItem, layers, promises_1, ids;
7349
- var _this = this;
7368
+ var webMapItem, layers, promises, _loop_2, this_2, _i, layers_1, x, ids;
7350
7369
  return __generator(this, function (_a) {
7351
7370
  switch (_a.label) {
7352
7371
  case 0:
7353
7372
  webMapItem = this.layer;
7354
7373
  if (!(webMapItem && webMapItem.item.item_type === 'root')) return [3 /*break*/, 2];
7355
7374
  layers = webMapItem.tree.getDescendants();
7356
- promises_1 = [];
7357
- layers.forEach(function (x) {
7375
+ promises = [];
7376
+ _loop_2 = function (x) {
7358
7377
  var item = x.item;
7359
7378
  if (item.item_type === 'layer') {
7360
7379
  var id = item.layer_style_id;
7361
- var promise = _this.options.connector.getResource(id).then(function (y) {
7380
+ var promise = this_2.options.connector.getResource(id).then(function (y) {
7362
7381
  if (y) {
7363
7382
  var parentId = Number(y.resource.parent.id);
7364
7383
  item.parentId = parentId;
7365
7384
  return parentId;
7366
7385
  }
7367
7386
  });
7368
- promises_1.push(promise);
7387
+ promises.push(promise);
7369
7388
  }
7370
- });
7371
- return [4 /*yield*/, Promise.all(promises_1)];
7389
+ };
7390
+ this_2 = this;
7391
+ for (_i = 0, layers_1 = layers; _i < layers_1.length; _i++) {
7392
+ x = layers_1[_i];
7393
+ _loop_2(x);
7394
+ }
7395
+ return [4 /*yield*/, Promise.all(promises)];
7372
7396
  case 1:
7373
7397
  ids = _a.sent();
7374
7398
  return [2 /*return*/, ids.filter(function (x) { return x !== undefined; })];
@@ -7784,10 +7808,8 @@ function extendNgwWebmapLayerAdapter(opt) {
7784
7808
  var A = /** @class */ (function (_super) {
7785
7809
  __extends(A, _super);
7786
7810
  function A(map, options) {
7787
- var _this = this;
7788
7811
  options = __assign(__assign({}, opt), options);
7789
- _this = _super.call(this, map, options) || this;
7790
- return _this;
7812
+ return _super.call(this, map, options) || this;
7791
7813
  }
7792
7814
  return A;
7793
7815
  }(NgwWebmapLayerAdapter));