@nextgis/ngw-map 1.12.1 → 1.13.5

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.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.13.5; author: NextGIS */
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -4043,31 +4043,31 @@ var Cache = Cache$1;
4043
4043
  /**
4044
4044
  * Thrown when...
4045
4045
  */
4046
- var NgwError = /** @class */ (function (_super) {
4047
- __extends(NgwError, _super);
4048
- function NgwError(er) {
4046
+ var NetworkError = /** @class */ (function (_super) {
4047
+ __extends(NetworkError, _super);
4048
+ function NetworkError(url) {
4049
4049
  var _this = _super.call(this) || this;
4050
- _this.name = 'NgwError';
4051
- Object.assign(_this, er);
4052
- Object.setPrototypeOf(_this, NgwError.prototype);
4050
+ _this.name = 'NetworkError';
4051
+ Object.setPrototypeOf(_this, NetworkError.prototype);
4052
+ _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
4053
4053
  return _this;
4054
4054
  }
4055
- return NgwError;
4055
+ return NetworkError;
4056
4056
  }(Error));
4057
4057
 
4058
4058
  /**
4059
4059
  * Thrown when...
4060
4060
  */
4061
- var NetworkError = /** @class */ (function (_super) {
4062
- __extends(NetworkError, _super);
4063
- function NetworkError(url) {
4061
+ var NgwError = /** @class */ (function (_super) {
4062
+ __extends(NgwError, _super);
4063
+ function NgwError(er) {
4064
4064
  var _this = _super.call(this) || this;
4065
- _this.name = 'NetworkError';
4066
- Object.setPrototypeOf(_this, NetworkError.prototype);
4067
- _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
4065
+ _this.name = 'NgwError';
4066
+ Object.assign(_this, er);
4067
+ Object.setPrototypeOf(_this, NgwError.prototype);
4068
4068
  return _this;
4069
4069
  }
4070
- return NetworkError;
4070
+ return NgwError;
4071
4071
  }(Error));
4072
4072
 
4073
4073
  function isObject(val) {
@@ -4181,11 +4181,6 @@ var loadData;
4181
4181
  xhr.abort();
4182
4182
  });
4183
4183
  }
4184
- if (options.signal) {
4185
- options.signal.addEventListener('abort', function () {
4186
- xhr.abort();
4187
- });
4188
- }
4189
4184
  xhr.send(data);
4190
4185
  };
4191
4186
  }
@@ -4636,6 +4631,7 @@ var NgwConnector$1 = /** @class */ (function () {
4636
4631
  this.id = ID$1++;
4637
4632
  this.emitter = new events.exports.EventEmitter();
4638
4633
  this.routeStr = '/api/component/pyramid/route';
4634
+ this.activeRequests = [];
4639
4635
  var exist = findConnector(options);
4640
4636
  if (exist) {
4641
4637
  return exist;
@@ -4721,6 +4717,7 @@ var NgwConnector$1 = /** @class */ (function () {
4721
4717
  * Disconnecting a user. Aborting all current requests
4722
4718
  */
4723
4719
  NgwConnector.prototype.logout = function () {
4720
+ this.abort();
4724
4721
  removeConnector(this);
4725
4722
  this.options.auth = undefined;
4726
4723
  this.user = undefined;
@@ -4773,6 +4770,17 @@ var NgwConnector$1 = /** @class */ (function () {
4773
4770
  }
4774
4771
  }
4775
4772
  };
4773
+ /** Stop all api requests */
4774
+ NgwConnector.prototype.abort = function () {
4775
+ for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
4776
+ var req = _a[_i];
4777
+ req.cancel();
4778
+ }
4779
+ this.activeRequests = [];
4780
+ };
4781
+ NgwConnector.prototype.getActiveApiRequests = function () {
4782
+ return __spreadArray([], this.activeRequests, true);
4783
+ };
4776
4784
  /**
4777
4785
  * Send request to NGW api router.
4778
4786
  * @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
@@ -4987,14 +4995,20 @@ var NgwConnector$1 = /** @class */ (function () {
4987
4995
  NgwConnector.prototype._loadData = function (url, options) {
4988
4996
  var _this = this;
4989
4997
  options.responseType = options.responseType || 'json';
4990
- return new CancelablePromise(function (resolve, reject, onCancel) {
4998
+ var request = new CancelablePromise(function (resolve, reject, onCancel) {
4991
4999
  if (_this.user) {
4992
5000
  options = options || {};
4993
5001
  // options.withCredentials = true;
4994
5002
  options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
4995
5003
  }
4996
5004
  loadData(url, resolve, options, reject, onCancel);
4997
- }).catch(function (httpError) {
5005
+ })
5006
+ .then(function (resp) {
5007
+ _this._cleanActiveRequests(request);
5008
+ return resp;
5009
+ })
5010
+ .catch(function (httpError) {
5011
+ _this._cleanActiveRequests(request);
4998
5012
  if (httpError instanceof CancelablePromise.CancelError) ;
4999
5013
  else {
5000
5014
  // @ts-ignore
@@ -5007,6 +5021,20 @@ var NgwConnector$1 = /** @class */ (function () {
5007
5021
  }
5008
5022
  }
5009
5023
  });
5024
+ if (options.signal &&
5025
+ typeof options.signal.addEventListener === 'function') {
5026
+ options.signal.addEventListener('abort', function () {
5027
+ request.cancel();
5028
+ });
5029
+ }
5030
+ this.activeRequests.push(request);
5031
+ return request;
5032
+ };
5033
+ NgwConnector.prototype._cleanActiveRequests = function (request) {
5034
+ var activeRequestIndex = this.activeRequests.indexOf(request);
5035
+ if (activeRequestIndex !== -1) {
5036
+ this.activeRequests.splice(activeRequestIndex, 1);
5037
+ }
5010
5038
  };
5011
5039
  NgwConnector.prototype._handleHttpError = function (er) {
5012
5040
  if (er) {
@@ -5128,12 +5156,12 @@ function fetchNgwLayerItemExtent(_a) {
5128
5156
  function fetchNgwExtent(options) {
5129
5157
  return options.connector.getResource(options.resourceId).then(function (resource) {
5130
5158
  if (resource) {
5131
- return fetchNgwResourceExtent(resource, options.connector);
5159
+ return fetchNgwResourceExtent(resource, options.connector, options);
5132
5160
  }
5133
5161
  });
5134
5162
  }
5135
5163
  /** @deprecated use {@link fetchNgwExtent} instead */
5136
- function fetchNgwResourceExtent(item, connector) {
5164
+ function fetchNgwResourceExtent(item, connector, options) {
5137
5165
  if (item.webmap) {
5138
5166
  return CancelablePromise.resolve(getNgwWebmapExtent(item.webmap));
5139
5167
  }
@@ -5142,15 +5170,12 @@ function fetchNgwResourceExtent(item, connector) {
5142
5170
  if (resource.cls && resource.cls.indexOf('style') !== -1) {
5143
5171
  return connector.getResource(resource.parent.id).then(function (res) {
5144
5172
  if (res) {
5145
- return fetchNgwLayerExtent({
5146
- resourceId: res.resource.id,
5147
- connector: connector,
5148
- });
5173
+ return fetchNgwLayerExtent(__assign(__assign({}, options), { resourceId: res.resource.id, connector: connector }));
5149
5174
  }
5150
5175
  });
5151
5176
  }
5152
5177
  else {
5153
- return fetchNgwLayerExtent({ resourceId: resource.id, connector: connector });
5178
+ return fetchNgwLayerExtent(__assign(__assign({}, options), { resourceId: resource.id, connector: connector }));
5154
5179
  }
5155
5180
  }
5156
5181
  }
@@ -5321,7 +5346,7 @@ function createWktFromCoordArray(coord) {
5321
5346
  }
5322
5347
  function fetchNgwLayerItemsRequest(options) {
5323
5348
  var params = __assign({}, FEATURE_REQUEST_PARAMS);
5324
- var limit = options.limit, offset = options.offset, orderBy = options.orderBy, paramList = options.paramList, connector = options.connector, intersects = options.intersects, resourceId = options.resourceId;
5349
+ 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;
5325
5350
  if (limit) {
5326
5351
  if (limit !== Number.POSITIVE_INFINITY) {
5327
5352
  params.limit = limit;
@@ -5351,11 +5376,10 @@ function fetchNgwLayerItemsRequest(options) {
5351
5376
  params.paramList = paramList;
5352
5377
  }
5353
5378
  var reqParams = __assign({ id: resourceId }, params);
5354
- return connector.get('feature_layer.feature.collection', { cache: options.cache }, reqParams);
5379
+ return connector.get('feature_layer.feature.collection', { cache: cache, signal: signal }, reqParams);
5355
5380
  }
5356
5381
 
5357
5382
  function prepareNgwFieldsToPropertiesFilter(fields) {
5358
- console.log(fields);
5359
5383
  var f;
5360
5384
  var _loop_1 = function () {
5361
5385
  var field = fields[f];
@@ -7364,7 +7388,7 @@ var NgwResource = /** @class */ (function () {
7364
7388
  });
7365
7389
  });
7366
7390
  };
7367
- NgwResource.prototype.getBounds = function () {
7391
+ NgwResource.prototype.getBounds = function (options) {
7368
7392
  return __awaiter(this, void 0, void 0, function () {
7369
7393
  var _a;
7370
7394
  return __generator(this, function (_b) {
@@ -7375,7 +7399,7 @@ var NgwResource = /** @class */ (function () {
7375
7399
  }
7376
7400
  if (!this.item) return [3 /*break*/, 2];
7377
7401
  _a = this;
7378
- return [4 /*yield*/, fetchNgwResourceExtent(this.item, this.connector)];
7402
+ return [4 /*yield*/, fetchNgwResourceExtent(this.item, this.connector, options)];
7379
7403
  case 1:
7380
7404
  _a._extent = _b.sent();
7381
7405
  return [2 /*return*/, this._extent];
@@ -8017,7 +8041,7 @@ function createParamsFromFeatures(features, resourceId, multiple) {
8017
8041
  return featureParams;
8018
8042
  }
8019
8043
  function fetchIdentifyGeoJson(options) {
8020
- var connector = options.connector, identify = options.identify;
8044
+ var connector = options.connector, identify = options.identify, requestOptions = options.requestOptions;
8021
8045
  for (var l in identify) {
8022
8046
  var id = Number(l);
8023
8047
  if (!isNaN(id)) {
@@ -8033,7 +8057,7 @@ function fetchIdentifyGeoJson(options) {
8033
8057
  }
8034
8058
  var params = getIdentifyItems(identify);
8035
8059
  if (params && params.length) {
8036
- return fetchNgwLayerFeature(__assign({ connector: connector }, params[0]));
8060
+ return fetchNgwLayerFeature(__assign(__assign(__assign({}, requestOptions), { connector: connector }), params[0]));
8037
8061
  }
8038
8062
  return CancelablePromise.resolve(undefined);
8039
8063
  }
@@ -8046,21 +8070,25 @@ function fetchIdentifyItem(options) {
8046
8070
  return CancelablePromise.resolve(undefined);
8047
8071
  }
8048
8072
  function featureLayerIdentify(options) {
8049
- var g = options.geom;
8050
- var geom = [];
8051
- if (Array.isArray(g)) {
8052
- geom = g;
8073
+ var geom = options.geom, signal = options.signal, cache = options.cache;
8074
+ var geom_ = [];
8075
+ if (Array.isArray(geom)) {
8076
+ geom_ = geom;
8053
8077
  }
8054
8078
  else {
8055
- var polygon = g.type === 'Feature' ? g.geometry : g.type === 'Polygon' ? g : false;
8079
+ var polygon = geom.type === 'Feature'
8080
+ ? geom.geometry
8081
+ : geom.type === 'Polygon'
8082
+ ? geom
8083
+ : false;
8056
8084
  if (polygon) {
8057
- geom = polygon.coordinates[0];
8085
+ geom_ = polygon.coordinates[0];
8058
8086
  }
8059
8087
  }
8060
- if (geom) {
8088
+ if (geom_) {
8061
8089
  // create wkt string
8062
8090
  var polygonStr = [];
8063
- for (var _i = 0, geom_1 = geom; _i < geom_1.length; _i++) {
8091
+ for (var _i = 0, geom_1 = geom_; _i < geom_1.length; _i++) {
8064
8092
  var _a = geom_1[_i], lng = _a[0], lat = _a[1];
8065
8093
  var _b = degrees2meters(lng, lat), x = _b[0], y = _b[1];
8066
8094
  polygonStr.push(x + ' ' + y);
@@ -8072,18 +8100,22 @@ function featureLayerIdentify(options) {
8072
8100
  srs: 3857,
8073
8101
  layers: layers,
8074
8102
  };
8075
- return options.connector.post('feature_layer.identify', { data: data });
8103
+ return options.connector.post('feature_layer.identify', {
8104
+ data: data,
8105
+ signal: signal,
8106
+ cache: cache,
8107
+ });
8076
8108
  }
8077
8109
  else {
8078
8110
  throw new Error('Not valid geometry format to make intersection');
8079
8111
  }
8080
8112
  }
8081
8113
  function sendIdentifyRequest(ev, options) {
8082
- var _a;
8083
8114
  deprecatedMapClick(ev);
8084
- var _b = ev.lngLat, lng = _b[0], lat = _b[1];
8085
- var geom = (_a = options.geom) !== null && _a !== void 0 ? _a : getCirclePolygonCoordinates(lng, lat, options.radius);
8086
- return featureLayerIdentify(__assign(__assign({}, options), { geom: geom }));
8115
+ var _a = ev.lngLat, lng = _a[0], lat = _a[1];
8116
+ var geom = options.geom, radius = options.radius, signal = options.signal, cache = options.cache;
8117
+ var geom_ = geom !== null && geom !== void 0 ? geom : getCirclePolygonCoordinates(lng, lat, radius);
8118
+ return featureLayerIdentify(__assign(__assign({}, options), { geom: geom_, signal: signal, cache: cache }));
8087
8119
  }
8088
8120
  function createIdentifyItem(opt) {
8089
8121
  return new IdentifyItem(opt);