@nextgis/geocoder 1.12.1 → 1.14.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/geocoder; version: 1.12.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.14.0; author: NextGIS */
2
2
  import CancelablePromise from '@nextgis/cancelable-promise';
3
3
  import { objectAssign, fixUrlStr } from '@nextgis/utils';
4
4
  import NgwConnector from '@nextgis/ngw-connector';
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 1.12.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.14.0; author: NextGIS */
2
2
  var Geocoder = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -1373,31 +1373,31 @@ var Geocoder = (function (exports) {
1373
1373
  /**
1374
1374
  * Thrown when...
1375
1375
  */
1376
- var NgwError = /** @class */ (function (_super) {
1377
- __extends(NgwError, _super);
1378
- function NgwError(er) {
1376
+ var NetworkError = /** @class */ (function (_super) {
1377
+ __extends(NetworkError, _super);
1378
+ function NetworkError(url) {
1379
1379
  var _this = _super.call(this) || this;
1380
- _this.name = 'NgwError';
1381
- Object.assign(_this, er);
1382
- Object.setPrototypeOf(_this, NgwError.prototype);
1380
+ _this.name = 'NetworkError';
1381
+ Object.setPrototypeOf(_this, NetworkError.prototype);
1382
+ _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
1383
1383
  return _this;
1384
1384
  }
1385
- return NgwError;
1385
+ return NetworkError;
1386
1386
  }(Error));
1387
1387
 
1388
1388
  /**
1389
1389
  * Thrown when...
1390
1390
  */
1391
- var NetworkError = /** @class */ (function (_super) {
1392
- __extends(NetworkError, _super);
1393
- function NetworkError(url) {
1391
+ var NgwError = /** @class */ (function (_super) {
1392
+ __extends(NgwError, _super);
1393
+ function NgwError(er) {
1394
1394
  var _this = _super.call(this) || this;
1395
- _this.name = 'NetworkError';
1396
- Object.setPrototypeOf(_this, NetworkError.prototype);
1397
- _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
1395
+ _this.name = 'NgwError';
1396
+ Object.assign(_this, er);
1397
+ Object.setPrototypeOf(_this, NgwError.prototype);
1398
1398
  return _this;
1399
1399
  }
1400
- return NetworkError;
1400
+ return NgwError;
1401
1401
  }(Error));
1402
1402
 
1403
1403
  function isObject(val) {
@@ -1511,11 +1511,6 @@ var Geocoder = (function (exports) {
1511
1511
  xhr.abort();
1512
1512
  });
1513
1513
  }
1514
- if (options.signal) {
1515
- options.signal.addEventListener('abort', function () {
1516
- xhr.abort();
1517
- });
1518
- }
1519
1514
  xhr.send(data);
1520
1515
  };
1521
1516
  }
@@ -1966,6 +1961,7 @@ var Geocoder = (function (exports) {
1966
1961
  this.id = ID++;
1967
1962
  this.emitter = new events.exports.EventEmitter();
1968
1963
  this.routeStr = '/api/component/pyramid/route';
1964
+ this.activeRequests = [];
1969
1965
  var exist = findConnector(options);
1970
1966
  if (exist) {
1971
1967
  return exist;
@@ -2051,6 +2047,7 @@ var Geocoder = (function (exports) {
2051
2047
  * Disconnecting a user. Aborting all current requests
2052
2048
  */
2053
2049
  NgwConnector.prototype.logout = function () {
2050
+ this.abort();
2054
2051
  removeConnector(this);
2055
2052
  this.options.auth = undefined;
2056
2053
  this.user = undefined;
@@ -2103,6 +2100,17 @@ var Geocoder = (function (exports) {
2103
2100
  }
2104
2101
  }
2105
2102
  };
2103
+ /** Stop all api requests */
2104
+ NgwConnector.prototype.abort = function () {
2105
+ for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
2106
+ var req = _a[_i];
2107
+ req.cancel();
2108
+ }
2109
+ this.activeRequests = [];
2110
+ };
2111
+ NgwConnector.prototype.getActiveApiRequests = function () {
2112
+ return __spreadArray([], this.activeRequests, true);
2113
+ };
2106
2114
  /**
2107
2115
  * Send request to NGW api router.
2108
2116
  * @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
@@ -2317,14 +2325,20 @@ var Geocoder = (function (exports) {
2317
2325
  NgwConnector.prototype._loadData = function (url, options) {
2318
2326
  var _this = this;
2319
2327
  options.responseType = options.responseType || 'json';
2320
- return new CancelablePromise(function (resolve, reject, onCancel) {
2328
+ var request = new CancelablePromise(function (resolve, reject, onCancel) {
2321
2329
  if (_this.user) {
2322
2330
  options = options || {};
2323
2331
  // options.withCredentials = true;
2324
2332
  options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
2325
2333
  }
2326
2334
  loadData(url, resolve, options, reject, onCancel);
2327
- }).catch(function (httpError) {
2335
+ })
2336
+ .then(function (resp) {
2337
+ _this._cleanActiveRequests(request);
2338
+ return resp;
2339
+ })
2340
+ .catch(function (httpError) {
2341
+ _this._cleanActiveRequests(request);
2328
2342
  if (httpError instanceof CancelablePromise.CancelError) ;
2329
2343
  else {
2330
2344
  // @ts-ignore
@@ -2337,6 +2351,20 @@ var Geocoder = (function (exports) {
2337
2351
  }
2338
2352
  }
2339
2353
  });
2354
+ if (options.signal &&
2355
+ typeof options.signal.addEventListener === 'function') {
2356
+ options.signal.addEventListener('abort', function () {
2357
+ request.cancel();
2358
+ });
2359
+ }
2360
+ this.activeRequests.push(request);
2361
+ return request;
2362
+ };
2363
+ NgwConnector.prototype._cleanActiveRequests = function (request) {
2364
+ var activeRequestIndex = this.activeRequests.indexOf(request);
2365
+ if (activeRequestIndex !== -1) {
2366
+ this.activeRequests.splice(activeRequestIndex, 1);
2367
+ }
2340
2368
  };
2341
2369
  NgwConnector.prototype._handleHttpError = function (er) {
2342
2370
  if (er) {