@nextgis/ngw-map 1.8.4 → 1.9.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/ngw-map; version: 1.8.4; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.9.0; author: NextGIS */
2
2
  var NgwMap = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -1428,10 +1428,6 @@ var NgwMap = (function (exports) {
1428
1428
  }
1429
1429
  return false;
1430
1430
  }
1431
- /** @deprecated use {@link isPropertyFilter} instead */
1432
- function checkIfPropertyFilter(filter) {
1433
- return isPropertyFilter(filter);
1434
- }
1435
1431
  function featureFilter(feature, filters) {
1436
1432
  var properties = __assign({}, feature.properties);
1437
1433
  if (properties) {
@@ -2051,7 +2047,11 @@ var NgwMap = (function (exports) {
2051
2047
  * @returns The map's current zoom level (0-24).
2052
2048
  */
2053
2049
  WebMapMain.prototype.getZoom = function () {
2054
- return this.mapAdapter.getZoom();
2050
+ var zoom = this.mapAdapter.getZoom();
2051
+ if (typeof zoom === 'number') {
2052
+ return zoom;
2053
+ }
2054
+ throw Error('Unable to get zoom level. Perhaps the map is not have been initialized yet');
2055
2055
  };
2056
2056
  WebMapMain.prototype.zoomIn = function () {
2057
2057
  if (this.mapAdapter.zoomIn) {
@@ -2077,27 +2077,25 @@ var NgwMap = (function (exports) {
2077
2077
  }
2078
2078
  }
2079
2079
  };
2080
- /**
2081
- * Sets the view of the map geographical center and zoom
2082
- * @param lngLat - Array of two numbers representing longitude and latitude of the center of the map view.
2083
- * @param zoom - The zoom level to set (0-24).
2084
- *
2085
- * @example
2086
- * ```javascript
2087
- * // Mount Everest 27° 59′ 17″ N, 86° 55′ 31″ E
2088
- * webMap.setView([86.925278, 27.988056], 12)
2089
- * ```
2090
- */
2091
- WebMapMain.prototype.setView = function (lngLat, zoom) {
2092
- if (this.mapAdapter.setView && lngLat && defined(zoom)) {
2093
- this.mapAdapter.setView(lngLat, zoom);
2080
+ WebMapMain.prototype.setView = function (lngLatOrOpt, zoom) {
2081
+ if (Array.isArray(lngLatOrOpt)) {
2082
+ var lngLat = lngLatOrOpt;
2083
+ if (this.mapAdapter.setView && lngLat && defined(zoom)) {
2084
+ this.mapAdapter.setView(lngLat, zoom);
2085
+ }
2086
+ else {
2087
+ if (lngLat) {
2088
+ this.mapAdapter.setCenter(lngLat);
2089
+ }
2090
+ if (defined(zoom)) {
2091
+ this.mapAdapter.setZoom(zoom);
2092
+ }
2093
+ }
2094
2094
  }
2095
2095
  else {
2096
- if (lngLat) {
2097
- this.mapAdapter.setCenter(lngLat);
2098
- }
2099
- if (defined(zoom)) {
2100
- this.mapAdapter.setZoom(zoom);
2096
+ var viewOpt = lngLatOrOpt;
2097
+ if (this.mapAdapter.setView) {
2098
+ this.mapAdapter.setView(viewOpt);
2101
2099
  }
2102
2100
  }
2103
2101
  };
@@ -2547,9 +2545,9 @@ var NgwMap = (function (exports) {
2547
2545
  var _a, _b;
2548
2546
  if (options === void 0) { options = {}; }
2549
2547
  return __awaiter(this, void 0, void 0, function () {
2550
- var id, _order, adapterEngine, geoJsonOptions, _c, maxZoom, minZoom, visibility, modified, _adapter, layerId, layer, opacity, getBounds, extent;
2551
- return __generator(this, function (_d) {
2552
- switch (_d.label) {
2548
+ var id, _order, adapterEngine, geoJsonOptions, visibility, modified, _adapter, layerId, layer, opacity, getBounds, extent;
2549
+ return __generator(this, function (_c) {
2550
+ switch (_c.label) {
2553
2551
  case 0:
2554
2552
  id = this._layersIdCounter++;
2555
2553
  _order = defined(order)
@@ -2568,13 +2566,12 @@ var NgwMap = (function (exports) {
2568
2566
  if (!('then' in adapter)) return [3 /*break*/, 4];
2569
2567
  return [4 /*yield*/, adapter];
2570
2568
  case 3:
2571
- adapterEngine = (_d.sent());
2572
- _d.label = 4;
2569
+ adapterEngine = (_c.sent());
2570
+ _c.label = 4;
2573
2571
  case 4:
2574
2572
  geoJsonOptions = options;
2575
2573
  this._updateGeoJsonOptions(geoJsonOptions);
2576
- _c = this.options, maxZoom = _c.maxZoom, minZoom = _c.minZoom;
2577
- options = __assign({ id: String(id), order: _order, maxZoom: maxZoom, minZoom: minZoom }, options);
2574
+ options = __assign({ id: String(id), order: _order }, options);
2578
2575
  visibility = (_a = options.visibility) !== null && _a !== void 0 ? _a : true;
2579
2576
  options.visibility = false;
2580
2577
  if (options.baselayer) {
@@ -2610,11 +2607,11 @@ var NgwMap = (function (exports) {
2610
2607
  this._emitLayerEvent('layer:preadd', layerId || '', _adapter);
2611
2608
  return [4 /*yield*/, this.onMapLoad()];
2612
2609
  case 5:
2613
- _d.sent();
2610
+ _c.sent();
2614
2611
  _adapter.map = this.mapAdapter.map;
2615
2612
  return [4 /*yield*/, _adapter.addLayer(_adapter.options)];
2616
2613
  case 6:
2617
- layer = _d.sent();
2614
+ layer = _c.sent();
2618
2615
  // checking that the original layer was inserted into the adapter anyway
2619
2616
  _adapter.layer = layer;
2620
2617
  // think about how to move `id` to the adapter's constructor,
@@ -2643,8 +2640,8 @@ var NgwMap = (function (exports) {
2643
2640
  if (!visibility) return [3 /*break*/, 8];
2644
2641
  return [4 /*yield*/, this.showLayer(layerId)];
2645
2642
  case 7:
2646
- _d.sent();
2647
- _d.label = 8;
2643
+ _c.sent();
2644
+ _c.label = 8;
2648
2645
  case 8:
2649
2646
  opacity = options.opacity;
2650
2647
  if (opacity !== undefined && opacity <= 1) {
@@ -2654,12 +2651,12 @@ var NgwMap = (function (exports) {
2654
2651
  if (!(options.fit && getBounds)) return [3 /*break*/, 11];
2655
2652
  return [4 /*yield*/, getBounds.call(_adapter)];
2656
2653
  case 9:
2657
- extent = _d.sent();
2654
+ extent = _c.sent();
2658
2655
  if (!extent) return [3 /*break*/, 11];
2659
2656
  return [4 /*yield*/, this.fitBounds(extent)];
2660
2657
  case 10:
2661
- _d.sent();
2662
- _d.label = 11;
2658
+ _c.sent();
2659
+ _c.label = 11;
2663
2660
  case 11:
2664
2661
  this._emitLayerEvent('layer:add', layerId, _adapter);
2665
2662
  return [2 /*return*/, _adapter];
@@ -3163,6 +3160,17 @@ var NgwMap = (function (exports) {
3163
3160
  attribution: tileJson.attribution,
3164
3161
  });
3165
3162
  };
3163
+ /** @internal */
3164
+ WebMapLayers.prototype._emitLayerEvent = function (name, id, options) {
3165
+ var name_ = String(name);
3166
+ if (defined(id) && name_.startsWith('layer:')) {
3167
+ var specificLayerName = name_.replace('layer:', 'layer-' + id + ':');
3168
+ // @ts-ignore can't paste template literal key for interface
3169
+ this.emitter.emit(specificLayerName, options);
3170
+ }
3171
+ // @ts-ignore
3172
+ this.emitter.emit(name, options);
3173
+ };
3166
3174
  WebMapLayers.prototype._onLayerClick = function (options) {
3167
3175
  return __awaiter(this, void 0, void 0, function () {
3168
3176
  var id;
@@ -3222,14 +3230,6 @@ var NgwMap = (function (exports) {
3222
3230
  }
3223
3231
  }
3224
3232
  };
3225
- WebMapLayers.prototype._emitLayerEvent = function (name, id, options) {
3226
- if (defined(id) && name.startsWith('layer:')) {
3227
- var specificLayerName = name.replace('layer:', 'layer-' + id + ':');
3228
- // @ts-ignore can't paste template literal key for interface
3229
- this.emitter.emit(specificLayerName, options);
3230
- }
3231
- this.emitter.emit(name, options);
3232
- };
3233
3233
  return WebMapLayers;
3234
3234
  }(WebMapMain));
3235
3235
 
@@ -5006,7 +5006,7 @@ var NgwMap = (function (exports) {
5006
5006
  };
5007
5007
  if (logic === 'any') {
5008
5008
  filters_.forEach(function (f) {
5009
- if (checkIfPropertyFilter(f)) {
5009
+ if (isPropertyFilter(f)) {
5010
5010
  _queries.push(fetchNgwLayerItemsRequest(__assign(__assign({}, opt), { paramList: __spreadArray(__spreadArray([], _parentAllParams, true), [createParam(f)]) })));
5011
5011
  }
5012
5012
  else {
@@ -5019,7 +5019,7 @@ var NgwMap = (function (exports) {
5019
5019
  var propertiesFilterList = [];
5020
5020
  for (var _i = 0, filters_1 = filters_; _i < filters_1.length; _i++) {
5021
5021
  var f = filters_1[_i];
5022
- if (checkIfPropertyFilter(f)) {
5022
+ if (isPropertyFilter(f)) {
5023
5023
  filters_2.push(createParam(f));
5024
5024
  }
5025
5025
  else {
@@ -5155,10 +5155,21 @@ var NgwMap = (function (exports) {
5155
5155
  });
5156
5156
  }
5157
5157
 
5158
+ function fetchNgwLayerCount(_a) {
5159
+ var connector = _a.connector, resourceId = _a.resourceId, _b = _a.cache, cache = _b === void 0 ? true : _b;
5160
+ return connector
5161
+ .get('feature_layer.feature.count', { cache: cache }, {
5162
+ id: resourceId,
5163
+ })
5164
+ .then(function (resp) {
5165
+ return resp.total_count;
5166
+ });
5167
+ }
5168
+
5158
5169
  function createGeoJsonAdapter(props) {
5159
5170
  var _a, _b;
5160
5171
  return __awaiter(this, void 0, void 0, function () {
5161
- var item, webMap, Adapter, connector, layerOptions, alop, addLayerOptionsPriority, options, GeoJsonAdapter, _fullDataLoad, _lastFilterArgs, _dataPromise, resourceId, getData, removed, abort, NgwGeoJsonAdapter;
5172
+ var item, webMap, Adapter, connector, layerOptions, alop, addLayerOptionsPriority, options, GeoJsonAdapter, _loadedIds, _fullDataLoad, _lastFilterArgs, _dataPromise, resourceId, getData, removed, abort, NgwGeoJsonAdapter;
5162
5173
  var _this = this;
5163
5174
  return __generator(this, function (_c) {
5164
5175
  switch (_c.label) {
@@ -5167,6 +5178,7 @@ var NgwMap = (function (exports) {
5167
5178
  addLayerOptionsPriority = alop !== null && alop !== void 0 ? alop : true;
5168
5179
  options = layerOptions;
5169
5180
  GeoJsonAdapter = Adapter || webMap.mapAdapter.layerAdapters.GEOJSON;
5181
+ _loadedIds = [];
5170
5182
  _fullDataLoad = false;
5171
5183
  return [4 /*yield*/, resourceIdFromLayerOptions(options, connector)];
5172
5184
  case 1:
@@ -5205,7 +5217,7 @@ var NgwMap = (function (exports) {
5205
5217
  }
5206
5218
  NgwGeoJsonAdapter.prototype.addLayer = function (opt) {
5207
5219
  return __awaiter(this, void 0, void 0, function () {
5208
- var needUpdate, waitFullLoad, layer, updatePromise;
5220
+ var needUpdate, waitFullLoad, strategy, layer, updatePromise;
5209
5221
  return __generator(this, function (_a) {
5210
5222
  switch (_a.label) {
5211
5223
  case 0:
@@ -5233,8 +5245,9 @@ var NgwMap = (function (exports) {
5233
5245
  opt.data = undefined;
5234
5246
  needUpdate = false;
5235
5247
  }
5248
+ strategy = opt.strategy || undefined;
5249
+ this.options.strategy = strategy;
5236
5250
  layer = _super.prototype.addLayer.call(this, opt);
5237
- this.options.strategy = opt.strategy || undefined;
5238
5251
  _lastFilterArgs = {
5239
5252
  filters: opt.propertiesFilter,
5240
5253
  options: getLayerFilterOptions(opt),
@@ -5248,7 +5261,7 @@ var NgwMap = (function (exports) {
5248
5261
  _a.sent();
5249
5262
  _a.label = 2;
5250
5263
  case 2:
5251
- if (this.options.strategy === 'BBOX' && !_fullDataLoad) {
5264
+ if (strategy && strategy.startsWith('BBOX') && !_fullDataLoad) {
5252
5265
  this._addBboxEventListener();
5253
5266
  }
5254
5267
  return [2 /*return*/, layer];
@@ -5262,10 +5275,11 @@ var NgwMap = (function (exports) {
5262
5275
  };
5263
5276
  NgwGeoJsonAdapter.prototype.getBounds = function () {
5264
5277
  return __awaiter(this, void 0, void 0, function () {
5265
- var hasData;
5278
+ var hasData, strategy;
5266
5279
  return __generator(this, function (_a) {
5267
5280
  hasData = this.getLayers && this.getLayers().length;
5268
- if (this.options.strategy === 'BBOX' || hasData) {
5281
+ strategy = this.options.strategy;
5282
+ if ((strategy === null || strategy === void 0 ? void 0 : strategy.startsWith('BBOX')) || hasData) {
5269
5283
  return [2 /*return*/, fetchNgwResourceExtent(item, connector)];
5270
5284
  }
5271
5285
  else {
@@ -5288,61 +5302,86 @@ var NgwMap = (function (exports) {
5288
5302
  abort();
5289
5303
  };
5290
5304
  NgwGeoJsonAdapter.prototype.getCount = function () {
5291
- var _this = this;
5292
- if (this._count !== undefined) {
5293
- return this._count;
5294
- }
5295
- return connector
5296
- .get('feature_layer.feature.count', { cache: true }, {
5297
- id: resourceId,
5298
- })
5299
- .then(function (resp) {
5300
- if (resp) {
5301
- _this._count = resp.total_count;
5302
- return _this._count;
5303
- }
5304
- });
5305
+ return fetchNgwLayerCount({ connector: connector, resourceId: resourceId, cache: true });
5305
5306
  };
5306
5307
  NgwGeoJsonAdapter.prototype.updateLayer = function (filterArgs) {
5308
+ var _a;
5307
5309
  return __awaiter(this, void 0, void 0, function () {
5308
- var data, count, er_1;
5309
- return __generator(this, function (_a) {
5310
- switch (_a.label) {
5310
+ var _b, minZoom, maxZoom, zoom, data, newData, count, _i, _c, f, er_1;
5311
+ return __generator(this, function (_d) {
5312
+ switch (_d.label) {
5311
5313
  case 0:
5312
5314
  filterArgs = filterArgs || _lastFilterArgs || {};
5313
- if (!(this.options.strategy === 'BBOX')) return [3 /*break*/, 2];
5315
+ if (!((_a = this.options.strategy) === null || _a === void 0 ? void 0 : _a.startsWith('BBOX'))) return [3 /*break*/, 2];
5314
5316
  return [4 /*yield*/, webMap.onLoad('create')];
5315
5317
  case 1:
5316
- _a.sent();
5318
+ _d.sent();
5317
5319
  filterArgs.options = filterArgs.options || {};
5318
5320
  filterArgs.options.intersects = webMap.getBounds();
5319
- _a.label = 2;
5321
+ _b = this.options, minZoom = _b.minZoom, maxZoom = _b.maxZoom;
5322
+ zoom = webMap.getZoom();
5323
+ if (minZoom !== undefined && zoom < minZoom) {
5324
+ return [2 /*return*/];
5325
+ }
5326
+ if (maxZoom !== undefined && zoom > maxZoom) {
5327
+ return [2 /*return*/];
5328
+ }
5329
+ if (_fullDataLoad) {
5330
+ return [2 /*return*/];
5331
+ }
5332
+ _d.label = 2;
5320
5333
  case 2:
5321
5334
  if (removed) {
5322
5335
  return [2 /*return*/];
5323
5336
  }
5324
- _a.label = 3;
5337
+ _d.label = 3;
5325
5338
  case 3:
5326
- _a.trys.push([3, 7, , 8]);
5339
+ _d.trys.push([3, 10, , 11]);
5327
5340
  return [4 /*yield*/, getData(filterArgs.filters, __assign(__assign({}, filterArgs.options), { srs: this.options.srs }))];
5328
5341
  case 4:
5329
- data = _a.sent();
5342
+ data = _d.sent();
5343
+ newData = data;
5330
5344
  return [4 /*yield*/, this.getCount()];
5331
5345
  case 5:
5332
- count = _a.sent();
5333
- _fullDataLoad = count === data.features.length;
5334
- return [4 /*yield*/, webMap.setLayerData(this, data)];
5346
+ count = _d.sent();
5347
+ if (!(this.options.strategy === 'BBOX+')) return [3 /*break*/, 7];
5348
+ newData = {
5349
+ type: 'FeatureCollection',
5350
+ features: [],
5351
+ };
5352
+ for (_i = 0, _c = data.features; _i < _c.length; _i++) {
5353
+ f = _c[_i];
5354
+ if (_loadedIds.indexOf(String(f.id)) === -1) {
5355
+ _loadedIds.push(String(f.id));
5356
+ newData.features.push(f);
5357
+ }
5358
+ }
5359
+ _fullDataLoad = count !== undefined && _loadedIds.length >= count;
5360
+ return [4 /*yield*/, webMap.addLayerData(this, newData)];
5335
5361
  case 6:
5336
- _a.sent();
5337
- this.emitter.emit('updated');
5338
- return [3 /*break*/, 8];
5362
+ _d.sent();
5363
+ return [3 /*break*/, 9];
5339
5364
  case 7:
5340
- er_1 = _a.sent();
5365
+ _fullDataLoad = count !== undefined && data.features.length >= count;
5366
+ return [4 /*yield*/, webMap.setLayerData(this, data)];
5367
+ case 8:
5368
+ _d.sent();
5369
+ _d.label = 9;
5370
+ case 9:
5371
+ this.emitter.emit('updated', data);
5372
+ webMap._emitLayerEvent('layer:updated', options.id || '', {
5373
+ data: data,
5374
+ newData: newData,
5375
+ isFull: _fullDataLoad,
5376
+ });
5377
+ return [3 /*break*/, 11];
5378
+ case 10:
5379
+ er_1 = _d.sent();
5341
5380
  if (er_1 instanceof Error && er_1.name !== 'CancelError') {
5342
5381
  throw er_1;
5343
5382
  }
5344
- return [3 /*break*/, 8];
5345
- case 8:
5383
+ return [3 /*break*/, 11];
5384
+ case 11:
5346
5385
  if (_super.prototype.updateLayer) {
5347
5386
  _super.prototype.updateLayer.call(this);
5348
5387
  }
@@ -6312,8 +6351,6 @@ var NgwMap = (function (exports) {
6312
6351
  return setScaleRatio(scale);
6313
6352
  };
6314
6353
  NgwWebmapItem.prototype._getZoomRange = function (item) {
6315
- var minZoomMap = this.webMap.options.minZoom;
6316
- var maxZoomMap = this.webMap.options.maxZoom;
6317
6354
  var minZoomWebmap = this.options.minZoom;
6318
6355
  var maxZoomWebmap = this.options.maxZoom;
6319
6356
  var minZoomLayer = item.layer_min_scale_denom
@@ -6322,8 +6359,8 @@ var NgwMap = (function (exports) {
6322
6359
  var maxZoomLayer = item.layer_max_scale_denom
6323
6360
  ? this._mapScaleToZoomLevel(item.layer_max_scale_denom)
6324
6361
  : undefined;
6325
- var minZooms = [minZoomMap, minZoomWebmap, minZoomLayer].filter(Boolean);
6326
- var maxZooms = [maxZoomMap, maxZoomWebmap, maxZoomLayer].filter(Boolean);
6362
+ var minZooms = [minZoomWebmap, minZoomLayer].filter(Boolean);
6363
+ var maxZooms = [maxZoomWebmap, maxZoomLayer].filter(Boolean);
6327
6364
  var minZoom = Math.max.apply(Math, minZooms);
6328
6365
  var maxZoom = Math.min.apply(Math, maxZooms);
6329
6366
  return { minZoom: minZoom, maxZoom: maxZoom };