@tic-nova/ngx-mapbox-gl 14.0.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.
Files changed (80) hide show
  1. package/README.md +3 -0
  2. package/esm2022/index.js +32 -0
  3. package/esm2022/index.js.map +1 -0
  4. package/esm2022/lib/control/attribution-control.directive.js +39 -0
  5. package/esm2022/lib/control/attribution-control.directive.js.map +1 -0
  6. package/esm2022/lib/control/control.component.js +62 -0
  7. package/esm2022/lib/control/control.component.js.map +1 -0
  8. package/esm2022/lib/control/fullscreen-control.directive.js +39 -0
  9. package/esm2022/lib/control/fullscreen-control.directive.js.map +1 -0
  10. package/esm2022/lib/control/geolocate-control.directive.js +52 -0
  11. package/esm2022/lib/control/geolocate-control.directive.js.map +1 -0
  12. package/esm2022/lib/control/navigation-control.directive.js +39 -0
  13. package/esm2022/lib/control/navigation-control.directive.js.map +1 -0
  14. package/esm2022/lib/control/scale-control.directive.js +45 -0
  15. package/esm2022/lib/control/scale-control.directive.js.map +1 -0
  16. package/esm2022/lib/draggable/draggable.directive.js +121 -0
  17. package/esm2022/lib/draggable/draggable.directive.js.map +1 -0
  18. package/esm2022/lib/image/image.component.js +79 -0
  19. package/esm2022/lib/image/image.component.js.map +1 -0
  20. package/esm2022/lib/layer/layer.component.js +139 -0
  21. package/esm2022/lib/layer/layer.component.js.map +1 -0
  22. package/esm2022/lib/map/map.component.js +381 -0
  23. package/esm2022/lib/map/map.component.js.map +1 -0
  24. package/esm2022/lib/map/map.service.js +725 -0
  25. package/esm2022/lib/map/map.service.js.map +1 -0
  26. package/esm2022/lib/map/map.types.js +30 -0
  27. package/esm2022/lib/map/map.types.js.map +1 -0
  28. package/esm2022/lib/marker/marker.component.js +114 -0
  29. package/esm2022/lib/marker/marker.component.js.map +1 -0
  30. package/esm2022/lib/markers-for-clusters/markers-for-clusters.component.js +168 -0
  31. package/esm2022/lib/markers-for-clusters/markers-for-clusters.component.js.map +1 -0
  32. package/esm2022/lib/popup/popup.component.js +124 -0
  33. package/esm2022/lib/popup/popup.component.js.map +1 -0
  34. package/esm2022/lib/provide-mapbox-gl.js +8 -0
  35. package/esm2022/lib/provide-mapbox-gl.js.map +1 -0
  36. package/esm2022/lib/source/canvas-source.component.js +74 -0
  37. package/esm2022/lib/source/canvas-source.component.js.map +1 -0
  38. package/esm2022/lib/source/geojson/feature.component.js +42 -0
  39. package/esm2022/lib/source/geojson/feature.component.js.map +1 -0
  40. package/esm2022/lib/source/geojson/geojson-source.component.js +204 -0
  41. package/esm2022/lib/source/geojson/geojson-source.component.js.map +1 -0
  42. package/esm2022/lib/source/image-source.component.js +58 -0
  43. package/esm2022/lib/source/image-source.component.js.map +1 -0
  44. package/esm2022/lib/source/raster-dem-source.component.js +91 -0
  45. package/esm2022/lib/source/raster-dem-source.component.js.map +1 -0
  46. package/esm2022/lib/source/raster-source.component.js +85 -0
  47. package/esm2022/lib/source/raster-source.component.js.map +1 -0
  48. package/esm2022/lib/source/vector-source.component.js +99 -0
  49. package/esm2022/lib/source/vector-source.component.js.map +1 -0
  50. package/esm2022/lib/source/video-source.component.js +80 -0
  51. package/esm2022/lib/source/video-source.component.js.map +1 -0
  52. package/esm2022/ngx-mapbox-gl.js +5 -0
  53. package/esm2022/ngx-mapbox-gl.js.map +1 -0
  54. package/index.d.ts +24 -0
  55. package/lib/control/attribution-control.directive.d.ts +11 -0
  56. package/lib/control/control.component.d.ts +21 -0
  57. package/lib/control/fullscreen-control.directive.d.ts +11 -0
  58. package/lib/control/geolocate-control.directive.d.ts +15 -0
  59. package/lib/control/navigation-control.directive.d.ts +11 -0
  60. package/lib/control/scale-control.directive.d.ts +12 -0
  61. package/lib/draggable/draggable.directive.d.ts +20 -0
  62. package/lib/image/image.component.d.ts +34 -0
  63. package/lib/layer/layer.component.d.ts +422 -0
  64. package/lib/map/map.component.d.ts +185 -0
  65. package/lib/map/map.service.d.ts +123 -0
  66. package/lib/map/map.types.d.ts +72 -0
  67. package/lib/marker/marker.component.d.ts +31 -0
  68. package/lib/markers-for-clusters/markers-for-clusters.component.d.ts +28 -0
  69. package/lib/popup/popup.component.d.ts +33 -0
  70. package/lib/provide-mapbox-gl.d.ts +6 -0
  71. package/lib/source/canvas-source.component.d.ts +23 -0
  72. package/lib/source/geojson/feature.component.d.ts +16 -0
  73. package/lib/source/geojson/geojson-source.component.d.ts +63 -0
  74. package/lib/source/image-source.component.d.ts +22 -0
  75. package/lib/source/raster-dem-source.component.d.ts +23 -0
  76. package/lib/source/raster-source.component.d.ts +23 -0
  77. package/lib/source/vector-source.component.d.ts +24 -0
  78. package/lib/source/video-source.component.d.ts +24 -0
  79. package/ngx-mapbox-gl.d.ts +5 -0
  80. package/package.json +44 -0
