@nextgis/ngw-leaflet 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-leaflet; version: 1.12.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.13.2; 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.12.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.13.2; author: NextGIS */
2
2
  var NgwLeaflet = (function () {
3
3
  'use strict';
4
4
 
@@ -15399,6 +15399,9 @@ var NgwLeaflet = (function () {
15399
15399
 
15400
15400
  function isObject$1(val) {
15401
15401
  return Object.prototype.toString.call(val) === '[object Object]';
15402
+ }
15403
+ function isArray(val) {
15404
+ return Object.prototype.toString.call(val) === '[object Array]';
15402
15405
  }
15403
15406
 
15404
15407
  function fixUrlStr(url) {
@@ -16462,6 +16465,9 @@ var NgwLeaflet = (function () {
16462
16465
  'movestart',
16463
16466
  'move',
16464
16467
  'moveend',
16468
+ 'mousemove',
16469
+ 'mouseout',
16470
+ 'mouseover',
16465
16471
  ];
16466
16472
  if (opt && opt.include) {
16467
16473
  events = events.filter(function (x) { return opt.include.includes(x); });
@@ -18113,31 +18119,31 @@ var NgwLeaflet = (function () {
18113
18119
  /**
18114
18120
  * Thrown when...
18115
18121
  */
18116
- var NgwError = /** @class */ (function (_super) {
18117
- __extends(NgwError, _super);
18118
- function NgwError(er) {
18122
+ var NetworkError = /** @class */ (function (_super) {
18123
+ __extends(NetworkError, _super);
18124
+ function NetworkError(url) {
18119
18125
  var _this = _super.call(this) || this;
18120
- _this.name = 'NgwError';
18121
- Object.assign(_this, er);
18122
- Object.setPrototypeOf(_this, NgwError.prototype);
18126
+ _this.name = 'NetworkError';
18127
+ Object.setPrototypeOf(_this, NetworkError.prototype);
18128
+ _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
18123
18129
  return _this;
18124
18130
  }
18125
- return NgwError;
18131
+ return NetworkError;
18126
18132
  }(Error));
18127
18133
 
18128
18134
  /**
18129
18135
  * Thrown when...
18130
18136
  */
18131
- var NetworkError = /** @class */ (function (_super) {
18132
- __extends(NetworkError, _super);
18133
- function NetworkError(url) {
18137
+ var NgwError = /** @class */ (function (_super) {
18138
+ __extends(NgwError, _super);
18139
+ function NgwError(er) {
18134
18140
  var _this = _super.call(this) || this;
18135
- _this.name = 'NetworkError';
18136
- Object.setPrototypeOf(_this, NetworkError.prototype);
18137
- _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
18141
+ _this.name = 'NgwError';
18142
+ Object.assign(_this, er);
18143
+ Object.setPrototypeOf(_this, NgwError.prototype);
18138
18144
  return _this;
18139
18145
  }
18140
- return NetworkError;
18146
+ return NgwError;
18141
18147
  }(Error));
18142
18148
 
18143
18149
  function isObject(val) {
@@ -18392,7 +18398,12 @@ var NgwLeaflet = (function () {
18392
18398
  forCache.id = resource;
18393
18399
  }
18394
18400
  else if (isObject(resource)) {
18395
- forCache.id = resource.id;
18401
+ if (resource.id !== undefined) {
18402
+ forCache.id = resource.id;
18403
+ }
18404
+ else if (resource.keyname) {
18405
+ forCache.keyname = resource.keyname;
18406
+ }
18396
18407
  }
18397
18408
  var makeRequest = function () {
18398
18409
  if (typeof resource === 'string') {
@@ -18494,20 +18505,35 @@ var NgwLeaflet = (function () {
18494
18505
  };
18495
18506
  ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
18496
18507
  var _this = this;
18497
- return this.getId(resource).then(function (parent) {
18498
- return _this.connector
18499
- .get('resource.collection', __assign({ cache: true }, requestOptions), {
18500
- parent: parent,
18501
- })
18502
- .then(function (items) {
18503
- for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
18504
- var i = items_1[_i];
18505
- _this.cache.add('resource.item', CancelablePromise.resolve(i), {
18506
- id: i.resource.id,
18507
- });
18508
+ return this.getIdOrFail(resource).then(function (parent) {
18509
+ return _this._getChildrenOf(parent, requestOptions);
18510
+ });
18511
+ };
18512
+ ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
18513
+ var _this = this;
18514
+ if (_items === void 0) { _items = []; }
18515
+ return this.connector
18516
+ .get('resource.collection', __assign({ cache: true }, requestOptions), {
18517
+ parent: parent,
18518
+ })
18519
+ .then(function (items) {
18520
+ var recursivePromises = [];
18521
+ for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
18522
+ var item = items_1[_i];
18523
+ _this.cache.add('resource.item', CancelablePromise.resolve(item), {
18524
+ id: item.resource.id,
18525
+ });
18526
+ _items.push(item);
18527
+ if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
18528
+ recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
18508
18529
  }
18509
- return items;
18510
- });
18530
+ }
18531
+ if (recursivePromises.length) {
18532
+ return CancelablePromise.all(recursivePromises).then(function () {
18533
+ return _items;
18534
+ });
18535
+ }
18536
+ return _items;
18511
18537
  });
18512
18538
  };
18513
18539
  ResourcesControl.prototype.update = function (resource, data) {
@@ -19032,7 +19058,7 @@ var NgwLeaflet = (function () {
19032
19058
  NgwConnector.prototype._loadData = function (url, options) {
19033
19059
  var _this = this;
19034
19060
  options.responseType = options.responseType || 'json';
19035
- return new CancelablePromise(function (resolve, reject, onCancel) {
19061
+ var request = new CancelablePromise(function (resolve, reject, onCancel) {
19036
19062
  if (_this.user) {
19037
19063
  options = options || {};
19038
19064
  // options.withCredentials = true;
@@ -19052,6 +19078,13 @@ var NgwLeaflet = (function () {
19052
19078
  }
19053
19079
  }
19054
19080
  });
19081
+ if (options.signal &&
19082
+ typeof options.signal.addEventListener === 'function') {
19083
+ options.signal.addEventListener('abort', function () {
19084
+ request.cancel();
19085
+ });
19086
+ }
19087
+ return request;
19055
19088
  };
19056
19089
  NgwConnector.prototype._handleHttpError = function (er) {
19057
19090
  if (er) {
@@ -19161,12 +19194,12 @@ var NgwLeaflet = (function () {
19161
19194
  function fetchNgwExtent(options) {
19162
19195
  return options.connector.getResource(options.resourceId).then(function (resource) {
19163
19196
  if (resource) {
19164
- return fetchNgwResourceExtent(resource, options.connector);
19197
+ return fetchNgwResourceExtent(resource, options.connector, options);
19165
19198
  }
19166
19199
  });
19167
19200
  }
19168
19201
  /** @deprecated use {@link fetchNgwExtent} instead */
19169
- function fetchNgwResourceExtent(item, connector) {
19202
+ function fetchNgwResourceExtent(item, connector, options) {
19170
19203
  if (item.webmap) {
19171
19204
  return CancelablePromise.resolve(getNgwWebmapExtent(item.webmap));
19172
19205
  }
@@ -19175,15 +19208,12 @@ var NgwLeaflet = (function () {
19175
19208
  if (resource.cls && resource.cls.indexOf('style') !== -1) {
19176
19209
  return connector.getResource(resource.parent.id).then(function (res) {
19177
19210
  if (res) {
19178
- return fetchNgwLayerExtent({
19179
- resourceId: res.resource.id,
19180
- connector: connector,
19181
- });
19211
+ return fetchNgwLayerExtent(__assign(__assign({}, options), { resourceId: res.resource.id, connector: connector }));
19182
19212
  }
19183
19213
  });
19184
19214
  }
19185
19215
  else {
19186
- return fetchNgwLayerExtent({ resourceId: resource.id, connector: connector });
19216
+ return fetchNgwLayerExtent(__assign(__assign({}, options), { resourceId: resource.id, connector: connector }));
19187
19217
  }
19188
19218
  }
19189
19219
  }
@@ -19354,7 +19384,7 @@ var NgwLeaflet = (function () {
19354
19384
  }
19355
19385
  function fetchNgwLayerItemsRequest(options) {
19356
19386
  var params = __assign({}, FEATURE_REQUEST_PARAMS);
19357
- var limit = options.limit, offset = options.offset, orderBy = options.orderBy, paramList = options.paramList, connector = options.connector, intersects = options.intersects, resourceId = options.resourceId;
19387
+ 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;
19358
19388
  if (limit) {
19359
19389
  if (limit !== Number.POSITIVE_INFINITY) {
19360
19390
  params.limit = limit;
@@ -19384,7 +19414,7 @@ var NgwLeaflet = (function () {
19384
19414
  params.paramList = paramList;
19385
19415
  }
19386
19416
  var reqParams = __assign({ id: resourceId }, params);
19387
- return connector.get('feature_layer.feature.collection', { cache: options.cache }, reqParams);
19417
+ return connector.get('feature_layer.feature.collection', { cache: cache, signal: signal }, reqParams);
19388
19418
  }
19389
19419
 
19390
19420
  function prepareNgwFieldsToPropertiesFilter(fields) {
@@ -19407,6 +19437,9 @@ var NgwLeaflet = (function () {
19407
19437
  fields[f] = new (Date.bind.apply(Date, __spreadArray([void 0], dt_1, false)))().toISOString();
19408
19438
  }
19409
19439
  }
19440
+ else if (f === 'id' && typeof field === 'string') {
19441
+ fields[f] = field.split(',').map(Number);
19442
+ }
19410
19443
  };
19411
19444
  for (f in fields) {
19412
19445
  _loop_1();
@@ -19419,7 +19452,7 @@ var NgwLeaflet = (function () {
19419
19452
  if (filters) {
19420
19453
  return createFeatureFieldFilterQueries(__assign(__assign({}, options), { filters: filters })).then(function (data) {
19421
19454
  var _a;
19422
- var clientFilterValidate = (_a = options.clientFilterValidate) !== null && _a !== void 0 ? _a : true;
19455
+ var clientFilterValidate = (_a = options.clientFilterValidate) !== null && _a !== void 0 ? _a : isFilterWithAnyCase(filters);
19423
19456
  // Additional client-side filter check
19424
19457
  if (clientFilterValidate) {
19425
19458
  data = data.filter(function (y) {
@@ -19434,6 +19467,21 @@ var NgwLeaflet = (function () {
19434
19467
  else {
19435
19468
  return fetchNgwLayerItemsRequest(options);
19436
19469
  }
19470
+ }
19471
+ function isFilterWithAnyCase(filters) {
19472
+ if (filters[0] === 'any') {
19473
+ return true;
19474
+ }
19475
+ for (var i = 1; i < filters.length; i++) {
19476
+ var p = filters[i];
19477
+ if (isArray(p)) {
19478
+ var deep = isFilterWithAnyCase(p);
19479
+ if (deep) {
19480
+ return true;
19481
+ }
19482
+ }
19483
+ }
19484
+ return false;
19437
19485
  }
19438
19486
 
19439
19487
  function fetchNgwLayerFeatures(options) {
@@ -21378,7 +21426,7 @@ var NgwLeaflet = (function () {
21378
21426
  });
21379
21427
  });
21380
21428
  };
21381
- NgwResource.prototype.getBounds = function () {
21429
+ NgwResource.prototype.getBounds = function (options) {
21382
21430
  return __awaiter(this, void 0, void 0, function () {
21383
21431
  var _a;
21384
21432
  return __generator(this, function (_b) {
@@ -21389,7 +21437,7 @@ var NgwLeaflet = (function () {
21389
21437
  }
21390
21438
  if (!this.item) return [3 /*break*/, 2];
21391
21439
  _a = this;
21392
- return [4 /*yield*/, fetchNgwResourceExtent(this.item, this.connector)];
21440
+ return [4 /*yield*/, fetchNgwResourceExtent(this.item, this.connector, options)];
21393
21441
  case 1:
21394
21442
  _a._extent = _b.sent();
21395
21443
  return [2 /*return*/, this._extent];
@@ -21983,7 +22031,6 @@ var NgwLeaflet = (function () {
21983
22031
 
21984
22032
  function getIdentifyItems(identify, multiple) {
21985
22033
  if (multiple === void 0) { multiple = false; }
21986
- var params;
21987
22034
  var resources = [];
21988
22035
  var paramsList = [];
21989
22036
  for (var l in identify) {
@@ -22004,14 +22051,9 @@ var NgwLeaflet = (function () {
22004
22051
  if ('features' in identifyItem) {
22005
22052
  var layerFeatures = identifyItem.features;
22006
22053
  var resourceId = Number(l);
22007
- var feature = layerFeatures[0];
22008
- if (feature) {
22009
- params = {
22010
- featureId: feature.id,
22011
- resourceId: resourceId,
22012
- feature: feature,
22013
- };
22014
- paramsList.push(params);
22054
+ var featureParams = createParamsFromFeatures(layerFeatures, resourceId, multiple);
22055
+ if (featureParams.length) {
22056
+ paramsList.push.apply(paramsList, featureParams);
22015
22057
  if (!multiple) {
22016
22058
  break;
22017
22059
  }
@@ -22020,8 +22062,24 @@ var NgwLeaflet = (function () {
22020
22062
  }
22021
22063
  return paramsList;
22022
22064
  }
22065
+ function createParamsFromFeatures(features, resourceId, multiple) {
22066
+ var featureParams = [];
22067
+ for (var _i = 0, features_1 = features; _i < features_1.length; _i++) {
22068
+ var feature = features_1[_i];
22069
+ var params = {
22070
+ featureId: feature.id,
22071
+ resourceId: resourceId,
22072
+ feature: feature,
22073
+ };
22074
+ featureParams.push(params);
22075
+ if (!multiple) {
22076
+ break;
22077
+ }
22078
+ }
22079
+ return featureParams;
22080
+ }
22023
22081
  function fetchIdentifyGeoJson(options) {
22024
- var connector = options.connector, identify = options.identify;
22082
+ var connector = options.connector, identify = options.identify, requestOptions = options.requestOptions;
22025
22083
  for (var l in identify) {
22026
22084
  var id = Number(l);
22027
22085
  if (!isNaN(id)) {
@@ -22037,7 +22095,7 @@ var NgwLeaflet = (function () {
22037
22095
  }
22038
22096
  var params = getIdentifyItems(identify);
22039
22097
  if (params && params.length) {
22040
- return fetchNgwLayerFeature(__assign({ connector: connector }, params[0]));
22098
+ return fetchNgwLayerFeature(__assign(__assign(__assign({}, requestOptions), { connector: connector }), params[0]));
22041
22099
  }
22042
22100
  return CancelablePromise.resolve(undefined);
22043
22101
  }
@@ -22050,21 +22108,25 @@ var NgwLeaflet = (function () {
22050
22108
  return CancelablePromise.resolve(undefined);
22051
22109
  }
22052
22110
  function featureLayerIdentify(options) {
22053
- var g = options.geom;
22054
- var geom = [];
22055
- if (Array.isArray(g)) {
22056
- geom = g;
22111
+ var geom = options.geom, signal = options.signal, cache = options.cache;
22112
+ var geom_ = [];
22113
+ if (Array.isArray(geom)) {
22114
+ geom_ = geom;
22057
22115
  }
22058
22116
  else {
22059
- var polygon = g.type === 'Feature' ? g.geometry : g.type === 'Polygon' ? g : false;
22117
+ var polygon = geom.type === 'Feature'
22118
+ ? geom.geometry
22119
+ : geom.type === 'Polygon'
22120
+ ? geom
22121
+ : false;
22060
22122
  if (polygon) {
22061
- geom = polygon.coordinates[0];
22123
+ geom_ = polygon.coordinates[0];
22062
22124
  }
22063
22125
  }
22064
- if (geom) {
22126
+ if (geom_) {
22065
22127
  // create wkt string
22066
22128
  var polygonStr = [];
22067
- for (var _i = 0, geom_1 = geom; _i < geom_1.length; _i++) {
22129
+ for (var _i = 0, geom_1 = geom_; _i < geom_1.length; _i++) {
22068
22130
  var _a = geom_1[_i], lng = _a[0], lat = _a[1];
22069
22131
  var _b = degrees2meters(lng, lat), x = _b[0], y = _b[1];
22070
22132
  polygonStr.push(x + ' ' + y);
@@ -22076,18 +22138,22 @@ var NgwLeaflet = (function () {
22076
22138
  srs: 3857,
22077
22139
  layers: layers,
22078
22140
  };
22079
- return options.connector.post('feature_layer.identify', { data: data });
22141
+ return options.connector.post('feature_layer.identify', {
22142
+ data: data,
22143
+ signal: signal,
22144
+ cache: cache,
22145
+ });
22080
22146
  }
22081
22147
  else {
22082
22148
  throw new Error('Not valid geometry format to make intersection');
22083
22149
  }
22084
22150
  }
22085
22151
  function sendIdentifyRequest(ev, options) {
22086
- var _a;
22087
22152
  deprecatedMapClick(ev);
22088
- var _b = ev.lngLat, lng = _b[0], lat = _b[1];
22089
- var geom = (_a = options.geom) !== null && _a !== void 0 ? _a : getCirclePolygonCoordinates(lng, lat, options.radius);
22090
- return featureLayerIdentify(__assign(__assign({}, options), { geom: geom }));
22153
+ var _a = ev.lngLat, lng = _a[0], lat = _a[1];
22154
+ var geom = options.geom, radius = options.radius, signal = options.signal, cache = options.cache;
22155
+ var geom_ = geom !== null && geom !== void 0 ? geom : getCirclePolygonCoordinates(lng, lat, radius);
22156
+ return featureLayerIdentify(__assign(__assign({}, options), { geom: geom_, signal: signal, cache: cache }));
22091
22157
  }
22092
22158
  function createIdentifyItem(opt) {
22093
22159
  return new IdentifyItem(opt);
@@ -24247,18 +24313,25 @@ var NgwLeaflet = (function () {
24247
24313
  this._universalEvents = [
24248
24314
  'move',
24249
24315
  'zoom',
24250
- 'moveend',
24251
24316
  'zoomend',
24252
24317
  'zoomstart',
24318
+ 'moveend',
24253
24319
  'movestart',
24254
24320
  ];
24321
+ this._positionEvents = [
24322
+ 'mousemove',
24323
+ 'mouseout',
24324
+ 'mouseover',
24325
+ ];
24255
24326
  }
24256
24327
  LeafletMapAdapter.prototype.create = function (options) {
24257
24328
  var _this = this;
24258
24329
  this.options = __assign({}, options);
24259
24330
  if (this.options.target) {
24260
24331
  var _a = this.options, zoom = _a.zoom, center = _a.center, maxZoom = _a.maxZoom, minZoom = _a.minZoom, mb = _a.maxBounds, mapAdapterOptions = _a.mapAdapterOptions;
24261
- this.map = new leafletSrc.exports.Map(this.options.target, __assign({ attributionControl: false, zoomControl: false, maxBounds: mb ? arrayToBoundsExpression(mb) : undefined, maxZoom: maxZoom, minZoom: minZoom, center: center && [center[1], center[0]], zoom: zoom }, mapAdapterOptions));
24332
+ this.map =
24333
+ this.options.map ||
24334
+ new leafletSrc.exports.Map(this.options.target, __assign({ attributionControl: false, zoomControl: false, maxBounds: mb ? arrayToBoundsExpression(mb) : undefined, maxZoom: maxZoom, minZoom: minZoom, center: center && [center[1], center[0]], zoom: zoom }, mapAdapterOptions));
24262
24335
  // create default pane
24263
24336
  var defPane = this.map.createPane('order-0');
24264
24337
  this.map._addUnselectCb = function (def) {
@@ -24504,9 +24577,22 @@ var NgwLeaflet = (function () {
24504
24577
  map.on('click', function (evt) {
24505
24578
  _this.onMapClick(evt);
24506
24579
  });
24507
- this._universalEvents.forEach(function (e) {
24580
+ var _loop_1 = function (e) {
24508
24581
  map.on(e, function () { return _this.emitter.emit(e, _this); }, map);
24509
- });
24582
+ };
24583
+ for (var _i = 0, _a = this._universalEvents; _i < _a.length; _i++) {
24584
+ var e = _a[_i];
24585
+ _loop_1(e);
24586
+ }
24587
+ var _loop_2 = function (e) {
24588
+ map.on(e, function (evt) {
24589
+ return _this.emitter.emit(e, convertMapClickEvent(evt));
24590
+ }, map);
24591
+ };
24592
+ for (var _b = 0, _c = this._positionEvents; _b < _c.length; _b++) {
24593
+ var e = _c[_b];
24594
+ _loop_2(e);
24595
+ }
24510
24596
  }
24511
24597
  };
24512
24598
  LeafletMapAdapter.layerAdapters = {