@nextgis/ngw-map 1.12.0 → 1.13.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.12.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.13.2; author: NextGIS */
2
2
  var NgwMap = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -1308,6 +1308,9 @@ var NgwMap = (function (exports) {
1308
1308
 
1309
1309
  function isObject$1(val) {
1310
1310
  return Object.prototype.toString.call(val) === '[object Object]';
1311
+ }
1312
+ function isArray(val) {
1313
+ return Object.prototype.toString.call(val) === '[object Array]';
1311
1314
  }
1312
1315
 
1313
1316
  function fixUrlStr(url) {
@@ -2371,6 +2374,9 @@ var NgwMap = (function (exports) {
2371
2374
  'movestart',
2372
2375
  'move',
2373
2376
  'moveend',
2377
+ 'mousemove',
2378
+ 'mouseout',
2379
+ 'mouseover',
2374
2380
  ];
2375
2381
  if (opt && opt.include) {
2376
2382
  events = events.filter(function (x) { return opt.include.includes(x); });
@@ -4040,31 +4046,31 @@ var NgwMap = (function (exports) {
4040
4046
  /**
4041
4047
  * Thrown when...
4042
4048
  */
4043
- var NgwError = /** @class */ (function (_super) {
4044
- __extends(NgwError, _super);
4045
- function NgwError(er) {
4049
+ var NetworkError = /** @class */ (function (_super) {
4050
+ __extends(NetworkError, _super);
4051
+ function NetworkError(url) {
4046
4052
  var _this = _super.call(this) || this;
4047
- _this.name = 'NgwError';
4048
- Object.assign(_this, er);
4049
- Object.setPrototypeOf(_this, NgwError.prototype);
4053
+ _this.name = 'NetworkError';
4054
+ Object.setPrototypeOf(_this, NetworkError.prototype);
4055
+ _this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
4050
4056
  return _this;
4051
4057
  }
4052
- return NgwError;
4058
+ return NetworkError;
4053
4059
  }(Error));
4054
4060
 
4055
4061
  /**
4056
4062
  * Thrown when...
4057
4063
  */
4058
- var NetworkError = /** @class */ (function (_super) {
4059
- __extends(NetworkError, _super);
4060
- function NetworkError(url) {
4064
+ var NgwError = /** @class */ (function (_super) {
4065
+ __extends(NgwError, _super);
4066
+ function NgwError(er) {
4061
4067
  var _this = _super.call(this) || this;
4062
- _this.name = 'NetworkError';
4063
- Object.setPrototypeOf(_this, NetworkError.prototype);
4064
- _this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
4068
+ _this.name = 'NgwError';
4069
+ Object.assign(_this, er);
4070
+ Object.setPrototypeOf(_this, NgwError.prototype);
4065
4071
  return _this;
4066
4072
  }
4067
- return NetworkError;
4073
+ return NgwError;
4068
4074
  }(Error));
4069
4075
 
4070
4076
  function isObject(val) {
@@ -4319,7 +4325,12 @@ var NgwMap = (function (exports) {
4319
4325
  forCache.id = resource;
4320
4326
  }
4321
4327
  else if (isObject(resource)) {
4322
- forCache.id = resource.id;
4328
+ if (resource.id !== undefined) {
4329
+ forCache.id = resource.id;
4330
+ }
4331
+ else if (resource.keyname) {
4332
+ forCache.keyname = resource.keyname;
4333
+ }
4323
4334
  }
4324
4335
  var makeRequest = function () {
4325
4336
  if (typeof resource === 'string') {
@@ -4421,20 +4432,35 @@ var NgwMap = (function (exports) {
4421
4432
  };
4422
4433
  ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
4423
4434
  var _this = this;
4424
- return this.getId(resource).then(function (parent) {
4425
- return _this.connector
4426
- .get('resource.collection', __assign({ cache: true }, requestOptions), {
4427
- parent: parent,
4428
- })
4429
- .then(function (items) {
4430
- for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
4431
- var i = items_1[_i];
4432
- _this.cache.add('resource.item', CancelablePromise.resolve(i), {
4433
- id: i.resource.id,
4434
- });
4435
+ return this.getIdOrFail(resource).then(function (parent) {
4436
+ return _this._getChildrenOf(parent, requestOptions);
4437
+ });
4438
+ };
4439
+ ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
4440
+ var _this = this;
4441
+ if (_items === void 0) { _items = []; }
4442
+ return this.connector
4443
+ .get('resource.collection', __assign({ cache: true }, requestOptions), {
4444
+ parent: parent,
4445
+ })
4446
+ .then(function (items) {
4447
+ var recursivePromises = [];
4448
+ for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
4449
+ var item = items_1[_i];
4450
+ _this.cache.add('resource.item', CancelablePromise.resolve(item), {
4451
+ id: item.resource.id,
4452
+ });
4453
+ _items.push(item);
4454
+ if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
4455
+ recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
4435
4456
  }
4436
- return items;
4437
- });
4457
+ }
4458
+ if (recursivePromises.length) {
4459
+ return CancelablePromise.all(recursivePromises).then(function () {
4460
+ return _items;
4461
+ });
4462
+ }
4463
+ return _items;
4438
4464
  });
4439
4465
  };
4440
4466
  ResourcesControl.prototype.update = function (resource, data) {
@@ -4959,7 +4985,7 @@ var NgwMap = (function (exports) {
4959
4985
  NgwConnector.prototype._loadData = function (url, options) {
4960
4986
  var _this = this;
4961
4987
  options.responseType = options.responseType || 'json';
4962
- return new CancelablePromise(function (resolve, reject, onCancel) {
4988
+ var request = new CancelablePromise(function (resolve, reject, onCancel) {
4963
4989
  if (_this.user) {
4964
4990
  options = options || {};
4965
4991
  // options.withCredentials = true;
@@ -4979,6 +5005,13 @@ var NgwMap = (function (exports) {
4979
5005
  }
4980
5006
  }
4981
5007
  });
5008
+ if (options.signal &&
5009
+ typeof options.signal.addEventListener === 'function') {
5010
+ options.signal.addEventListener('abort', function () {
5011
+ request.cancel();
5012
+ });
5013
+ }
5014
+ return request;
4982
5015
  };
4983
5016
  NgwConnector.prototype._handleHttpError = function (er) {
4984
5017
  if (er) {
@@ -5100,12 +5133,12 @@ var NgwMap = (function (exports) {
5100
5133
  function fetchNgwExtent(options) {
5101
5134
  return options.connector.getResource(options.resourceId).then(function (resource) {
5102
5135
  if (resource) {
5103
- return fetchNgwResourceExtent(resource, options.connector);
5136
+ return fetchNgwResourceExtent(resource, options.connector, options);
5104
5137
  }
5105
5138
  });
5106
5139
  }
5107
5140
  /** @deprecated use {@link fetchNgwExtent} instead */
5108
- function fetchNgwResourceExtent(item, connector) {
5141
+ function fetchNgwResourceExtent(item, connector, options) {
5109
5142
  if (item.webmap) {
5110
5143
  return CancelablePromise.resolve(getNgwWebmapExtent(item.webmap));
5111
5144
  }
@@ -5114,15 +5147,12 @@ var NgwMap = (function (exports) {
5114
5147
  if (resource.cls && resource.cls.indexOf('style') !== -1) {
5115
5148
  return connector.getResource(resource.parent.id).then(function (res) {
5116
5149
  if (res) {
5117
- return fetchNgwLayerExtent({
5118
- resourceId: res.resource.id,
5119
- connector: connector,
5120
- });
5150
+ return fetchNgwLayerExtent(__assign(__assign({}, options), { resourceId: res.resource.id, connector: connector }));
5121
5151
  }
5122
5152
  });
5123
5153
  }
5124
5154
  else {
5125
- return fetchNgwLayerExtent({ resourceId: resource.id, connector: connector });
5155
+ return fetchNgwLayerExtent(__assign(__assign({}, options), { resourceId: resource.id, connector: connector }));
5126
5156
  }
5127
5157
  }
5128
5158
  }
@@ -5293,7 +5323,7 @@ var NgwMap = (function (exports) {
5293
5323
  }
5294
5324
  function fetchNgwLayerItemsRequest(options) {
5295
5325
  var params = __assign({}, FEATURE_REQUEST_PARAMS);
5296
- var limit = options.limit, offset = options.offset, orderBy = options.orderBy, paramList = options.paramList, connector = options.connector, intersects = options.intersects, resourceId = options.resourceId;
5326
+ var limit = options.limit, cache = options.cache, signal = options.signal, offset = options.offset, orderBy = options.orderBy, paramList = options.paramList, connector = options.connector, intersects = options.intersects, resourceId = options.resourceId;
5297
5327
  if (limit) {
5298
5328
  if (limit !== Number.POSITIVE_INFINITY) {
5299
5329
  params.limit = limit;
@@ -5323,7 +5353,7 @@ var NgwMap = (function (exports) {
5323
5353
  params.paramList = paramList;
5324
5354
  }
5325
5355
  var reqParams = __assign({ id: resourceId }, params);
5326
- return connector.get('feature_layer.feature.collection', { cache: options.cache }, reqParams);
5356
+ return connector.get('feature_layer.feature.collection', { cache: cache, signal: signal }, reqParams);
5327
5357
  }
5328
5358
 
5329
5359
  function prepareNgwFieldsToPropertiesFilter(fields) {
@@ -5346,6 +5376,9 @@ var NgwMap = (function (exports) {
5346
5376
  fields[f] = new (Date.bind.apply(Date, __spreadArray([void 0], dt_1, false)))().toISOString();
5347
5377
  }
5348
5378
  }
5379
+ else if (f === 'id' && typeof field === 'string') {
5380
+ fields[f] = field.split(',').map(Number);
5381
+ }
5349
5382
  };
5350
5383
  for (f in fields) {
5351
5384
  _loop_1();
@@ -5358,7 +5391,7 @@ var NgwMap = (function (exports) {
5358
5391
  if (filters) {
5359
5392
  return createFeatureFieldFilterQueries(__assign(__assign({}, options), { filters: filters })).then(function (data) {
5360
5393
  var _a;
5361
- var clientFilterValidate = (_a = options.clientFilterValidate) !== null && _a !== void 0 ? _a : true;
5394
+ var clientFilterValidate = (_a = options.clientFilterValidate) !== null && _a !== void 0 ? _a : isFilterWithAnyCase(filters);
5362
5395
  // Additional client-side filter check
5363
5396
  if (clientFilterValidate) {
5364
5397
  data = data.filter(function (y) {
@@ -5373,6 +5406,21 @@ var NgwMap = (function (exports) {
5373
5406
  else {
5374
5407
  return fetchNgwLayerItemsRequest(options);
5375
5408
  }
5409
+ }
5410
+ function isFilterWithAnyCase(filters) {
5411
+ if (filters[0] === 'any') {
5412
+ return true;
5413
+ }
5414
+ for (var i = 1; i < filters.length; i++) {
5415
+ var p = filters[i];
5416
+ if (isArray(p)) {
5417
+ var deep = isFilterWithAnyCase(p);
5418
+ if (deep) {
5419
+ return true;
5420
+ }
5421
+ }
5422
+ }
5423
+ return false;
5376
5424
  }
5377
5425
 
5378
5426
  function fetchNgwLayerFeatures(options) {
@@ -7317,7 +7365,7 @@ var NgwMap = (function (exports) {
7317
7365
  });
7318
7366
  });
7319
7367
  };
7320
- NgwResource.prototype.getBounds = function () {
7368
+ NgwResource.prototype.getBounds = function (options) {
7321
7369
  return __awaiter(this, void 0, void 0, function () {
7322
7370
  var _a;
7323
7371
  return __generator(this, function (_b) {
@@ -7328,7 +7376,7 @@ var NgwMap = (function (exports) {
7328
7376
  }
7329
7377
  if (!this.item) return [3 /*break*/, 2];
7330
7378
  _a = this;
7331
- return [4 /*yield*/, fetchNgwResourceExtent(this.item, this.connector)];
7379
+ return [4 /*yield*/, fetchNgwResourceExtent(this.item, this.connector, options)];
7332
7380
  case 1:
7333
7381
  _a._extent = _b.sent();
7334
7382
  return [2 /*return*/, this._extent];
@@ -7922,7 +7970,6 @@ var NgwMap = (function (exports) {
7922
7970
 
7923
7971
  function getIdentifyItems(identify, multiple) {
7924
7972
  if (multiple === void 0) { multiple = false; }
7925
- var params;
7926
7973
  var resources = [];
7927
7974
  var paramsList = [];
7928
7975
  for (var l in identify) {
@@ -7943,14 +7990,9 @@ var NgwMap = (function (exports) {
7943
7990
  if ('features' in identifyItem) {
7944
7991
  var layerFeatures = identifyItem.features;
7945
7992
  var resourceId = Number(l);
7946
- var feature = layerFeatures[0];
7947
- if (feature) {
7948
- params = {
7949
- featureId: feature.id,
7950
- resourceId: resourceId,
7951
- feature: feature,
7952
- };
7953
- paramsList.push(params);
7993
+ var featureParams = createParamsFromFeatures(layerFeatures, resourceId, multiple);
7994
+ if (featureParams.length) {
7995
+ paramsList.push.apply(paramsList, featureParams);
7954
7996
  if (!multiple) {
7955
7997
  break;
7956
7998
  }
@@ -7959,8 +8001,24 @@ var NgwMap = (function (exports) {
7959
8001
  }
7960
8002
  return paramsList;
7961
8003
  }
8004
+ function createParamsFromFeatures(features, resourceId, multiple) {
8005
+ var featureParams = [];
8006
+ for (var _i = 0, features_1 = features; _i < features_1.length; _i++) {
8007
+ var feature = features_1[_i];
8008
+ var params = {
8009
+ featureId: feature.id,
8010
+ resourceId: resourceId,
8011
+ feature: feature,
8012
+ };
8013
+ featureParams.push(params);
8014
+ if (!multiple) {
8015
+ break;
8016
+ }
8017
+ }
8018
+ return featureParams;
8019
+ }
7962
8020
  function fetchIdentifyGeoJson(options) {
7963
- var connector = options.connector, identify = options.identify;
8021
+ var connector = options.connector, identify = options.identify, requestOptions = options.requestOptions;
7964
8022
  for (var l in identify) {
7965
8023
  var id = Number(l);
7966
8024
  if (!isNaN(id)) {
@@ -7976,7 +8034,7 @@ var NgwMap = (function (exports) {
7976
8034
  }
7977
8035
  var params = getIdentifyItems(identify);
7978
8036
  if (params && params.length) {
7979
- return fetchNgwLayerFeature(__assign({ connector: connector }, params[0]));
8037
+ return fetchNgwLayerFeature(__assign(__assign(__assign({}, requestOptions), { connector: connector }), params[0]));
7980
8038
  }
7981
8039
  return CancelablePromise.resolve(undefined);
7982
8040
  }
@@ -7989,21 +8047,25 @@ var NgwMap = (function (exports) {
7989
8047
  return CancelablePromise.resolve(undefined);
7990
8048
  }
7991
8049
  function featureLayerIdentify(options) {
7992
- var g = options.geom;
7993
- var geom = [];
7994
- if (Array.isArray(g)) {
7995
- geom = g;
8050
+ var geom = options.geom, signal = options.signal, cache = options.cache;
8051
+ var geom_ = [];
8052
+ if (Array.isArray(geom)) {
8053
+ geom_ = geom;
7996
8054
  }
7997
8055
  else {
7998
- var polygon = g.type === 'Feature' ? g.geometry : g.type === 'Polygon' ? g : false;
8056
+ var polygon = geom.type === 'Feature'
8057
+ ? geom.geometry
8058
+ : geom.type === 'Polygon'
8059
+ ? geom
8060
+ : false;
7999
8061
  if (polygon) {
8000
- geom = polygon.coordinates[0];
8062
+ geom_ = polygon.coordinates[0];
8001
8063
  }
8002
8064
  }
8003
- if (geom) {
8065
+ if (geom_) {
8004
8066
  // create wkt string
8005
8067
  var polygonStr = [];
8006
- for (var _i = 0, geom_1 = geom; _i < geom_1.length; _i++) {
8068
+ for (var _i = 0, geom_1 = geom_; _i < geom_1.length; _i++) {
8007
8069
  var _a = geom_1[_i], lng = _a[0], lat = _a[1];
8008
8070
  var _b = degrees2meters(lng, lat), x = _b[0], y = _b[1];
8009
8071
  polygonStr.push(x + ' ' + y);
@@ -8015,18 +8077,22 @@ var NgwMap = (function (exports) {
8015
8077
  srs: 3857,
8016
8078
  layers: layers,
8017
8079
  };
8018
- return options.connector.post('feature_layer.identify', { data: data });
8080
+ return options.connector.post('feature_layer.identify', {
8081
+ data: data,
8082
+ signal: signal,
8083
+ cache: cache,
8084
+ });
8019
8085
  }
8020
8086
  else {
8021
8087
  throw new Error('Not valid geometry format to make intersection');
8022
8088
  }
8023
8089
  }
8024
8090
  function sendIdentifyRequest(ev, options) {
8025
- var _a;
8026
8091
  deprecatedMapClick(ev);
8027
- var _b = ev.lngLat, lng = _b[0], lat = _b[1];
8028
- var geom = (_a = options.geom) !== null && _a !== void 0 ? _a : getCirclePolygonCoordinates(lng, lat, options.radius);
8029
- return featureLayerIdentify(__assign(__assign({}, options), { geom: geom }));
8092
+ var _a = ev.lngLat, lng = _a[0], lat = _a[1];
8093
+ var geom = options.geom, radius = options.radius, signal = options.signal, cache = options.cache;
8094
+ var geom_ = geom !== null && geom !== void 0 ? geom : getCirclePolygonCoordinates(lng, lat, radius);
8095
+ return featureLayerIdentify(__assign(__assign({}, options), { geom: geom_, signal: signal, cache: cache }));
8030
8096
  }
8031
8097
  function createIdentifyItem(opt) {
8032
8098
  return new IdentifyItem(opt);