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