@@ -0,0 +1,725 @@
1
+ import { Injectable, InjectionToken, Injector, NgZone, afterEveryRender, inject, } from '@angular/core';
2
+ import { Map, Marker, Popup, } from 'mapbox-gl';
3
+ import { AsyncSubject, Subscription } from 'rxjs';
4
+ import * as i0 from "@angular/core";
5
+ export const MAPBOX_API_KEY = new InjectionToken('MapboxApiKey');
6
+ export class MapService {
7
+ zone = inject(NgZone);
8
+ MAPBOX_API_KEY = inject(MAPBOX_API_KEY, {
9
+ optional: true,
10
+ });
11
+ injector = inject(Injector);
12
+ mapInstance;
13
+ mapCreated$;
14
+ mapLoaded$;
15
+ mapEvents;
16
+ mapCreated = new AsyncSubject();
17
+ mapLoaded = new AsyncSubject();
18
+ markersToRemove = [];
19
+ popupsToRemove = [];
20
+ imageIdsToRemove = [];
21
+ subscription = new Subscription();
22
+ constructor() {
23
+ this.mapCreated$ = this.mapCreated.asObservable();
24
+ this.mapLoaded$ = this.mapLoaded.asObservable();
25
+ }
26
+ setup(options) {
27
+ const mapOptions = {
28
+ ...options.mapOptions,
29
+ bearing: Array.isArray(options.mapOptions.bearing)
30
+ ? options.mapOptions.bearing[0]
31
+ : options.mapOptions.bearing,
32
+ zoom: Array.isArray(options.mapOptions.zoom)
33
+ ? options.mapOptions.zoom[0]
34
+ : options.mapOptions.zoom,
35
+ pitch: Array.isArray(options.mapOptions.pitch)
36
+ ? options.mapOptions.pitch[0]
37
+ : options.mapOptions.pitch,
38
+ accessToken: options.accessToken || this.MAPBOX_API_KEY || '',
39
+ };
40
+ this.createMap(mapOptions);
41
+ this.hookEvents(options.mapEvents);
42
+ this.mapEvents = options.mapEvents;
43
+ this.mapCreated.next(undefined);
44
+ this.mapCreated.complete();
45
+ // Intentionally emit mapCreate after internal mapCreated event
46
+ if (options.mapEvents.mapCreate.observed) {
47
+ this.zone.run(() => {
48
+ options.mapEvents.mapCreate.emit(this.mapInstance);
49
+ });
50
+ }
51
+ }
52
+ destroyMap() {
53
+ if (this.mapInstance) {
54
+ this.subscription.unsubscribe();
55
+ this.mapInstance.remove();
56
+ }
57
+ }
58
+ updateProjection(projection) {
59
+ return this.zone.runOutsideAngular(() => {
60
+ this.mapInstance.setProjection(projection);
61
+ });
62
+ }
63
+ updateMinZoom(minZoom) {
64
+ return this.zone.runOutsideAngular(() => {
65
+ this.mapInstance.setMinZoom(minZoom);
66
+ });
67
+ }
68
+ updateMaxZoom(maxZoom) {
69
+ return this.zone.runOutsideAngular(() => {
70
+ this.mapInstance.setMaxZoom(maxZoom);
71
+ });
72
+ }
73
+ updateMinPitch(minPitch) {
74
+ return this.zone.runOutsideAngular(() => {
75
+ this.mapInstance.setMinPitch(minPitch);
76
+ });
77
+ }
78
+ updateMaxPitch(maxPitch) {
79
+ return this.zone.runOutsideAngular(() => {
80
+ this.mapInstance.setMaxPitch(maxPitch);
81
+ });
82
+ }
83
+ updateRenderWorldCopies(status) {
84
+ return this.zone.runOutsideAngular(() => {
85
+ this.mapInstance.setRenderWorldCopies(status);
86
+ });
87
+ }
88
+ updateScrollZoom(status) {
89
+ return this.zone.runOutsideAngular(() => {
90
+ status
91
+ ? this.mapInstance.scrollZoom.enable()
92
+ : this.mapInstance.scrollZoom.disable();
93
+ });
94
+ }
95
+ updateDragRotate(status) {
96
+ return this.zone.runOutsideAngular(() => {
97
+ status
98
+ ? this.mapInstance.dragRotate.enable()
99
+ : this.mapInstance.dragRotate.disable();
100
+ });
101
+ }
102
+ updateTouchPitch(status) {
103
+ return this.zone.runOutsideAngular(() => {
104
+ status
105
+ ? this.mapInstance.touchPitch.enable()
106
+ : this.mapInstance.touchPitch.disable();
107
+ });
108
+ }
109
+ updateTouchZoomRotate(status) {
110
+ return this.zone.runOutsideAngular(() => {
111
+ status
112
+ ? this.mapInstance.touchZoomRotate.enable()
113
+ : this.mapInstance.touchZoomRotate.disable();
114
+ });
115
+ }
116
+ updateDoubleClickZoom(status) {
117
+ return this.zone.runOutsideAngular(() => {
118
+ status
119
+ ? this.mapInstance.doubleClickZoom.enable()
120
+ : this.mapInstance.doubleClickZoom.disable();
121
+ });
122
+ }
123
+ updateKeyboard(status) {
124
+ return this.zone.runOutsideAngular(() => {
125
+ status
126
+ ? this.mapInstance.keyboard.enable()
127
+ : this.mapInstance.keyboard.disable();
128
+ });
129
+ }
130
+ updateDragPan(status) {
131
+ return this.zone.runOutsideAngular(() => {
132
+ status
133
+ ? this.mapInstance.dragPan.enable()
134
+ : this.mapInstance.dragPan.disable();
135
+ });
136
+ }
137
+ updateBoxZoom(status) {
138
+ return this.zone.runOutsideAngular(() => {
139
+ status
140
+ ? this.mapInstance.boxZoom.enable()
141
+ : this.mapInstance.boxZoom.disable();
142
+ });
143
+ }
144
+ updateStyle(style) {
145
+ return this.zone.runOutsideAngular(() => {
146
+ this.mapInstance.setStyle(style);
147
+ });
148
+ }
149
+ updateMaxBounds(maxBounds) {
150
+ return this.zone.runOutsideAngular(() => {
151
+ this.mapInstance.setMaxBounds(maxBounds);
152
+ });
153
+ }
154
+ changeCanvasCursor(cursor) {
155
+ const canvas = this.mapInstance.getCanvasContainer();
156
+ canvas.style.cursor = cursor;
157
+ }
158
+ queryRenderedFeatures(pointOrBox, parameters) {
159
+ return this.mapInstance.queryRenderedFeatures(pointOrBox, parameters);
160
+ }
161
+ panTo(center, options) {
162
+ return this.zone.runOutsideAngular(() => {
163
+ this.mapInstance.panTo(center, options);
164
+ });
165
+ }
166
+ move(movingMethod, movingOptions, zoom, center, bearing, pitch) {
167
+ return this.zone.runOutsideAngular(() => {
168
+ this.mapInstance[movingMethod]({
169
+ ...movingOptions,
170
+ zoom: zoom != null ? zoom : this.mapInstance.getZoom(),
171
+ center: center != null ? center : this.mapInstance.getCenter(),
172
+ bearing: bearing != null ? bearing : this.mapInstance.getBearing(),
173
+ pitch: pitch != null ? pitch : this.mapInstance.getPitch(),
174
+ });
175
+ });
176
+ }
177
+ addLayer(layer, bindEvents, before) {
178
+ this.zone.runOutsideAngular(() => {
179
+ Object.keys(layer.layerOptions).forEach((key) => {
180
+ const tkey = key;
181
+ if (layer.layerOptions[tkey] === undefined) {
182
+ delete layer.layerOptions[tkey];
183
+ }
184
+ });
185
+ this.mapInstance.addLayer(layer.layerOptions, before);
186
+ if (bindEvents) {
187
+ if (layer.layerEvents.layerClick.observed) {
188
+ this.mapInstance.on('click', layer.layerOptions.id, (evt) => {
189
+ this.zone.run(() => {
190
+ layer.layerEvents.layerClick.emit(evt);
191
+ });
192
+ });
193
+ }
194
+ if (layer.layerEvents.layerDblClick.observed) {
195
+ this.mapInstance.on('dblclick', layer.layerOptions.id, (evt) => {
196
+ this.zone.run(() => {
197
+ layer.layerEvents.layerDblClick.emit(evt);
198
+ });
199
+ });
200
+ }
201
+ if (layer.layerEvents.layerMouseDown.observed) {
202
+ this.mapInstance.on('mousedown', layer.layerOptions.id, (evt) => {
203
+ this.zone.run(() => {
204
+ layer.layerEvents.layerMouseDown.emit(evt);
205
+ });
206
+ });
207
+ }
208
+ if (layer.layerEvents.layerMouseUp.observed) {
209
+ this.mapInstance.on('mouseup', layer.layerOptions.id, (evt) => {
210
+ this.zone.run(() => {
211
+ layer.layerEvents.layerMouseUp.emit(evt);
212
+ });
213
+ });
214
+ }
215
+ if (layer.layerEvents.layerMouseEnter.observed) {
216
+ this.mapInstance.on('mouseenter', layer.layerOptions.id, (evt) => {
217
+ this.zone.run(() => {
218
+ layer.layerEvents.layerMouseEnter.emit(evt);
219
+ });
220
+ });
221
+ }
222
+ if (layer.layerEvents.layerMouseLeave.observed) {
223
+ this.mapInstance.on('mouseleave', layer.layerOptions.id, (evt) => {
224
+ this.zone.run(() => {
225
+ layer.layerEvents.layerMouseLeave.emit(evt);
226
+ });
227
+ });
228
+ }
229
+ if (layer.layerEvents.layerMouseMove.observed) {
230
+ this.mapInstance.on('mousemove', layer.layerOptions.id, (evt) => {
231
+ this.zone.run(() => {
232
+ layer.layerEvents.layerMouseMove.emit(evt);
233
+ });
234
+ });
235
+ }
236
+ if (layer.layerEvents.layerMouseOver.observed) {
237
+ this.mapInstance.on('mouseover', layer.layerOptions.id, (evt) => {
238
+ this.zone.run(() => {
239
+ layer.layerEvents.layerMouseOver.emit(evt);
240
+ });
241
+ });
242
+ }
243
+ if (layer.layerEvents.layerMouseOut.observed) {
244
+ this.mapInstance.on('mouseout', layer.layerOptions.id, (evt) => {
245
+ this.zone.run(() => {
246
+ layer.layerEvents.layerMouseOut.emit(evt);
247
+ });
248
+ });
249
+ }
250
+ if (layer.layerEvents.layerContextMenu.observed) {
251
+ this.mapInstance.on('contextmenu', layer.layerOptions.id, (evt) => {
252
+ this.zone.run(() => {
253
+ layer.layerEvents.layerContextMenu.emit(evt);
254
+ });
255
+ });
256
+ }
257
+ if (layer.layerEvents.layerTouchStart.observed) {
258
+ this.mapInstance.on('touchstart', layer.layerOptions.id, (evt) => {
259
+ this.zone.run(() => {
260
+ layer.layerEvents.layerTouchStart.emit(evt);
261
+ });
262
+ });
263
+ }
264
+ if (layer.layerEvents.layerTouchEnd.observed) {
265
+ this.mapInstance.on('touchend', layer.layerOptions.id, (evt) => {
266
+ this.zone.run(() => {
267
+ layer.layerEvents.layerTouchEnd.emit(evt);
268
+ });
269
+ });
270
+ }
271
+ if (layer.layerEvents.layerTouchCancel.observed) {
272
+ this.mapInstance.on('touchcancel', layer.layerOptions.id, (evt) => {
273
+ this.zone.run(() => {
274
+ layer.layerEvents.layerTouchCancel.emit(evt);
275
+ });
276
+ });
277
+ }
278
+ }
279
+ });
280
+ }
281
+ removeLayer(layerId) {
282
+ this.zone.runOutsideAngular(() => {
283
+ if (this.mapInstance.getLayer(layerId) != null) {
284
+ this.mapInstance.removeLayer(layerId);
285
+ }
286
+ });
287
+ }
288
+ addMarker(marker) {
289
+ const options = {
290
+ offset: marker.markersOptions.offset,
291
+ anchor: marker.markersOptions.anchor,
292
+ draggable: marker.markersOptions.draggable,
293
+ rotationAlignment: marker.markersOptions.rotationAlignment,
294
+ pitchAlignment: marker.markersOptions.pitchAlignment,
295
+ clickTolerance: marker.markersOptions.clickTolerance,
296
+ };
297
+ Object.keys(options).forEach((key) => {
298
+ const tkey = key;
299
+ if (options[tkey] === undefined) {
300
+ delete options[tkey];
301
+ }
302
+ });
303
+ if (marker.markersOptions.element.childNodes.length > 0) {
304
+ options.element = marker.markersOptions.element;
305
+ }
306
+ const markerInstance = new Marker(options);
307
+ if (marker.markersEvents.markerDragStart.observed) {
308
+ markerInstance.on('dragstart', (event) => {
309
+ if (event) {
310
+ const { target } = event;
311
+ this.zone.run(() => {
312
+ marker.markersEvents.markerDragStart.emit(target);
313
+ });
314
+ }
315
+ });
316
+ }
317
+ /*
318
+
319
+ */
320
+ if (marker.markersEvents.markerDrag.observed) {
321
+ markerInstance.on('drag', (event) => {
322
+ if (event) {
323
+ const { target } = event;
324
+ this.zone.run(() => {
325
+ marker.markersEvents.markerDrag.emit(target);
326
+ });
327
+ }
328
+ });
329
+ }
330
+ if (marker.markersEvents.markerDragEnd.observed) {
331
+ markerInstance.on('dragend', (event) => {
332
+ if (event) {
333
+ const { target } = event;
334
+ this.zone.run(() => {
335
+ marker.markersEvents.markerDragEnd.emit(target);
336
+ });
337
+ }
338
+ });
339
+ }
340
+ const lngLat = marker.markersOptions.feature
341
+ ? marker.markersOptions.feature.geometry.coordinates
342
+ : marker.markersOptions.lngLat;
343
+ markerInstance.setLngLat(lngLat);
344
+ return this.zone.runOutsideAngular(() => {
345
+ markerInstance.addTo(this.mapInstance);
346
+ return markerInstance;
347
+ });
348
+ }
349
+ removeMarker(marker) {
350
+ this.markersToRemove.push(marker);
351
+ }
352
+ createPopup(popup, element) {
353
+ return this.zone.runOutsideAngular(() => {
354
+ Object.keys(popup.popupOptions).forEach((key) => {
355
+ const tkey = key;
356
+ return (popup.popupOptions[tkey] === undefined &&
357
+ delete popup.popupOptions[tkey]);
358
+ });
359
+ const popupInstance = new Popup(popup.popupOptions);
360
+ popupInstance.setDOMContent(element);
361
+ if (popup.popupEvents.popupClose.observed) {
362
+ popupInstance.on('close', () => {
363
+ this.zone.run(() => {
364
+ popup.popupEvents.popupClose.emit();
365
+ });
366
+ });
367
+ }
368
+ if (popup.popupEvents.popupOpen.observed) {
369
+ popupInstance.on('open', () => {
370
+ this.zone.run(() => {
371
+ popup.popupEvents.popupOpen.emit();
372
+ });
373
+ });
374
+ }
375
+ return popupInstance;
376
+ });
377
+ }
378
+ addPopupToMap(popup, lngLat, skipOpenEvent = false) {
379
+ return this.zone.runOutsideAngular(() => {
380
+ if (skipOpenEvent && popup._listeners) {
381
+ delete popup._listeners['open'];
382
+ }
383
+ popup.setLngLat(lngLat);
384
+ popup.addTo(this.mapInstance);
385
+ });
386
+ }
387
+ addPopupToMarker(marker, popup) {
388
+ return this.zone.runOutsideAngular(() => {
389
+ marker.setPopup(popup);
390
+ });
391
+ }
392
+ removePopupFromMap(popup, skipCloseEvent = false) {
393
+ if (skipCloseEvent && popup._listeners) {
394
+ delete popup._listeners['close'];
395
+ }
396
+ this.popupsToRemove.push(popup);
397
+ }
398
+ removePopupFromMarker(marker) {
399
+ return this.zone.runOutsideAngular(() => {
400
+ marker.setPopup(undefined);
401
+ });
402
+ }
403
+ addControl(control, position) {
404
+ return this.zone.runOutsideAngular(() => {
405
+ this.mapInstance.addControl(control, position);
406
+ });
407
+ }
408
+ removeControl(control) {
409
+ return this.zone.runOutsideAngular(() => {
410
+ this.mapInstance.removeControl(control);
411
+ });
412
+ }
413
+ async loadAndAddImage(imageId, url, options) {
414
+ return this.zone.runOutsideAngular(() => new Promise((resolve, reject) => {
415
+ this.mapInstance.loadImage(url, (error, image) => {
416
+ if (error) {
417
+ reject(error);
418
+ return;
419
+ }
420
+ if (!image) {
421
+ reject(new Error('Image not loaded'));
422
+ return;
423
+ }
424
+ this.addImage(imageId, image, options);
425
+ resolve();
426
+ });
427
+ }));
428
+ }
429
+ addImage(imageId, data, options) {
430
+ return this.zone.runOutsideAngular(() => {
431
+ this.mapInstance.addImage(imageId, data, options);
432
+ });
433
+ }
434
+ removeImage(imageId) {
435
+ this.imageIdsToRemove.push(imageId);
436
+ }
437
+ addSource(sourceId, source) {
438
+ return this.zone.runOutsideAngular(() => {
439
+ Object.keys(source).forEach((key) => {
440
+ const tkey = key;
441
+ return source[tkey] === undefined && delete source[tkey];
442
+ });
443
+ this.mapInstance.addSource(sourceId, source);
444
+ });
445
+ }
446
+ getSource(sourceId) {
447
+ return this.mapInstance.getSource(sourceId);
448
+ }
449
+ removeSource(sourceId) {
450
+ this.zone.runOutsideAngular(() => {
451
+ this.findLayersBySourceId(sourceId).forEach((layer) => this.mapInstance.removeLayer(layer.id));
452
+ this.mapInstance.removeSource(sourceId);
453
+ });
454
+ }
455
+ setLayerAllPaintProperty(layerId, paint) {
456
+ return this.zone.runOutsideAngular(() => {
457
+ Object.keys(paint).forEach((key) => {
458
+ const tKey = key;
459
+ // TODO Check for perf, setPaintProperty only on changed paint props maybe
460
+ this.mapInstance.setPaintProperty(layerId, tKey, paint[tKey]);
461
+ });
462
+ });
463
+ }
464
+ setLayerAllLayoutProperty(layerId, layout) {
465
+ return this.zone.runOutsideAngular(() => {
466
+ Object.keys(layout).forEach((key) => {
467
+ const tKey = key;
468
+ // TODO Check for perf, setLayoutProperty only on changed layout props maybe
469
+ this.mapInstance.setLayoutProperty(layerId, tKey, layout[tKey]);
470
+ });
471
+ });
472
+ }
473
+ setLayerFilter(layerId, filter) {
474
+ return this.zone.runOutsideAngular(() => {
475
+ this.mapInstance.setFilter(layerId, filter);
476
+ });
477
+ }
478
+ setLayerBefore(layerId, beforeId) {
479
+ return this.zone.runOutsideAngular(() => {
480
+ this.mapInstance.moveLayer(layerId, beforeId);
481
+ });
482
+ }
483
+ setLayerZoomRange(layerId, minZoom, maxZoom) {
484
+ return this.zone.runOutsideAngular(() => {
485
+ this.mapInstance.setLayerZoomRange(layerId, minZoom ? minZoom : 0, maxZoom ? maxZoom : 20);
486
+ });
487
+ }
488
+ fitBounds(bounds, options) {
489
+ return this.zone.runOutsideAngular(() => {
490
+ this.mapInstance.fitBounds(bounds, options);
491
+ });
492
+ }
493
+ fitScreenCoordinates(points, bearing, options) {
494
+ return this.zone.runOutsideAngular(() => {
495
+ this.mapInstance.fitScreenCoordinates(points[0], points[1], bearing, options);
496
+ });
497
+ }
498
+ applyChanges() {
499
+ this.zone.runOutsideAngular(() => {
500
+ this.removeMarkers();
501
+ this.removePopups();
502
+ this.removeImages();
503
+ });
504
+ }
505
+ createMap(options) {
506
+ NgZone.assertNotInAngularZone();
507
+ Object.keys(options).forEach((key) => {
508
+ const tkey = key;
509
+ if (options[tkey] === undefined) {
510
+ delete options[tkey];
511
+ }
512
+ });
513
+ this.mapInstance = new Map(options);
514
+ afterEveryRender({
515
+ write: () => {
516
+ this.applyChanges();
517
+ },
518
+ }, { injector: this.injector });
519
+ }
520
+ removeMarkers() {
521
+ for (const marker of this.markersToRemove) {
522
+ marker.remove();
523
+ }
524
+ this.markersToRemove = [];
525
+ }
526
+ removePopups() {
527
+ for (const popup of this.popupsToRemove) {
528
+ popup.remove();
529
+ }
530
+ this.popupsToRemove = [];
531
+ }
532
+ removeImages() {
533
+ for (const imageId of this.imageIdsToRemove) {
534
+ this.mapInstance.removeImage(imageId);
535
+ }
536
+ this.imageIdsToRemove = [];
537
+ }
538
+ findLayersBySourceId(sourceId) {
539
+ const layers = this.mapInstance.getStyle().layers;
540
+ if (layers == null) {
541
+ return [];
542
+ }
543
+ return layers.filter((l) => 'source' in l ? l.source === sourceId : false);
544
+ }
545
+ hookEvents(events) {
546
+ this.mapInstance.on('load', (evt) => {
547
+ this.mapLoaded.next(undefined);
548
+ this.mapLoaded.complete();
549
+ this.zone.run(() => {
550
+ events.mapLoad.emit(evt);
551
+ });
552
+ });
553
+ if (events.mapResize.observed) {
554
+ this.mapInstance.on('resize', (evt) => this.zone.run(() => {
555
+ events.mapResize.emit(evt);
556
+ }));
557
+ }
558
+ if (events.mapRemove.observed) {
559
+ this.mapInstance.on('remove', (evt) => this.zone.run(() => {
560
+ events.mapRemove.emit(evt);
561
+ }));
562
+ }
563
+ if (events.mapMouseDown.observed) {
564
+ this.mapInstance.on('mousedown', (evt) => this.zone.run(() => {
565
+ events.mapMouseDown.emit(evt);
566
+ }));
567
+ }
568
+ if (events.mapMouseUp.observed) {
569
+ this.mapInstance.on('mouseup', (evt) => this.zone.run(() => {
570
+ events.mapMouseUp.emit(evt);
571
+ }));
572
+ }
573
+ if (events.mapMouseMove.observed) {
574
+ this.mapInstance.on('mousemove', (evt) => this.zone.run(() => {
575
+ events.mapMouseMove.emit(evt);
576
+ }));
577
+ }
578
+ if (events.mapClick.observed) {
579
+ this.mapInstance.on('click', (evt) => this.zone.run(() => {
580
+ events.mapClick.emit(evt);
581
+ }));
582
+ }
583
+ if (events.mapDblClick.observed) {
584
+ this.mapInstance.on('dblclick', (evt) => this.zone.run(() => {
585
+ events.mapDblClick.emit(evt);
586
+ }));
587
+ }
588
+ if (events.mapMouseOver.observed) {
589
+ this.mapInstance.on('mouseover', (evt) => this.zone.run(() => {
590
+ events.mapMouseOver.emit(evt);
591
+ }));
592
+ }
593
+ if (events.mapMouseOut.observed) {
594
+ this.mapInstance.on('mouseout', (evt) => this.zone.run(() => {
595
+ events.mapMouseOut.emit(evt);
596
+ }));
597
+ }
598
+ if (events.mapContextMenu.observed) {
599
+ this.mapInstance.on('contextmenu', (evt) => this.zone.run(() => {
600
+ events.mapContextMenu.emit(evt);
601
+ }));
602
+ }
603
+ if (events.mapTouchStart.observed) {
604
+ this.mapInstance.on('touchstart', (evt) => this.zone.run(() => {
605
+ events.mapTouchStart.emit(evt);
606
+ }));
607
+ }
608
+ if (events.mapTouchEnd.observed) {
609
+ this.mapInstance.on('touchend', (evt) => this.zone.run(() => {
610
+ events.mapTouchEnd.emit(evt);
611
+ }));
612
+ }
613
+ if (events.mapTouchMove.observed) {
614
+ this.mapInstance.on('touchmove', (evt) => this.zone.run(() => {
615
+ events.mapTouchMove.emit(evt);
616
+ }));
617
+ }
618
+ if (events.mapTouchCancel.observed) {
619
+ this.mapInstance.on('touchcancel', (evt) => this.zone.run(() => {
620
+ events.mapTouchCancel.emit(evt);
621
+ }));
622
+ }
623
+ if (events.mapWheel.observed) {
624
+ this.mapInstance.on('wheel', (evt) => this.zone.run(() => {
625
+ events.mapWheel.emit(evt);
626
+ }));
627
+ }
628
+ if (events.moveStart.observed) {
629
+ this.mapInstance.on('movestart', (evt) => this.zone.run(() => events.moveStart.emit(evt)));
630
+ }
631
+ if (events.move.observed) {
632
+ this.mapInstance.on('move', (evt) => this.zone.run(() => events.move.emit(evt)));
633
+ }
634
+ if (events.moveEnd.observed) {
635
+ this.mapInstance.on('moveend', (evt) => this.zone.run(() => events.moveEnd.emit(evt)));
636
+ }
637
+ if (events.mapDragStart.observed) {
638
+ this.mapInstance.on('dragstart', (evt) => this.zone.run(() => events.mapDragStart.emit(evt)));
639
+ }
640
+ if (events.mapDrag.observed) {
641
+ this.mapInstance.on('drag', (evt) => this.zone.run(() => events.mapDrag.emit(evt)));
642
+ }
643
+ if (events.mapDragEnd.observed) {
644
+ this.mapInstance.on('dragend', (evt) => this.zone.run(() => events.mapDragEnd.emit(evt)));
645
+ }
646
+ if (events.zoomStart.observed) {
647
+ this.mapInstance.on('zoomstart', () => this.zone.run(() => events.zoomStart.emit()));
648
+ }
649
+ if (events.zoomEvt.observed) {
650
+ this.mapInstance.on('zoom', () => this.zone.run(() => events.zoomEvt.emit()));
651
+ }
652
+ if (events.zoomEnd.observed) {
653
+ this.mapInstance.on('zoomend', () => this.zone.run(() => events.zoomEnd.emit()));
654
+ }
655
+ if (events.rotateStart.observed) {
656
+ this.mapInstance.on('rotatestart', (evt) => this.zone.run(() => events.rotateStart.emit(evt)));
657
+ }
658
+ if (events.rotate.observed) {
659
+ this.mapInstance.on('rotate', (evt) => this.zone.run(() => events.rotate.emit(evt)));
660
+ }
661
+ if (events.rotateEnd.observed) {
662
+ this.mapInstance.on('rotateend', (evt) => this.zone.run(() => events.rotateEnd.emit(evt)));
663
+ }
664
+ if (events.pitchStart.observed) {
665
+ this.mapInstance.on('pitchstart', () => this.zone.run(() => events.pitchStart.emit()));
666
+ }
667
+ if (events.pitchEvt.observed) {
668
+ this.mapInstance.on('pitch', () => this.zone.run(() => events.pitchEvt.emit()));
669
+ }
670
+ if (events.pitchEnd.observed) {
671
+ this.mapInstance.on('pitchend', () => this.zone.run(() => events.pitchEnd.emit()));
672
+ }
673
+ if (events.boxZoomStart.observed) {
674
+ this.mapInstance.on('boxzoomstart', (evt) => this.zone.run(() => events.boxZoomStart.emit(evt)));
675
+ }
676
+ if (events.boxZoomEnd.observed) {
677
+ this.mapInstance.on('boxzoomend', (evt) => this.zone.run(() => events.boxZoomEnd.emit(evt)));
678
+ }
679
+ if (events.boxZoomCancel.observed) {
680
+ this.mapInstance.on('boxzoomcancel', (evt) => this.zone.run(() => events.boxZoomCancel.emit(evt)));
681
+ }
682
+ if (events.webGlContextLost.observed) {
683
+ this.mapInstance.on('webglcontextlost', (evt) => this.zone.run(() => events.webGlContextLost.emit(evt)));
684
+ }
685
+ if (events.webGlContextRestored.observed) {
686
+ this.mapInstance.on('webglcontextrestored', (evt) => this.zone.run(() => events.webGlContextRestored.emit(evt)));
687
+ }
688
+ if (events.render.observed) {
689
+ this.mapInstance.on('render', () => this.zone.run(() => events.render.emit()));
690
+ }
691
+ if (events.mapError.observed) {
692
+ this.mapInstance.on('error', (evt) => this.zone.run(() => events.mapError.emit(evt.error)));
693
+ }
694
+ if (events.data.observed) {
695
+ this.mapInstance.on('data', (evt) => this.zone.run(() => events.data.emit(evt)));
696
+ }
697
+ if (events.styleData.observed) {
698
+ this.mapInstance.on('styledata', (evt) => this.zone.run(() => events.styleData.emit(evt)));
699
+ }
700
+ if (events.sourceData.observed) {
701
+ this.mapInstance.on('sourcedata', (evt) => this.zone.run(() => events.sourceData.emit(evt)));
702
+ }
703
+ if (events.dataLoading.observed) {
704
+ this.mapInstance.on('dataloading', (evt) => this.zone.run(() => events.dataLoading.emit(evt)));
705
+ }
706
+ if (events.styleDataLoading.observed) {
707
+ this.mapInstance.on('styledataloading', (evt) => this.zone.run(() => events.styleDataLoading.emit(evt)));
708
+ }
709
+ if (events.sourceDataLoading.observed) {
710
+ this.mapInstance.on('sourcedataloading', (evt) => this.zone.run(() => events.sourceDataLoading.emit(evt)));
711
+ }
712
+ if (events.styleImageMissing.observed) {
713
+ this.mapInstance.on('styleimagemissing', (evt) => this.zone.run(() => events.styleImageMissing.emit(evt)));
714
+ }
715
+ if (events.idle.observed) {
716
+ this.mapInstance.on('idle', () => this.zone.run(() => events.idle.emit()));
717
+ }
718
+ }
719
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: MapService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
720
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: MapService });
721
+ }
722
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: MapService, decorators: [{
723
+ type: Injectable
724
+ }], ctorParameters: () => [] });
725
+ //# sourceMappingURL=map.service.js.map