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