@nextgis/ngw-leaflet 1.13.0 → 1.13.6

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.13.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.13.6; 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.13.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.13.6; author: NextGIS */
2
2
  var NgwLeaflet = (function () {
3
3
  'use strict';
4
4
 
@@ -16919,6 +16919,7 @@ var NgwLeaflet = (function () {
16919
16919
  };
16920
16920
  /** Shortcut for {@link WebMapLayers.addLayer} to create TileLayer adapter */
16921
16921
  WebMapLayers.prototype.addTileLayer = function (url, options) {
16922
+ if (options === void 0) { options = {}; }
16922
16923
  return this.addLayer('TILE', __assign(__assign({}, options), { url: url }));
16923
16924
  };
16924
16925
  WebMapLayers.prototype.addImageLayer = function (urlOrOptions, options) {
@@ -18119,31 +18120,31 @@ var NgwLeaflet = (function () {
18119
18120
  /**
18120
18121
  * Thrown when...
18121
18122
  */
18122
- var NgwError = /** @class */ (function (_super) {
18123
- __extends(NgwError, _super);
18124
- function NgwError(er) {
18123
+ var NetworkError = /** @class */ (function (_super) {
18124
+ __extends(NetworkError, _super);
18125
+ function NetworkError(url) {
18125
18126
  var _this = _super.call(this) || this;
18126
- _this.name = 'NgwError';
18127
- Object.assign(_this, er);
18128
- Object.setPrototypeOf(_this, NgwError.prototype);
18127
+ _this.name = 'NetworkError';
18128
+ Object.setPrototypeOf(_this, NetworkError.prototype);
18129
+ _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
18129
18130
  return _this;
18130
18131
  }
18131
- return NgwError;
18132
+ return NetworkError;
18132
18133
  }(Error));
18133
18134
 
18134
18135
  /**
18135
18136
  * Thrown when...
18136
18137
  */
18137
- var NetworkError = /** @class */ (function (_super) {
18138
- __extends(NetworkError, _super);
18139
- function NetworkError(url) {
18138
+ var NgwError = /** @class */ (function (_super) {
18139
+ __extends(NgwError, _super);
18140
+ function NgwError(er) {
18140
18141
  var _this = _super.call(this) || this;
18141
- _this.name = 'NetworkError';
18142
- Object.setPrototypeOf(_this, NetworkError.prototype);
18143
- _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
18142
+ _this.name = 'NgwError';
18143
+ Object.assign(_this, er);
18144
+ Object.setPrototypeOf(_this, NgwError.prototype);
18144
18145
  return _this;
18145
18146
  }
18146
- return NetworkError;
18147
+ return NgwError;
18147
18148
  }(Error));
18148
18149
 
18149
18150
  function isObject(val) {
@@ -18257,11 +18258,6 @@ var NgwLeaflet = (function () {
18257
18258
  xhr.abort();
18258
18259
  });
18259
18260
  }
18260
- if (options.signal) {
18261
- options.signal.addEventListener('abort', function () {
18262
- xhr.abort();
18263
- });
18264
- }
18265
18261
  xhr.send(data);
18266
18262
  };
18267
18263
  }
@@ -18712,6 +18708,7 @@ var NgwLeaflet = (function () {
18712
18708
  this.id = ID$1++;
18713
18709
  this.emitter = new events.exports.EventEmitter();
18714
18710
  this.routeStr = '/api/component/pyramid/route';
18711
+ this.activeRequests = [];
18715
18712
  var exist = findConnector(options);
18716
18713
  if (exist) {
18717
18714
  return exist;
@@ -18797,6 +18794,7 @@ var NgwLeaflet = (function () {
18797
18794
  * Disconnecting a user. Aborting all current requests
18798
18795
  */
18799
18796
  NgwConnector.prototype.logout = function () {
18797
+ this.abort();
18800
18798
  removeConnector(this);
18801
18799
  this.options.auth = undefined;
18802
18800
  this.user = undefined;
@@ -18849,6 +18847,17 @@ var NgwLeaflet = (function () {
18849
18847
  }
18850
18848
  }
18851
18849
  };
18850
+ /** Stop all api requests */
18851
+ NgwConnector.prototype.abort = function () {
18852
+ for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
18853
+ var req = _a[_i];
18854
+ req.cancel();
18855
+ }
18856
+ this.activeRequests = [];
18857
+ };
18858
+ NgwConnector.prototype.getActiveApiRequests = function () {
18859
+ return __spreadArray([], this.activeRequests, true);
18860
+ };
18852
18861
  /**
18853
18862
  * Send request to NGW api router.
18854
18863
  * @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
@@ -19063,14 +19072,20 @@ var NgwLeaflet = (function () {
19063
19072
  NgwConnector.prototype._loadData = function (url, options) {
19064
19073
  var _this = this;
19065
19074
  options.responseType = options.responseType || 'json';
19066
- return new CancelablePromise(function (resolve, reject, onCancel) {
19075
+ var request = new CancelablePromise(function (resolve, reject, onCancel) {
19067
19076
  if (_this.user) {
19068
19077
  options = options || {};
19069
19078
  // options.withCredentials = true;
19070
19079
  options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
19071
19080
  }
19072
19081
  loadData(url, resolve, options, reject, onCancel);
19073
- }).catch(function (httpError) {
19082
+ })
19083
+ .then(function (resp) {
19084
+ _this._cleanActiveRequests(request);
19085
+ return resp;
19086
+ })
19087
+ .catch(function (httpError) {
19088
+ _this._cleanActiveRequests(request);
19074
19089
  if (httpError instanceof CancelablePromise.CancelError) ;
19075
19090
  else {
19076
19091
  // @ts-ignore
@@ -19083,6 +19098,20 @@ var NgwLeaflet = (function () {
19083
19098
  }
19084
19099
  }
19085
19100
  });
19101
+ if (options.signal &&
19102
+ typeof options.signal.addEventListener === 'function') {
19103
+ options.signal.addEventListener('abort', function () {
19104
+ request.cancel();
19105
+ });
19106
+ }
19107
+ this.activeRequests.push(request);
19108
+ return request;
19109
+ };
19110
+ NgwConnector.prototype._cleanActiveRequests = function (request) {
19111
+ var activeRequestIndex = this.activeRequests.indexOf(request);
19112
+ if (activeRequestIndex !== -1) {
19113
+ this.activeRequests.splice(activeRequestIndex, 1);
19114
+ }
19086
19115
  };
19087
19116
  NgwConnector.prototype._handleHttpError = function (er) {
19088
19117
  if (er) {
@@ -19192,12 +19221,12 @@ var NgwLeaflet = (function () {
19192
19221
  function fetchNgwExtent(options) {
19193
19222
  return options.connector.getResource(options.resourceId).then(function (resource) {
19194
19223
  if (resource) {
19195
- return fetchNgwResourceExtent(resource, options.connector);
19224
+ return fetchNgwResourceExtent(resource, options.connector, options);
19196
19225
  }
19197
19226
  });
19198
19227
  }
19199
19228
  /** @deprecated use {@link fetchNgwExtent} instead */
19200
- function fetchNgwResourceExtent(item, connector) {
19229
+ function fetchNgwResourceExtent(item, connector, options) {
19201
19230
  if (item.webmap) {
19202
19231
  return CancelablePromise.resolve(getNgwWebmapExtent(item.webmap));
19203
19232
  }
@@ -19206,15 +19235,12 @@ var NgwLeaflet = (function () {
19206
19235
  if (resource.cls && resource.cls.indexOf('style') !== -1) {
19207
19236
  return connector.getResource(resource.parent.id).then(function (res) {
19208
19237
  if (res) {
19209
- return fetchNgwLayerExtent({
19210
- resourceId: res.resource.id,
19211
- connector: connector,
19212
- });
19238
+ return fetchNgwLayerExtent(__assign(__assign({}, options), { resourceId: res.resource.id, connector: connector }));
19213
19239
  }
19214
19240
  });
19215
19241
  }
19216
19242
  else {
19217
- return fetchNgwLayerExtent({ resourceId: resource.id, connector: connector });
19243
+ return fetchNgwLayerExtent(__assign(__assign({}, options), { resourceId: resource.id, connector: connector }));
19218
19244
  }
19219
19245
  }
19220
19246
  }
@@ -19385,7 +19411,7 @@ var NgwLeaflet = (function () {
19385
19411
  }
19386
19412
  function fetchNgwLayerItemsRequest(options) {
19387
19413
  var params = __assign({}, FEATURE_REQUEST_PARAMS);
19388
- var limit = options.limit, offset = options.offset, orderBy = options.orderBy, paramList = options.paramList, connector = options.connector, intersects = options.intersects, resourceId = options.resourceId;
19414
+ 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;
19389
19415
  if (limit) {
19390
19416
  if (limit !== Number.POSITIVE_INFINITY) {
19391
19417
  params.limit = limit;
@@ -19415,11 +19441,10 @@ var NgwLeaflet = (function () {
19415
19441
  params.paramList = paramList;
19416
19442
  }
19417
19443
  var reqParams = __assign({ id: resourceId }, params);
19418
- return connector.get('feature_layer.feature.collection', { cache: options.cache }, reqParams);
19444
+ return connector.get('feature_layer.feature.collection', { cache: cache, signal: signal }, reqParams);
19419
19445
  }
19420
19446
 
19421
19447
  function prepareNgwFieldsToPropertiesFilter(fields) {
19422
- console.log(fields);
19423
19448
  var f;
19424
19449
  var _loop_1 = function () {
19425
19450
  var field = fields[f];
@@ -21428,7 +21453,7 @@ var NgwLeaflet = (function () {
21428
21453
  });
21429
21454
  });
21430
21455
  };
21431
- NgwResource.prototype.getBounds = function () {
21456
+ NgwResource.prototype.getBounds = function (options) {
21432
21457
  return __awaiter(this, void 0, void 0, function () {
21433
21458
  var _a;
21434
21459
  return __generator(this, function (_b) {
@@ -21439,7 +21464,7 @@ var NgwLeaflet = (function () {
21439
21464
  }
21440
21465
  if (!this.item) return [3 /*break*/, 2];
21441
21466
  _a = this;
21442
- return [4 /*yield*/, fetchNgwResourceExtent(this.item, this.connector)];
21467
+ return [4 /*yield*/, fetchNgwResourceExtent(this.item, this.connector, options)];
21443
21468
  case 1:
21444
21469
  _a._extent = _b.sent();
21445
21470
  return [2 /*return*/, this._extent];
@@ -22081,7 +22106,7 @@ var NgwLeaflet = (function () {
22081
22106
  return featureParams;
22082
22107
  }
22083
22108
  function fetchIdentifyGeoJson(options) {
22084
- var connector = options.connector, identify = options.identify;
22109
+ var connector = options.connector, identify = options.identify, requestOptions = options.requestOptions;
22085
22110
  for (var l in identify) {
22086
22111
  var id = Number(l);
22087
22112
  if (!isNaN(id)) {
@@ -22097,7 +22122,7 @@ var NgwLeaflet = (function () {
22097
22122
  }
22098
22123
  var params = getIdentifyItems(identify);
22099
22124
  if (params && params.length) {
22100
- return fetchNgwLayerFeature(__assign({ connector: connector }, params[0]));
22125
+ return fetchNgwLayerFeature(__assign(__assign(__assign({}, requestOptions), { connector: connector }), params[0]));
22101
22126
  }
22102
22127
  return CancelablePromise.resolve(undefined);
22103
22128
  }
@@ -22110,21 +22135,25 @@ var NgwLeaflet = (function () {
22110
22135
  return CancelablePromise.resolve(undefined);
22111
22136
  }
22112
22137
  function featureLayerIdentify(options) {
22113
- var g = options.geom;
22114
- var geom = [];
22115
- if (Array.isArray(g)) {
22116
- geom = g;
22138
+ var geom = options.geom, signal = options.signal, cache = options.cache;
22139
+ var geom_ = [];
22140
+ if (Array.isArray(geom)) {
22141
+ geom_ = geom;
22117
22142
  }
22118
22143
  else {
22119
- var polygon = g.type === 'Feature' ? g.geometry : g.type === 'Polygon' ? g : false;
22144
+ var polygon = geom.type === 'Feature'
22145
+ ? geom.geometry
22146
+ : geom.type === 'Polygon'
22147
+ ? geom
22148
+ : false;
22120
22149
  if (polygon) {
22121
- geom = polygon.coordinates[0];
22150
+ geom_ = polygon.coordinates[0];
22122
22151
  }
22123
22152
  }
22124
- if (geom) {
22153
+ if (geom_) {
22125
22154
  // create wkt string
22126
22155
  var polygonStr = [];
22127
- for (var _i = 0, geom_1 = geom; _i < geom_1.length; _i++) {
22156
+ for (var _i = 0, geom_1 = geom_; _i < geom_1.length; _i++) {
22128
22157
  var _a = geom_1[_i], lng = _a[0], lat = _a[1];
22129
22158
  var _b = degrees2meters(lng, lat), x = _b[0], y = _b[1];
22130
22159
  polygonStr.push(x + ' ' + y);
@@ -22136,18 +22165,22 @@ var NgwLeaflet = (function () {
22136
22165
  srs: 3857,
22137
22166
  layers: layers,
22138
22167
  };
22139
- return options.connector.post('feature_layer.identify', { data: data });
22168
+ return options.connector.post('feature_layer.identify', {
22169
+ data: data,
22170
+ signal: signal,
22171
+ cache: cache,
22172
+ });
22140
22173
  }
22141
22174
  else {
22142
22175
  throw new Error('Not valid geometry format to make intersection');
22143
22176
  }
22144
22177
  }
22145
22178
  function sendIdentifyRequest(ev, options) {
22146
- var _a;
22147
22179
  deprecatedMapClick(ev);
22148
- var _b = ev.lngLat, lng = _b[0], lat = _b[1];
22149
- var geom = (_a = options.geom) !== null && _a !== void 0 ? _a : getCirclePolygonCoordinates(lng, lat, options.radius);
22150
- return featureLayerIdentify(__assign(__assign({}, options), { geom: geom }));
22180
+ var _a = ev.lngLat, lng = _a[0], lat = _a[1];
22181
+ var geom = options.geom, radius = options.radius, signal = options.signal, cache = options.cache;
22182
+ var geom_ = geom !== null && geom !== void 0 ? geom : getCirclePolygonCoordinates(lng, lat, radius);
22183
+ return featureLayerIdentify(__assign(__assign({}, options), { geom: geom_, signal: signal, cache: cache }));
22151
22184
  }
22152
22185
  function createIdentifyItem(opt) {
22153
22186
  return new IdentifyItem(opt);