@nextgis/ngw-map 1.11.9 → 1.12.1

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.11.9; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.12.1; author: NextGIS */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -17,29 +17,101 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
17
17
  var CancelablePromise__default = /*#__PURE__*/_interopDefaultLegacy(CancelablePromise);
18
18
  var NgwConnector__default = /*#__PURE__*/_interopDefaultLegacy(NgwConnector);
19
19
 
20
+ /*! *****************************************************************************
21
+ Copyright (c) Microsoft Corporation.
22
+
23
+ Permission to use, copy, modify, and/or distribute this software for any
24
+ purpose with or without fee is hereby granted.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
27
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
28
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
29
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
30
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
31
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32
+ PERFORMANCE OF THIS SOFTWARE.
33
+ ***************************************************************************** */
34
+ /* global Reflect, Promise */
35
+
36
+ var extendStatics = function(d, b) {
37
+ extendStatics = Object.setPrototypeOf ||
38
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
39
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
40
+ return extendStatics(d, b);
41
+ };
42
+
43
+ function __extends(d, b) {
44
+ if (typeof b !== "function" && b !== null)
45
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
46
+ extendStatics(d, b);
47
+ function __() { this.constructor = d; }
48
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
49
+ }
50
+
51
+ var __assign = function() {
52
+ __assign = Object.assign || function __assign(t) {
53
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
54
+ s = arguments[i];
55
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
56
+ }
57
+ return t;
58
+ };
59
+ return __assign.apply(this, arguments);
60
+ };
61
+
62
+ function __awaiter(thisArg, _arguments, P, generator) {
63
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
64
+ return new (P || (P = Promise))(function (resolve, reject) {
65
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
66
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
67
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
68
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
69
+ });
70
+ }
71
+
72
+ function __generator(thisArg, body) {
73
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
74
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
75
+ function verb(n) { return function (v) { return step([n, v]); }; }
76
+ function step(op) {
77
+ if (f) throw new TypeError("Generator is already executing.");
78
+ while (_) try {
79
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
80
+ if (y = 0, t) op = [op[0] & 2, t.value];
81
+ switch (op[0]) {
82
+ case 0: case 1: t = op; break;
83
+ case 4: _.label++; return { value: op[1], done: false };
84
+ case 5: _.label++; y = op[1]; op = [0]; continue;
85
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
86
+ default:
87
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
88
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
89
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
90
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
91
+ if (t[2]) _.ops.pop();
92
+ _.trys.pop(); continue;
93
+ }
94
+ op = body.call(thisArg, _);
95
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
96
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
97
+ }
98
+ }
99
+
20
100
  function appendNgwResources(options, resource, defOptions, overwriteOptions) {
21
101
  if (typeof resource === 'number' || typeof resource === 'string') {
22
102
  resource = Number(resource);
23
- options.push({
24
- ...defOptions,
25
- resource,
26
- });
103
+ options.push(__assign(__assign({}, defOptions), { resource: resource }));
27
104
  }
28
105
  else if (Array.isArray(resource)) {
29
- const [resourceId, id] = resource;
30
- options.push({
31
- ...defOptions,
32
- resource: resourceId,
33
- id,
34
- ...overwriteOptions,
35
- });
106
+ var resourceId = resource[0], id = resource[1];
107
+ options.push(__assign(__assign(__assign({}, defOptions), { resource: resourceId, id: id }), overwriteOptions));
36
108
  }
37
109
  else if (typeof resource === 'object') {
38
- options.push({ ...defOptions, ...resource, ...overwriteOptions });
110
+ options.push(__assign(__assign(__assign({}, defOptions), resource), overwriteOptions));
39
111
  }
40
112
  }
41
113
 
42
- const OPTIONS = {
114
+ var OPTIONS = {
43
115
  target: 'map',
44
116
  baseUrl: '',
45
117
  whitlabel: false,
@@ -56,9 +128,9 @@ const OPTIONS = {
56
128
  pixelRadius: 10,
57
129
  };
58
130
  function prepareWebMapOptions(options) {
59
- const kits = [new qmsKit.QmsKit()];
131
+ var kits = [new qmsKit.QmsKit()];
60
132
  if (options.starterKits) {
61
- options.starterKits.forEach((x) => {
133
+ options.starterKits.forEach(function (x) {
62
134
  kits.push(x);
63
135
  });
64
136
  }
@@ -82,19 +154,15 @@ function prepareWebMapOptions(options) {
82
154
  auth: options.auth,
83
155
  }));
84
156
  }
85
- options = {
86
- ...options,
87
- starterKits: kits,
88
- create: false,
89
- };
157
+ options = __assign(__assign({}, options), { starterKits: kits, create: false });
90
158
  return options;
91
159
  }
92
160
 
93
161
  function getIdentifyRadius(center, zoom, pixelRadius) {
94
162
  pixelRadius = pixelRadius !== null && pixelRadius !== void 0 ? pixelRadius : 10;
95
- const metresPerPixel = (40075016.686 * Math.abs(Math.cos((center[1] * 180) / Math.PI))) /
163
+ var metresPerPixel = (40075016.686 * Math.abs(Math.cos((center[1] * 180) / Math.PI))) /
96
164
  Math.pow(2, zoom + 8);
97
- const radius = pixelRadius * metresPerPixel * 0.0005;
165
+ var radius = pixelRadius * metresPerPixel * 0.0005;
98
166
  return radius;
99
167
  }
100
168
 
@@ -117,27 +185,29 @@ function getIdentifyRadius(center, zoom, pixelRadius) {
117
185
  * });
118
186
  * ```
119
187
  */
120
- class NgwMap extends webmap.WebMap {
121
- constructor(options) {
122
- super(prepareWebMapOptions(options));
123
- this.emitter = new events.EventEmitter();
124
- this._ngwLayers = {};
125
- this._promises = {
188
+ var NgwMap = /** @class */ (function (_super) {
189
+ __extends(NgwMap, _super);
190
+ function NgwMap(options) {
191
+ var _this = _super.call(this, prepareWebMapOptions(options)) || this;
192
+ _this.emitter = new events.EventEmitter();
193
+ _this._ngwLayers = {};
194
+ _this._promises = {
126
195
  select: [],
127
196
  identify: [],
128
197
  };
129
198
  if (options.connector) {
130
- this.connector = options.connector;
199
+ _this.connector = options.connector;
131
200
  }
132
- this._createWebMap().then(() => {
133
- const container = this.getContainer();
201
+ _this._createWebMap().then(function () {
202
+ var container = _this.getContainer();
134
203
  if (container) {
135
204
  container.classList.add('ngw-map-container');
136
205
  }
137
- if (this.options.whitlabel) {
138
- this._whiteLabel();
206
+ if (_this.options.whitlabel) {
207
+ _this._whiteLabel();
139
208
  }
140
209
  });
210
+ return _this;
141
211
  }
142
212
  /**
143
213
  * Organized addition to the map design and controls elements,
@@ -153,10 +223,18 @@ class NgwMap extends webmap.WebMap {
153
223
  * ngwMap.addControl('ZOOM', 'top-right')
154
224
  * ```
155
225
  */
156
- async addControl(controlDef, position, options) {
157
- await this.onLoad('controls:create');
158
- return super.addControl(controlDef, position, options);
159
- }
226
+ NgwMap.prototype.addControl = function (controlDef, position, options) {
227
+ return __awaiter(this, void 0, void 0, function () {
228
+ return __generator(this, function (_a) {
229
+ switch (_a.label) {
230
+ case 0: return [4 /*yield*/, this.onLoad('controls:create')];
231
+ case 1:
232
+ _a.sent();
233
+ return [2 /*return*/, _super.prototype.addControl.call(this, controlDef, position, options)];
234
+ }
235
+ });
236
+ });
237
+ };
160
238
  /**
161
239
  * Add any (style, vector, webmap) NGW layer by resource definition.
162
240
  * @param options - set layer identification parameters and render method.
@@ -173,61 +251,68 @@ class NgwMap extends webmap.WebMap {
173
251
  * });
174
252
  * ```
175
253
  */
176
- async addNgwLayer(options) {
177
- await this.onMapLoad();
178
- // @ts-ignore for backward compatibility
179
- const { keyname, resourceId } = options;
180
- if (keyname || resourceId !== undefined) {
181
- utils.deprecatedWarn('set `resource` options instead of `keyname` or `resourceId`');
182
- }
183
- const resource = options.resource;
184
- if (!keyname && !resourceId && !resource) {
185
- throw new Error('resource, resourceId or keyname is required parameter to add NGW layer');
186
- }
187
- if (utils.defined(this.options.baseUrl)) {
188
- try {
189
- if (utils.defined(this.options.setViewDelay)) {
190
- options.adapterOptions = options.adapterOptions || {};
191
- if (!utils.defined(options.adapterOptions.setViewDelay)) {
192
- options.adapterOptions.setViewDelay = this.options.setViewDelay;
193
- }
194
- }
195
- const adapter = ngwKit.createNgwLayerAdapter(options, this, this.connector);
196
- const adapterOpts = {
197
- visibility: true,
198
- // TODO: do not merge options, use only `adapterOptions`
199
- ...options,
200
- ...options.adapterOptions,
201
- };
202
- const layer = (await this.addLayer(adapter, adapterOpts));
203
- const id = layer && this.getLayerId(layer);
204
- if (layer && id) {
205
- this._ngwLayers[id] = { layer, resourceId: layer.resourceId };
206
- layer.options.name =
207
- layer.options.name ||
208
- (layer.item && layer.item.resource.display_name);
209
- if (layer.options.baselayer) {
210
- const visibleLayerBaseLayer = this.getActiveBaseLayer();
211
- if (visibleLayerBaseLayer) {
212
- return layer;
254
+ NgwMap.prototype.addNgwLayer = function (options) {
255
+ return __awaiter(this, void 0, void 0, function () {
256
+ var keyname, resourceId, resource, adapter, adapterOpts, layer, id, visibleLayerBaseLayer, er_1, resId;
257
+ return __generator(this, function (_a) {
258
+ switch (_a.label) {
259
+ case 0: return [4 /*yield*/, this.onMapLoad()];
260
+ case 1:
261
+ _a.sent();
262
+ keyname = options.keyname, resourceId = options.resourceId;
263
+ if (keyname || resourceId !== undefined) {
264
+ utils.deprecatedWarn('set `resource` options instead of `keyname` or `resourceId`');
213
265
  }
214
- }
266
+ resource = options.resource;
267
+ if (!keyname && !resourceId && !resource) {
268
+ throw new Error('resource, resourceId or keyname is required parameter to add NGW layer');
269
+ }
270
+ if (!utils.defined(this.options.baseUrl)) return [3 /*break*/, 5];
271
+ _a.label = 2;
272
+ case 2:
273
+ _a.trys.push([2, 4, , 5]);
274
+ if (utils.defined(this.options.setViewDelay)) {
275
+ options.adapterOptions = options.adapterOptions || {};
276
+ if (!utils.defined(options.adapterOptions.setViewDelay)) {
277
+ options.adapterOptions.setViewDelay = this.options.setViewDelay;
278
+ }
279
+ }
280
+ adapter = ngwKit.createNgwLayerAdapter(options, this, this.connector);
281
+ adapterOpts = __assign(__assign({ visibility: true }, options), options.adapterOptions);
282
+ return [4 /*yield*/, this.addLayer(adapter, adapterOpts)];
283
+ case 3:
284
+ layer = (_a.sent());
285
+ id = layer && this.getLayerId(layer);
286
+ if (layer && id) {
287
+ this._ngwLayers[id] = { layer: layer, resourceId: layer.resourceId };
288
+ layer.options.name =
289
+ layer.options.name ||
290
+ (layer.item && layer.item.resource.display_name);
291
+ if (layer.options.baselayer) {
292
+ visibleLayerBaseLayer = this.getActiveBaseLayer();
293
+ if (visibleLayerBaseLayer) {
294
+ return [2 /*return*/, layer];
295
+ }
296
+ }
297
+ }
298
+ return [2 /*return*/, layer];
299
+ case 4:
300
+ er_1 = _a.sent();
301
+ resId = utils.isObject(resource) && 'id' in resource
302
+ ? resource.id
303
+ : keyname || resourceId || resource;
304
+ console.error("Can't add NGW layer ".concat(resId, "."), er_1);
305
+ return [3 /*break*/, 5];
306
+ case 5: return [2 /*return*/];
215
307
  }
216
- return layer;
217
- }
218
- catch (er) {
219
- const resId = utils.isObject(resource) && 'id' in resource
220
- ? resource.id
221
- : keyname || resourceId || resource;
222
- console.error(`Can't add NGW layer ${resId}.`, er);
223
- }
224
- }
225
- }
308
+ });
309
+ });
310
+ };
226
311
  /**
227
312
  * Pans and zooms the map to the initial position specified in the options
228
313
  */
229
- fit() {
230
- const { center, zoom, bounds } = this.options;
314
+ NgwMap.prototype.fit = function () {
315
+ var _a = this.options, center = _a.center, zoom = _a.zoom, bounds = _a.bounds;
231
316
  if (center) {
232
317
  this.setCenter(center);
233
318
  if (zoom) {
@@ -237,46 +322,35 @@ class NgwMap extends webmap.WebMap {
237
322
  else if (bounds) {
238
323
  this.fitBounds(bounds);
239
324
  }
240
- }
241
- fetchNgwLayerItem(options) {
242
- return ngwKit.fetchNgwLayerItem({
243
- connector: this.connector,
244
- ...options,
245
- });
246
- }
247
- fetchNgwLayerItems(options) {
248
- return ngwKit.fetchNgwLayerItems({
249
- connector: this.connector,
250
- ...options,
251
- });
252
- }
253
- fetchNgwLayerFeature(options) {
254
- return ngwKit.fetchNgwLayerFeature({
255
- connector: this.connector,
256
- ...options,
257
- });
258
- }
259
- fetchNgwLayerFeatures(options) {
260
- return ngwKit.fetchNgwLayerFeatureCollection({
261
- connector: this.connector,
262
- ...options,
263
- });
264
- }
265
- fetchIdentifyItem(identify, requestOptions) {
266
- const promise = ngwKit.fetchIdentifyItem({
267
- identify,
325
+ };
326
+ NgwMap.prototype.fetchNgwLayerItem = function (options) {
327
+ return ngwKit.fetchNgwLayerItem(__assign({ connector: this.connector }, options));
328
+ };
329
+ NgwMap.prototype.fetchNgwLayerItems = function (options) {
330
+ return ngwKit.fetchNgwLayerItems(__assign({ connector: this.connector }, options));
331
+ };
332
+ NgwMap.prototype.fetchNgwLayerFeature = function (options) {
333
+ return ngwKit.fetchNgwLayerFeature(__assign({ connector: this.connector }, options));
334
+ };
335
+ NgwMap.prototype.fetchNgwLayerFeatures = function (options) {
336
+ return ngwKit.fetchNgwLayerFeatureCollection(__assign({ connector: this.connector }, options));
337
+ };
338
+ NgwMap.prototype.fetchIdentifyItem = function (identify, requestOptions) {
339
+ var promise = ngwKit.fetchIdentifyItem({
340
+ identify: identify,
268
341
  connector: this.connector,
269
- requestOptions,
342
+ requestOptions: requestOptions,
270
343
  // multiple,
271
344
  });
272
345
  this._addPromise('identify', promise);
273
346
  return promise;
274
- }
275
- fetchIdentifyGeoJson(identify, multiple = false) {
276
- const promise = ngwKit.fetchIdentifyGeoJson({
277
- identify,
347
+ };
348
+ NgwMap.prototype.fetchIdentifyGeoJson = function (identify, multiple) {
349
+ if (multiple === void 0) { multiple = false; }
350
+ var promise = ngwKit.fetchIdentifyGeoJson({
351
+ identify: identify,
278
352
  connector: this.connector,
279
- multiple,
353
+ multiple: multiple,
280
354
  });
281
355
  if (promise && 'then' in promise) {
282
356
  this._addPromise('identify', promise);
@@ -285,40 +359,71 @@ class NgwMap extends webmap.WebMap {
285
359
  else {
286
360
  return CancelablePromise__default.resolve(promise);
287
361
  }
288
- }
362
+ };
289
363
  /**
290
364
  * @deprecated use {@link fetchIdentifyGeoJson} instead
291
365
  */
292
- getIdentifyGeoJson(identify, multiple = false) {
366
+ NgwMap.prototype.getIdentifyGeoJson = function (identify, multiple) {
367
+ if (multiple === void 0) { multiple = false; }
293
368
  return this.fetchIdentifyGeoJson(identify, multiple);
294
- }
295
- async getNgwLayers() {
296
- await this.onLoad();
297
- return this._ngwLayers;
298
- }
299
- async getNgwLayerByResourceId(id) {
300
- for (const n in this._ngwLayers) {
301
- const mem = this._ngwLayers[n];
302
- if (mem.resourceId === id) {
303
- return mem && mem.layer;
304
- }
305
- else if (mem.layer.getIdentificationIds) {
306
- const ids = await mem.layer.getIdentificationIds();
307
- if (ids && ids.some((x) => x === id)) {
308
- return mem.layer;
369
+ };
370
+ NgwMap.prototype.getNgwLayers = function () {
371
+ return __awaiter(this, void 0, void 0, function () {
372
+ return __generator(this, function (_a) {
373
+ switch (_a.label) {
374
+ case 0: return [4 /*yield*/, this.onLoad()];
375
+ case 1:
376
+ _a.sent();
377
+ return [2 /*return*/, this._ngwLayers];
309
378
  }
310
- }
311
- if (mem.layer.getDependLayers) {
312
- const dependLayers = mem.layer.getDependLayers();
313
- const dependFit = dependLayers.find((x) => {
314
- return x.item && x.item.parentId === id;
315
- });
316
- if (dependFit) {
317
- return dependFit.layer;
379
+ });
380
+ });
381
+ };
382
+ NgwMap.prototype.getNgwLayerByResourceId = function (id) {
383
+ return __awaiter(this, void 0, void 0, function () {
384
+ var _a, _b, _i, n, mem, ids, dependLayers, dependFit;
385
+ return __generator(this, function (_c) {
386
+ switch (_c.label) {
387
+ case 0:
388
+ _a = [];
389
+ for (_b in this._ngwLayers)
390
+ _a.push(_b);
391
+ _i = 0;
392
+ _c.label = 1;
393
+ case 1:
394
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
395
+ n = _a[_i];
396
+ mem = this._ngwLayers[n];
397
+ if (!(mem.resourceId === id)) return [3 /*break*/, 2];
398
+ return [2 /*return*/, mem && mem.layer];
399
+ case 2:
400
+ if (!mem.layer.getIdentificationIds) return [3 /*break*/, 4];
401
+ return [4 /*yield*/, mem.layer.getIdentificationIds()];
402
+ case 3:
403
+ ids = _c.sent();
404
+ if (ids && ids.some(function (x) { return x === id; })) {
405
+ return [2 /*return*/, mem.layer];
406
+ }
407
+ _c.label = 4;
408
+ case 4:
409
+ if (mem.layer.getDependLayers) {
410
+ dependLayers = mem.layer.getDependLayers();
411
+ dependFit = dependLayers.find(function (x) {
412
+ return x.item && x.item.parentId === id;
413
+ });
414
+ if (dependFit) {
415
+ return [2 /*return*/, dependFit.layer];
416
+ }
417
+ }
418
+ _c.label = 5;
419
+ case 5:
420
+ _i++;
421
+ return [3 /*break*/, 1];
422
+ case 6: return [2 /*return*/];
318
423
  }
319
- }
320
- }
321
- }
424
+ });
425
+ });
426
+ };
322
427
  /**
323
428
  * Move map to layer. If the layer is NGW resource, extent will be received from the server
324
429
  *
@@ -329,131 +434,160 @@ class NgwMap extends webmap.WebMap {
329
434
  * ngwMap.fitLayer('ngw_layer_name');
330
435
  * ```
331
436
  */
332
- async fitLayer(layerDef, options) {
333
- let id;
334
- if (typeof layerDef === 'string' || typeof layerDef === 'number') {
335
- id = String(id);
336
- }
337
- else {
338
- id = layerDef.id;
339
- }
340
- const ngwLayer = id && this._ngwLayers[id];
341
- if (ngwLayer) {
342
- if (ngwLayer.layer.getBounds) {
343
- const bounds = await ngwLayer.layer.getBounds();
344
- if (bounds) {
345
- this.fitBounds(bounds, options);
346
- }
347
- }
348
- else {
349
- let item;
350
- if (ngwLayer.layer.item) {
351
- item = ngwLayer.layer.item;
352
- }
353
- else {
354
- const resourceId = ngwLayer.resourceId;
355
- item = await this.connector.getResource(resourceId);
356
- }
357
- if (item) {
358
- ngwKit.fetchNgwResourceExtent(item, this.connector).then((extent) => {
359
- if (extent) {
360
- this.fitBounds(extent, options);
437
+ NgwMap.prototype.fitLayer = function (layerDef, options) {
438
+ return __awaiter(this, void 0, void 0, function () {
439
+ var id, ngwLayer, bounds, item, resourceId;
440
+ var _this = this;
441
+ return __generator(this, function (_a) {
442
+ switch (_a.label) {
443
+ case 0:
444
+ if (typeof layerDef === 'string' || typeof layerDef === 'number') {
445
+ id = String(id);
446
+ }
447
+ else {
448
+ id = layerDef.id;
449
+ }
450
+ ngwLayer = id && this._ngwLayers[id];
451
+ if (!ngwLayer) return [3 /*break*/, 7];
452
+ if (!ngwLayer.layer.getBounds) return [3 /*break*/, 2];
453
+ return [4 /*yield*/, ngwLayer.layer.getBounds()];
454
+ case 1:
455
+ bounds = _a.sent();
456
+ if (bounds) {
457
+ this.fitBounds(bounds, options);
458
+ }
459
+ return [3 /*break*/, 6];
460
+ case 2:
461
+ item = void 0;
462
+ if (!ngwLayer.layer.item) return [3 /*break*/, 3];
463
+ item = ngwLayer.layer.item;
464
+ return [3 /*break*/, 5];
465
+ case 3:
466
+ resourceId = ngwLayer.resourceId;
467
+ return [4 /*yield*/, this.connector.getResource(resourceId)];
468
+ case 4:
469
+ item = _a.sent();
470
+ _a.label = 5;
471
+ case 5:
472
+ if (item) {
473
+ ngwKit.fetchNgwResourceExtent(item, this.connector).then(function (extent) {
474
+ if (extent) {
475
+ _this.fitBounds(extent, options);
476
+ }
477
+ });
361
478
  }
362
- });
479
+ _a.label = 6;
480
+ case 6: return [3 /*break*/, 8];
481
+ case 7:
482
+ _super.prototype.fitLayer.call(this, layerDef, options);
483
+ _a.label = 8;
484
+ case 8: return [2 /*return*/];
363
485
  }
364
- }
365
- }
366
- else {
367
- super.fitLayer(layerDef, options);
368
- }
369
- }
486
+ });
487
+ });
488
+ };
370
489
  /** @deprecated use {@link NgwMap.fitLayer} instead */
371
- async zoomToLayer(layerDef) {
372
- return this.fitLayer(layerDef);
373
- }
374
- onLoad(event = 'ngw-map:create') {
375
- return super.onLoad(event);
376
- }
377
- removeLayer(layerDef) {
378
- const layer = this.getLayer(layerDef);
490
+ NgwMap.prototype.zoomToLayer = function (layerDef) {
491
+ return __awaiter(this, void 0, void 0, function () {
492
+ return __generator(this, function (_a) {
493
+ return [2 /*return*/, this.fitLayer(layerDef)];
494
+ });
495
+ });
496
+ };
497
+ NgwMap.prototype.onLoad = function (event) {
498
+ if (event === void 0) { event = 'ngw-map:create'; }
499
+ return _super.prototype.onLoad.call(this, event);
500
+ };
501
+ NgwMap.prototype.removeLayer = function (layerDef) {
502
+ var layer = this.getLayer(layerDef);
379
503
  if (layer) {
380
- const layerId = this.getLayerId(layer);
504
+ var layerId = this.getLayerId(layer);
381
505
  if (layerId) {
382
506
  delete this._ngwLayers[layerId];
383
507
  }
384
- super.removeLayer(layer);
508
+ _super.prototype.removeLayer.call(this, layer);
385
509
  }
386
- }
387
- enableSelection() {
510
+ };
511
+ NgwMap.prototype.enableSelection = function () {
512
+ var _this = this;
388
513
  if (!this.$$selectFromNgwRaster) {
389
- this.$$selectFromNgwRaster = (ev) => {
390
- const count = this.emitter.listenerCount('ngw:select');
514
+ this.$$selectFromNgwRaster = function (ev) {
515
+ var count = _this.emitter.listenerCount('ngw:select');
391
516
  if (count) {
392
- this._selectFromNgwRaster(ev);
517
+ _this._selectFromNgwRaster(ev);
393
518
  }
394
519
  };
395
- this.$$selectFromNgwVector = (ev) => {
396
- if (this.emitter.listenerCount('ngw:select')) {
397
- this._selectFromNgwVector(ev);
520
+ this.$$selectFromNgwVector = function (ev) {
521
+ if (_this.emitter.listenerCount('ngw:select')) {
522
+ _this._selectFromNgwVector(ev);
398
523
  }
399
524
  };
400
525
  this.emitter.on('click', this.$$selectFromNgwRaster);
401
526
  this.emitter.on('layer:click', this.$$selectFromNgwVector);
402
527
  }
403
- }
404
- disableSelection() {
528
+ };
529
+ NgwMap.prototype.disableSelection = function () {
405
530
  if (this.$$selectFromNgwRaster) {
406
531
  this.emitter.removeListener('click', this.$$selectFromNgwRaster);
407
532
  this.emitter.removeListener('click', this._selectFromNgwVector);
408
533
  this.$$selectFromNgwRaster = undefined;
409
534
  this.$$selectFromNgwVector = undefined;
410
535
  }
411
- }
536
+ };
412
537
  /**
413
538
  * @deprecated use {@link NgwMap.fetchNgwLayerItem} instead
414
539
  */
415
- getNgwLayerItem(options) {
540
+ NgwMap.prototype.getNgwLayerItem = function (options) {
416
541
  return this.fetchNgwLayerItem(options);
417
- }
542
+ };
418
543
  /**
419
544
  * @deprecated use {@link NgwMap.fetchNgwLayerItems} instead
420
545
  */
421
- getNgwLayerItems(options) {
546
+ NgwMap.prototype.getNgwLayerItems = function (options) {
422
547
  return this.fetchNgwLayerItems(options);
423
- }
548
+ };
424
549
  /**
425
550
  * @deprecated use {@link NgwMap.fetchNgwLayerFeature} instead
426
551
  */
427
- getNgwLayerFeature(options) {
552
+ NgwMap.prototype.getNgwLayerFeature = function (options) {
428
553
  return this.fetchNgwLayerFeature(options);
429
- }
554
+ };
430
555
  /**
431
556
  * @deprecated use {@link NgwMap.fetchNgwLayerFeatures} instead
432
557
  */
433
- getNgwLayerFeatures(options) {
558
+ NgwMap.prototype.getNgwLayerFeatures = function (options) {
434
559
  return this.fetchNgwLayerFeatures(options);
435
- }
560
+ };
436
561
  /** @deprecated use {@link NgwMap.cancelPromises} instead */
437
- cancelPromise(...args) {
438
- this.cancelPromises(...args);
439
- }
440
- cancelPromises(...args) {
562
+ NgwMap.prototype.cancelPromise = function () {
563
+ var args = [];
564
+ for (var _i = 0; _i < arguments.length; _i++) {
565
+ args[_i] = arguments[_i];
566
+ }
567
+ this.cancelPromises.apply(this, args);
568
+ };
569
+ NgwMap.prototype.cancelPromises = function () {
570
+ var _this = this;
571
+ var args = [];
572
+ for (var _i = 0; _i < arguments.length; _i++) {
573
+ args[_i] = arguments[_i];
574
+ }
441
575
  if (!args.length) {
442
576
  args = Object.keys(this._promises);
443
577
  }
444
- args.forEach((name) => {
445
- const group = this._promises[name];
578
+ args.forEach(function (name) {
579
+ var group = _this._promises[name];
446
580
  if (group) {
447
- group.forEach((x) => x.cancel());
448
- this._promises[name] = [];
581
+ group.forEach(function (x) { return x.cancel(); });
582
+ _this._promises[name] = [];
449
583
  }
450
584
  });
451
- }
452
- _addPromise(groupName, promise) {
453
- const group = this._promises[groupName];
585
+ };
586
+ NgwMap.prototype._addPromise = function (groupName, promise) {
587
+ var group = this._promises[groupName];
454
588
  if (group && group.indexOf(promise) === -1) {
455
- const removeFromGroup = () => {
456
- const index = group.indexOf(promise);
589
+ var removeFromGroup = function () {
590
+ var index = group.indexOf(promise);
457
591
  if (index !== -1) {
458
592
  group.splice(index, 1);
459
593
  }
@@ -462,55 +596,78 @@ class NgwMap extends webmap.WebMap {
462
596
  promise.catch(removeFromGroup);
463
597
  group.push(promise);
464
598
  }
465
- }
466
- _isFitFromResource() {
467
- const params = this._initMapState;
599
+ };
600
+ NgwMap.prototype._isFitFromResource = function () {
601
+ var params = this._initMapState;
468
602
  if (params.zoom && params.center) {
469
603
  return false;
470
604
  }
471
605
  return true;
472
- }
473
- async _createWebMap() {
474
- await this.create();
475
- if (this.options.qmsId) {
476
- this._addQmsBaseLayer();
477
- }
478
- if (this.options.osm) {
479
- this._addOsmBaseLayer();
480
- }
481
- const resources = [];
482
- const layerFitAllowed = this._isFitFromResource();
483
- if (this.options.webmapId) {
484
- appendNgwResources(resources, this.options.webmapId, {
485
- fit: layerFitAllowed,
486
- });
487
- }
488
- if (this.options.resources && Array.isArray(this.options.resources)) {
489
- for (const x of this.options.resources) {
490
- const overwriteOptions = {};
491
- if (!layerFitAllowed) {
492
- overwriteOptions.fit = false;
606
+ };
607
+ NgwMap.prototype._createWebMap = function () {
608
+ return __awaiter(this, void 0, void 0, function () {
609
+ var resources, layerFitAllowed, _i, _a, x, overwriteOptions, _b, resources_1, r, er_2;
610
+ return __generator(this, function (_c) {
611
+ switch (_c.label) {
612
+ case 0: return [4 /*yield*/, this.create()];
613
+ case 1:
614
+ _c.sent();
615
+ if (this.options.qmsId) {
616
+ this._addQmsBaseLayer();
617
+ }
618
+ if (this.options.osm) {
619
+ this._addOsmBaseLayer();
620
+ }
621
+ resources = [];
622
+ layerFitAllowed = this._isFitFromResource();
623
+ if (this.options.webmapId) {
624
+ appendNgwResources(resources, this.options.webmapId, {
625
+ fit: layerFitAllowed,
626
+ });
627
+ }
628
+ if (this.options.resources && Array.isArray(this.options.resources)) {
629
+ for (_i = 0, _a = this.options.resources; _i < _a.length; _i++) {
630
+ x = _a[_i];
631
+ overwriteOptions = {};
632
+ if (!layerFitAllowed) {
633
+ overwriteOptions.fit = false;
634
+ }
635
+ appendNgwResources(resources, x, {}, overwriteOptions);
636
+ }
637
+ }
638
+ _b = 0, resources_1 = resources;
639
+ _c.label = 2;
640
+ case 2:
641
+ if (!(_b < resources_1.length)) return [3 /*break*/, 7];
642
+ r = resources_1[_b];
643
+ _c.label = 3;
644
+ case 3:
645
+ _c.trys.push([3, 5, , 6]);
646
+ return [4 /*yield*/, this.addNgwLayer(r)];
647
+ case 4:
648
+ _c.sent();
649
+ return [3 /*break*/, 6];
650
+ case 5:
651
+ er_2 = _c.sent();
652
+ console.warn(er_2);
653
+ return [3 /*break*/, 6];
654
+ case 6:
655
+ _b++;
656
+ return [3 /*break*/, 2];
657
+ case 7:
658
+ this._emitStatusEvent('ngw-map:create', this);
659
+ this.enableSelection();
660
+ return [2 /*return*/];
493
661
  }
494
- appendNgwResources(resources, x, {}, overwriteOptions);
495
- }
496
- }
497
- for (const r of resources) {
498
- try {
499
- await this.addNgwLayer(r);
500
- }
501
- catch (er) {
502
- console.warn(er);
503
- }
504
- }
505
- this._emitStatusEvent('ngw-map:create', this);
506
- this.enableSelection();
507
- }
508
- _addOsmBaseLayer() {
662
+ });
663
+ });
664
+ };
665
+ NgwMap.prototype._addOsmBaseLayer = function () {
509
666
  this.addBaseLayer('OSM');
510
- }
511
- _addQmsBaseLayer() {
512
- let qmsId;
513
- let qmsLayerName;
667
+ };
668
+ NgwMap.prototype._addQmsBaseLayer = function () {
669
+ var qmsId;
670
+ var qmsLayerName;
514
671
  if (Array.isArray(this.options.qmsId)) {
515
672
  qmsId = this.options.qmsId[0];
516
673
  qmsLayerName = this.options.qmsId[1];
@@ -518,140 +675,159 @@ class NgwMap extends webmap.WebMap {
518
675
  else {
519
676
  qmsId = Number(this.options.qmsId);
520
677
  }
521
- const qmsLayerOptions = {
522
- qmsId,
678
+ var qmsLayerOptions = {
679
+ qmsId: qmsId,
523
680
  };
524
681
  if (qmsLayerName) {
525
682
  qmsLayerOptions.id = qmsLayerName;
526
683
  }
527
684
  this.addBaseLayer('QMS', qmsLayerOptions);
528
- }
529
- _selectFromNgwVector(ev) {
530
- const layer = ev.layer;
685
+ };
686
+ NgwMap.prototype._selectFromNgwVector = function (ev) {
687
+ var _a;
688
+ var layer = ev.layer;
531
689
  // item property means layer is NgwResource
532
- const id = layer.item && layer.item.resource.id;
533
- const feature = ev.feature;
690
+ var id = layer.item && layer.item.resource.id;
691
+ var feature = ev.feature;
534
692
  if (id !== undefined && feature) {
535
- const featureId = feature.id;
693
+ var featureId = feature.id;
536
694
  if (featureId) {
537
- const identifyFeature = {
695
+ var identifyFeature = {
538
696
  id: Number(featureId),
539
697
  fields: feature.properties || {},
540
- label: `#${id}`,
698
+ label: "#".concat(id),
541
699
  layerId: Number(id),
542
700
  parent: '',
543
701
  geom: feature.geometry,
544
702
  };
545
- const items = {
703
+ var items = {
546
704
  featureCount: 1,
547
705
  features: [identifyFeature],
548
706
  };
549
- const identify = {
550
- featureCount: 1,
551
- [id]: items,
552
- };
553
- this._emitStatusEvent('ngw:select', this._prepareToIdentify({
554
- ...identify,
555
- resources: [id],
556
- sourceType: 'vector',
557
- }));
707
+ var identify = (_a = {
708
+ featureCount: 1
709
+ },
710
+ _a[id] = items,
711
+ _a);
712
+ this._emitStatusEvent('ngw:select', this._prepareToIdentify(__assign(__assign({}, identify), { resources: [id], sourceType: 'vector' })));
558
713
  return identify;
559
714
  }
560
715
  }
561
- }
562
- async _selectFromNgwRaster(ev) {
563
- this._emitStatusEvent('ngw:preselect');
564
- const promises = [];
565
- const layers = Object.values(this._ngwLayers);
566
- layers.sort((a, b) => {
567
- if (a.layer.order && b.layer.order) {
568
- return b.layer.order - a.layer.order;
569
- }
570
- return 1;
571
- });
572
- layers.forEach((l) => {
573
- const layer = l.layer;
574
- const identFunc = typeof layer.getIdentificationIds === 'function'
575
- ? layer.getIdentificationIds
576
- : false;
577
- if (identFunc && layer.options.selectable && this.isLayerVisible(layer)) {
578
- promises.push(identFunc.call(layer));
579
- }
580
- });
581
- const getIdsPromise = Promise.all(promises);
582
- const getIds = await getIdsPromise;
583
- const ids = [];
584
- getIds.forEach((x) => {
585
- if (x) {
586
- x.forEach((y) => ids.push(y));
587
- }
588
- });
589
- if (!ids.length) {
590
- this._emitStatusEvent('ngw:select', null);
591
- return;
592
- }
593
- const pixelRadius = this.options.pixelRadius || 10;
594
- const center = this.getCenter();
595
- let zoom = this.getZoom();
596
- zoom = zoom !== undefined ? zoom : 20;
597
- if (!center || !zoom) {
598
- this._emitStatusEvent('ngw:select', null);
599
- return;
600
- }
601
- const radius = getIdentifyRadius(center, zoom, pixelRadius);
602
- const selectPromise = ngwKit.sendIdentifyRequest(ev, {
603
- layers: ids,
604
- connector: this.connector,
605
- radius,
606
- }).then((resp) => {
607
- this._emitStatusEvent('ngw:select', this._prepareToIdentify({
608
- ...resp,
609
- resources: ids,
610
- sourceType: 'raster',
611
- event: ev,
612
- }));
613
- return resp;
716
+ };
717
+ NgwMap.prototype._selectFromNgwRaster = function (ev) {
718
+ return __awaiter(this, void 0, void 0, function () {
719
+ var promises, layers, getIdsPromise, getIds, ids, pixelRadius, center, zoom, radius, selectPromise;
720
+ var _this = this;
721
+ return __generator(this, function (_a) {
722
+ switch (_a.label) {
723
+ case 0:
724
+ this._emitStatusEvent('ngw:preselect');
725
+ promises = [];
726
+ layers = Object.values(this._ngwLayers);
727
+ layers.sort(function (a, b) {
728
+ if (a.layer.order && b.layer.order) {
729
+ return b.layer.order - a.layer.order;
730
+ }
731
+ return 1;
732
+ });
733
+ layers.forEach(function (l) {
734
+ var layer = l.layer;
735
+ var identFunc = typeof layer.getIdentificationIds === 'function'
736
+ ? layer.getIdentificationIds
737
+ : false;
738
+ if (identFunc && layer.options.selectable && _this.isLayerVisible(layer)) {
739
+ promises.push(identFunc.call(layer));
740
+ }
741
+ });
742
+ getIdsPromise = Promise.all(promises);
743
+ return [4 /*yield*/, getIdsPromise];
744
+ case 1:
745
+ getIds = _a.sent();
746
+ ids = [];
747
+ getIds.forEach(function (x) {
748
+ if (x) {
749
+ x.forEach(function (y) { return ids.push(y); });
750
+ }
751
+ });
752
+ if (!ids.length) {
753
+ this._emitStatusEvent('ngw:select', null);
754
+ return [2 /*return*/];
755
+ }
756
+ pixelRadius = this.options.pixelRadius || 10;
757
+ center = this.getCenter();
758
+ zoom = this.getZoom();
759
+ zoom = zoom !== undefined ? zoom : 20;
760
+ if (!center || !zoom) {
761
+ this._emitStatusEvent('ngw:select', null);
762
+ return [2 /*return*/];
763
+ }
764
+ radius = getIdentifyRadius(center, zoom, pixelRadius);
765
+ selectPromise = ngwKit.sendIdentifyRequest(ev, {
766
+ layers: ids,
767
+ connector: this.connector,
768
+ radius: radius,
769
+ }).then(function (resp) {
770
+ _this._emitStatusEvent('ngw:select', _this._prepareToIdentify(__assign(__assign({}, resp), { resources: ids, sourceType: 'raster', event: ev })));
771
+ return resp;
772
+ });
773
+ this._addPromise('select', selectPromise);
774
+ return [2 /*return*/, selectPromise];
775
+ }
776
+ });
614
777
  });
615
- this._addPromise('select', selectPromise);
616
- return selectPromise;
617
- }
618
- _prepareToIdentify(identify) {
619
- const getIdentifyItems_ = () => {
620
- return ngwKit.getIdentifyItems(identify, true).map((x) => {
778
+ };
779
+ NgwMap.prototype._prepareToIdentify = function (identify) {
780
+ var _this = this;
781
+ var getIdentifyItems_ = function () {
782
+ return ngwKit.getIdentifyItems(identify, true).map(function (x) {
621
783
  return ngwKit.createIdentifyItem({
622
784
  feature: x.feature,
623
- connector: this.connector,
785
+ connector: _this.connector,
624
786
  });
625
787
  });
626
788
  };
627
- return {
628
- ...identify,
629
- getIdentifyItems: getIdentifyItems_,
630
- };
631
- }
632
- async _whiteLabel() {
633
- const container = this.getContainer();
634
- if (container) {
635
- const logo = await ngwKit.getCompanyLogo(this.connector, this.options.companyLogoOptions);
636
- if (logo) {
637
- container.appendChild(logo);
638
- }
639
- }
640
- }
641
- }
642
- NgwMap.getIcon = icons.getIcon;
789
+ return __assign(__assign({}, identify), { getIdentifyItems: getIdentifyItems_ });
790
+ };
791
+ NgwMap.prototype._whiteLabel = function () {
792
+ return __awaiter(this, void 0, void 0, function () {
793
+ var container, logo;
794
+ return __generator(this, function (_a) {
795
+ switch (_a.label) {
796
+ case 0:
797
+ container = this.getContainer();
798
+ if (!container) return [3 /*break*/, 2];
799
+ return [4 /*yield*/, ngwKit.getCompanyLogo(this.connector, this.options.companyLogoOptions)];
800
+ case 1:
801
+ logo = _a.sent();
802
+ if (logo) {
803
+ container.appendChild(logo);
804
+ }
805
+ _a.label = 2;
806
+ case 2: return [2 /*return*/];
807
+ }
808
+ });
809
+ });
810
+ };
811
+ NgwMap.getIcon = icons.getIcon;
812
+ return NgwMap;
813
+ }(webmap.WebMap));
643
814
 
644
815
  /**
645
816
  * @module ngw-map
646
817
  */
647
- async function createNgwMap(options) {
648
- const ngwMap = new NgwMap(options);
649
- return ngwMap.onLoad();
818
+ function createNgwMap(options) {
819
+ return __awaiter(this, void 0, void 0, function () {
820
+ var ngwMap;
821
+ return __generator(this, function (_a) {
822
+ ngwMap = new NgwMap(options);
823
+ return [2 /*return*/, ngwMap.onLoad()];
824
+ });
825
+ });
650
826
  }
651
827
 
652
828
  exports.NgwMap = NgwMap;
653
829
  exports.createNgwMap = createNgwMap;
654
830
  for (var k in webmap) {
655
- if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = webmap[k];
831
+ if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = webmap[k];
656
832
  }
657
833
  //# sourceMappingURL=ngw-map.cjs.js.map