@artstesh/maps 4.0.0 → 4.0.3

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 (78) hide show
  1. package/dist/esm2020/map/map-plate/layers/tile-layer/tile-layer.component.mjs +40 -6
  2. package/dist/esm2020/map/map-plate/layers/tile-layer/tile-layer.factory.mjs +50 -0
  3. package/dist/esm2020/map/map-plate/layers/tile-layer/tile-layer.settings.mjs +14 -8
  4. package/dist/esm2020/map/map-plate/map-plate.component.mjs +8 -7
  5. package/dist/esm2020/map/map.module.mjs +3 -3
  6. package/dist/esm2020/map/messages/commands/add-tile.command.mjs +12 -0
  7. package/dist/esm2020/map/messages/commands/remove-tile.command.mjs +12 -0
  8. package/dist/esm2020/map/messages/events/map-click.event.mjs +13 -0
  9. package/dist/esm2020/map/messages/index.mjs +2 -1
  10. package/dist/esm2020/map/models/marker-model.mjs +4 -7
  11. package/dist/esm2020/map/services/map-click.service.mjs +49 -0
  12. package/dist/esm2020/map/services/map-management.service.mjs +21 -8
  13. package/dist/esm2020/map/services/map-postboy.service.mjs +6 -17
  14. package/dist/esm2020/map/services/map-state.service.mjs +4 -2
  15. package/dist/esm2020/map/services/message-registrator.service.mjs +23 -12
  16. package/dist/esm2020/src/map/map-plate/layers/tile-layer/tile-layer.component.mjs +40 -6
  17. package/dist/esm2020/src/map/map-plate/layers/tile-layer/tile-layer.factory.mjs +50 -0
  18. package/dist/esm2020/src/map/map-plate/layers/tile-layer/tile-layer.settings.mjs +14 -8
  19. package/dist/esm2020/src/map/map-plate/map-plate.component.mjs +8 -7
  20. package/dist/esm2020/src/map/map.module.mjs +3 -3
  21. package/dist/esm2020/src/map/messages/commands/add-tile.command.mjs +12 -0
  22. package/dist/esm2020/src/map/messages/commands/remove-tile.command.mjs +12 -0
  23. package/dist/esm2020/src/map/messages/events/map-click.event.mjs +13 -0
  24. package/dist/esm2020/src/map/messages/index.mjs +2 -1
  25. package/dist/esm2020/src/map/models/marker-model.mjs +4 -7
  26. package/dist/esm2020/src/map/services/map-click.service.mjs +49 -0
  27. package/dist/esm2020/src/map/services/map-management.service.mjs +21 -8
  28. package/dist/esm2020/src/map/services/map-postboy.service.mjs +6 -17
  29. package/dist/esm2020/src/map/services/map-state.service.mjs +4 -2
  30. package/dist/esm2020/src/map/services/message-registrator.service.mjs +23 -12
  31. package/dist/fesm2015/maps-components-src-map.mjs +263 -119
  32. package/dist/fesm2015/maps-components-src-map.mjs.map +1 -1
  33. package/dist/fesm2015/maps-components.mjs +263 -119
  34. package/dist/fesm2015/maps-components.mjs.map +1 -1
  35. package/dist/fesm2020/maps-components-src-map.mjs +261 -118
  36. package/dist/fesm2020/maps-components-src-map.mjs.map +1 -1
  37. package/dist/fesm2020/maps-components.mjs +261 -118
  38. package/dist/fesm2020/maps-components.mjs.map +1 -1
  39. package/dist/map/map-plate/layers/tile-layer/tile-layer.component.d.ts +14 -5
  40. package/dist/map/map-plate/layers/tile-layer/tile-layer.factory.d.ts +11 -0
  41. package/dist/map/map-plate/layers/tile-layer/tile-layer.settings.d.ts +3 -2
  42. package/dist/map/map-plate/map-plate.component.d.ts +2 -2
  43. package/dist/map/map.module.d.ts +1 -1
  44. package/dist/map/messages/commands/add-tile.command.d.ts +9 -0
  45. package/dist/map/messages/commands/remove-tile.command.d.ts +9 -0
  46. package/dist/map/messages/events/map-click.event.d.ts +12 -0
  47. package/dist/map/messages/index.d.ts +1 -0
  48. package/dist/map/models/marker-model.d.ts +2 -2
  49. package/dist/map/services/map-click.service.d.ts +16 -0
  50. package/dist/map/services/map-management.service.d.ts +5 -2
  51. package/dist/map/services/map-postboy.service.d.ts +4 -7
  52. package/dist/map/services/map-state.service.d.ts +3 -1
  53. package/dist/map/services/message-registrator.service.d.ts +7 -2
  54. package/dist/package.json +2 -1
  55. package/dist/src/map/map-plate/layers/tile-layer/tile-layer.component.d.ts +14 -5
  56. package/dist/src/map/map-plate/layers/tile-layer/tile-layer.factory.d.ts +11 -0
  57. package/dist/src/map/map-plate/layers/tile-layer/tile-layer.settings.d.ts +3 -2
  58. package/dist/src/map/map-plate/map-plate.component.d.ts +2 -2
  59. package/dist/src/map/map.module.d.ts +1 -1
  60. package/dist/src/map/messages/commands/add-tile.command.d.ts +9 -0
  61. package/dist/src/map/messages/commands/remove-tile.command.d.ts +9 -0
  62. package/dist/src/map/messages/events/map-click.event.d.ts +12 -0
  63. package/dist/src/map/messages/index.d.ts +1 -0
  64. package/dist/src/map/models/marker-model.d.ts +2 -2
  65. package/dist/src/map/services/map-click.service.d.ts +16 -0
  66. package/dist/src/map/services/map-management.service.d.ts +5 -2
  67. package/dist/src/map/services/map-postboy.service.d.ts +4 -7
  68. package/dist/src/map/services/map-state.service.d.ts +3 -1
  69. package/dist/src/map/services/message-registrator.service.d.ts +7 -2
  70. package/package.json +3 -2
  71. package/dist/esm2020/map/messages/commands/clear-layer.command.mjs +0 -12
  72. package/dist/esm2020/map/services/service.collector.mjs +0 -14
  73. package/dist/esm2020/src/map/messages/commands/clear-layer.command.mjs +0 -12
  74. package/dist/esm2020/src/map/services/service.collector.mjs +0 -14
  75. package/dist/map/messages/commands/clear-layer.command.d.ts +0 -7
  76. package/dist/map/services/service.collector.d.ts +0 -9
  77. package/dist/src/map/messages/commands/clear-layer.command.d.ts +0 -7
  78. package/dist/src/map/services/service.collector.d.ts +0 -9
@@ -4,14 +4,15 @@ import * as i4 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
5
  import { Feature } from 'ol';
6
6
  import { Point } from 'ol/geom';
7
- import { useGeographic } from 'ol/proj';
8
- import { Subject, ReplaySubject } from 'rxjs';
7
+ import { useGeographic, get } from 'ol/proj';
8
+ import { Subject } from 'rxjs';
9
+ import { PostboyService, PostboyAbstractRegistrator } from '@artstesh/postboy';
9
10
  import Map from 'ol/Map';
10
11
  import View from 'ol/View';
11
12
  import TileLayer from 'ol/layer/Tile';
12
13
  import OSM from 'ol/source/OSM';
13
14
  import { filter, first } from 'rxjs/operators';
14
- import { Vector } from 'ol/source';
15
+ import { XYZ, Vector } from 'ol/source';
15
16
  import { Vector as Vector$1 } from 'ol/layer';
16
17
  import Style from 'ol/style/Style';
17
18
  import { Icon, Circle, Fill, Stroke } from 'ol/style';
@@ -122,10 +123,8 @@ class MarkerModel {
122
123
  constructor(lat, lng, id, info) {
123
124
  this.lat = lat;
124
125
  this.lng = lng;
125
- this.id = id;
126
126
  this.info = info;
127
- if (id == null)
128
- this.id = IdGenerator.get();
127
+ this.id = id == null ? IdGenerator.get() : id;
129
128
  this._feature = this.getFeature();
130
129
  }
131
130
  get feature() {
@@ -134,9 +133,8 @@ class MarkerModel {
134
133
  getFeature() {
135
134
  const feature = new Feature(new Point([this.lng, this.lat]));
136
135
  feature.setId(this.id);
137
- if (this.info) {
138
- Object.keys(this.info).forEach((k) => feature.set(k, this.info[k]));
139
- }
136
+ if (this.info)
137
+ feature.set('info', this.info);
140
138
  return feature;
141
139
  }
142
140
  }
@@ -166,6 +164,18 @@ class MapRenderedEvent extends GenericMessage {
166
164
  }
167
165
  MapRenderedEvent.ID = 'b6121807-3b89-4cd3-82cf-089d2cefdc4f';
168
166
 
167
+ class MapClickEvent extends GenericMessage {
168
+ constructor(coordinates, entities) {
169
+ super();
170
+ this.coordinates = coordinates;
171
+ this.entities = entities;
172
+ }
173
+ get id() {
174
+ return MapClickEvent.ID;
175
+ }
176
+ }
177
+ MapClickEvent.ID = '323df526-8d9c-49c6-83e8-6e9a1e7762f7';
178
+
169
179
  class AddLayerCommand extends GenericMessage {
170
180
  constructor(layer) {
171
181
  super();
@@ -200,88 +210,72 @@ class RemoveLayerCommand extends GenericMessage {
200
210
  }
201
211
  RemoveLayerCommand.ID = 'ab484e0e-e185-45cd-8434-12101f3c7eb1';
202
212
 
203
- class ClearLayerCommand extends GenericMessage {
213
+ class AddTileCommand extends GenericMessage {
204
214
  constructor(layer) {
205
215
  super();
206
216
  this.layer = layer;
207
217
  }
208
218
  get id() {
209
- return ClearLayerCommand.ID;
219
+ return AddTileCommand.ID;
210
220
  }
211
221
  }
212
- ClearLayerCommand.ID = 'd02842b7-fa62-458d-b1e4-12dd814610c5';
222
+ AddTileCommand.ID = '25b7df28-72ce-4453-9fe6-54285a2fdc57';
213
223
 
214
- class MapPostboyService {
215
- constructor() {
216
- this.applications = {};
217
- }
218
- register(id, sub) {
219
- this.applications[id] = sub;
224
+ class RemoveTileCommand extends GenericMessage {
225
+ constructor(layer) {
226
+ super();
227
+ this.layer = layer;
220
228
  }
221
- subscribe(id) {
222
- if (!this.applications[id])
223
- throw new Error(`There is no event with id ${id}`);
224
- return this.applications[id].asObservable();
229
+ get id() {
230
+ return RemoveTileCommand.ID;
225
231
  }
226
- fire(message) {
227
- if (!this.applications[message.id])
228
- throw new Error(`There is no event with id ${message.id}`);
229
- this.applications[message.id].next(message);
232
+ }
233
+ RemoveTileCommand.ID = 'c36ccc0b-5638-4819-b148-2de57a59a5b7';
234
+
235
+ class MapPostboyService extends PostboyService {
236
+ constructor() {
237
+ super(...arguments);
238
+ this.observe = (id) => this.subscribe(id);
230
239
  }
231
240
  }
232
- MapPostboyService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapPostboyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
241
+ MapPostboyService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapPostboyService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
233
242
  MapPostboyService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapPostboyService });
234
243
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapPostboyService, decorators: [{
235
244
  type: Injectable
236
245
  }] });
237
246
 
238
- class MessageRegistratorService {
239
- constructor(service) {
240
- service.register(MapRenderedEvent.ID, new ReplaySubject(1));
241
- service.register(AddLayerCommand.ID, new Subject());
242
- service.register(PlaceLayerFeaturesCommand.ID, new ReplaySubject(1));
243
- service.register(RemoveLayerCommand.ID, new Subject());
244
- service.register(ClearLayerCommand.ID, new Subject());
245
- }
246
- }
247
- MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
248
- MessageRegistratorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService });
249
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService, decorators: [{
250
- type: Injectable
251
- }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
252
-
253
- class MapStateService {
254
- constructor(postboy) {
255
- this.postboy = postboy;
256
- postboy.subscribe(MapRenderedEvent.ID).subscribe((m) => (this.map = m));
257
- }
258
- }
259
- MapStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapStateService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
260
- MapStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapStateService });
261
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapStateService, decorators: [{
262
- type: Injectable
263
- }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
264
-
265
247
  class MapManagementService {
266
248
  constructor(postboy) {
267
249
  this.postboy = postboy;
268
250
  this.layers = {};
251
+ }
252
+ up() {
269
253
  this.observeMapRender();
270
254
  this.observeAddLayer();
271
255
  this.observeRemoveLayer();
272
256
  this.observePlaceFeatures();
273
- this.observeClearLayer();
257
+ this.observeAddTile();
258
+ this.observeRemoveTile();
259
+ }
260
+ observeRemoveTile() {
261
+ this.postboy.subscribe(RemoveTileCommand.ID).subscribe((c) => {
262
+ if (!this.map)
263
+ return;
264
+ this.map.removeLayer(c.layer);
265
+ });
266
+ }
267
+ observeAddTile() {
268
+ this.postboy.subscribe(AddTileCommand.ID).subscribe((c) => {
269
+ if (!this.map)
270
+ return;
271
+ this.map.addLayer(c.layer);
272
+ });
274
273
  }
275
274
  observeMapRender() {
276
275
  this.postboy.subscribe(MapRenderedEvent.ID).subscribe((m) => {
277
276
  this.map = m.map;
278
277
  });
279
278
  }
280
- observeClearLayer() {
281
- this.postboy.subscribe(ClearLayerCommand.ID).subscribe((c) => {
282
- this.layers[c.layer]?.getSource()?.clear();
283
- });
284
- }
285
279
  observeAddLayer() {
286
280
  this.postboy.subscribe(AddLayerCommand.ID).subscribe((c) => {
287
281
  if (!this.map)
@@ -313,14 +307,84 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
313
307
  type: Injectable
314
308
  }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
315
309
 
316
- class ServiceCollector {
317
- constructor(registrator, management, state) { }
310
+ class MapStateService {
311
+ constructor(postboy) {
312
+ this.postboy = postboy;
313
+ }
314
+ up() {
315
+ this.postboy.subscribe(MapRenderedEvent.ID).subscribe((m) => (this.map = m));
316
+ }
317
+ }
318
+ MapStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapStateService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
319
+ MapStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapStateService });
320
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapStateService, decorators: [{
321
+ type: Injectable
322
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
323
+
324
+ class MapClickService {
325
+ constructor(postboy) {
326
+ this.postboy = postboy;
327
+ }
328
+ up() {
329
+ this.observeMapRender();
330
+ }
331
+ observeMapRender() {
332
+ this.postboy.subscribe(MapRenderedEvent.ID).subscribe((m) => {
333
+ this.map = m.map;
334
+ this.map?.on('singleclick', (e) => {
335
+ this.postboy.fire(this.onClick(e));
336
+ });
337
+ });
338
+ }
339
+ onClick(ev) {
340
+ const model = new MapClickEvent(ev.coordinate, {});
341
+ this.map?.forEachFeatureAtPixel(ev.pixel, (f, l) => {
342
+ this.getFeatureCollectionWithInner([f])
343
+ .filter((f) => !!f.getId())
344
+ .forEach((fs) => {
345
+ let layerName = l.get('name');
346
+ if (!model.entities[layerName])
347
+ model.entities[layerName] = [];
348
+ model.entities[layerName].push(f.getId());
349
+ });
350
+ });
351
+ return model;
352
+ }
353
+ getFeatureCollectionWithInner(features) {
354
+ const result = [];
355
+ features?.forEach((f) => {
356
+ const innerFeatures = f.get('features');
357
+ innerFeatures?.length ? result.push(...innerFeatures) : result.push(f);
358
+ });
359
+ return result;
360
+ }
361
+ }
362
+ MapClickService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapClickService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
363
+ MapClickService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapClickService });
364
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapClickService, decorators: [{
365
+ type: Injectable
366
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
367
+
368
+ class MessageRegistratorService extends PostboyAbstractRegistrator {
369
+ constructor(service, management, state, interaction) {
370
+ super(service);
371
+ this.registerServices([management, state, interaction]);
372
+ }
373
+ _up() {
374
+ this.registerReplay(MapRenderedEvent.ID);
375
+ this.registerReplay(PlaceLayerFeaturesCommand.ID);
376
+ this.registerSubject(AddLayerCommand.ID);
377
+ this.registerSubject(RemoveLayerCommand.ID);
378
+ this.registerSubject(AddTileCommand.ID);
379
+ this.registerSubject(RemoveTileCommand.ID);
380
+ this.registerSubject(MapClickEvent.ID);
381
+ }
318
382
  }
319
- ServiceCollector.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ServiceCollector, deps: [{ token: MessageRegistratorService }, { token: MapManagementService }, { token: MapStateService }], target: i0.ɵɵFactoryTarget.Injectable });
320
- ServiceCollector.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ServiceCollector });
321
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ServiceCollector, decorators: [{
383
+ MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapClickService }], target: i0.ɵɵFactoryTarget.Injectable });
384
+ MessageRegistratorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService });
385
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService, decorators: [{
322
386
  type: Injectable
323
- }], ctorParameters: function () { return [{ type: MessageRegistratorService }, { type: MapManagementService }, { type: MapStateService }]; } });
387
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapClickService }]; } });
324
388
 
325
389
  class MapPlateFactory {
326
390
  build(settings) {
@@ -404,6 +468,7 @@ class MapPlateComponent extends DestructibleComponent {
404
468
  this.detector = detector;
405
469
  this.osmUrl = '';
406
470
  this._settings = new MapSettings();
471
+ registrator.up();
407
472
  }
408
473
  set settings(value) {
409
474
  if (!value || this._settings.isSame(value))
@@ -430,26 +495,145 @@ class MapPlateComponent extends DestructibleComponent {
430
495
  this.map.updateSize();
431
496
  }
432
497
  }
433
- MapPlateComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapPlateComponent, deps: [{ token: i0.ElementRef }, { token: MapPostboyService }, { token: MapPlateFactory }, { token: ServiceCollector }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
434
- MapPlateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: MapPlateComponent, selector: "lib-map-plate", inputs: { settings: "settings" }, providers: [MessageRegistratorService, MapStateService, MapManagementService, ServiceCollector], usesInheritance: true, ngImport: i0, template: "<ng-content></ng-content>\n<lib-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></lib-osm-tile-layer>\n", styles: ["lib-map-plate{position:relative;display:flex;flex-direction:column;height:100%}\n"], dependencies: [{ kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: OsmTileLayerComponent, selector: "lib-osm-tile-layer", inputs: ["url", "map"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
498
+ MapPlateComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapPlateComponent, deps: [{ token: i0.ElementRef }, { token: MapPostboyService }, { token: MapPlateFactory }, { token: MessageRegistratorService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
499
+ MapPlateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: MapPlateComponent, selector: "lib-map-plate", inputs: { settings: "settings" }, providers: [MessageRegistratorService, MapStateService, MapManagementService, MapClickService], usesInheritance: true, ngImport: i0, template: "<ng-content></ng-content>\n<lib-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></lib-osm-tile-layer>\n", styles: ["lib-map-plate{position:relative;display:flex;flex-direction:column;height:100%}\n"], dependencies: [{ kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: OsmTileLayerComponent, selector: "lib-osm-tile-layer", inputs: ["url", "map"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
435
500
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapPlateComponent, decorators: [{
436
501
  type: Component,
437
- args: [{ selector: 'lib-map-plate', changeDetection: ChangeDetectionStrategy.OnPush, providers: [MessageRegistratorService, MapStateService, MapManagementService, ServiceCollector], template: "<ng-content></ng-content>\n<lib-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></lib-osm-tile-layer>\n", styles: ["lib-map-plate{position:relative;display:flex;flex-direction:column;height:100%}\n"] }]
438
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MapPostboyService }, { type: MapPlateFactory }, { type: ServiceCollector }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { settings: [{
502
+ args: [{ selector: 'lib-map-plate', changeDetection: ChangeDetectionStrategy.OnPush, providers: [MessageRegistratorService, MapStateService, MapManagementService, MapClickService], template: "<ng-content></ng-content>\n<lib-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></lib-osm-tile-layer>\n", styles: ["lib-map-plate{position:relative;display:flex;flex-direction:column;height:100%}\n"] }]
503
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MapPostboyService }, { type: MapPlateFactory }, { type: MessageRegistratorService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { settings: [{
439
504
  type: Input
440
505
  }] } });
441
506
 
442
- class TileLayerComponent extends DestructibleComponent {
507
+ class TileLayerSettings {
443
508
  constructor() {
509
+ this.maxZoom = 19;
510
+ this.minZoom = 0;
511
+ this.opacity = 0.6;
512
+ this.url = '';
513
+ this.projection = 'EPSG:3857';
514
+ }
515
+ static copy(model) {
516
+ const result = new TileLayerSettings();
517
+ result.maxZoom = model.maxZoom;
518
+ result.minZoom = model.minZoom;
519
+ result.projection = model.projection;
520
+ result.opacity = model.opacity;
521
+ result.url = model.url;
522
+ return result;
523
+ }
524
+ setUrl(url) {
525
+ return TileLayerSettings.copy({ ...this, url });
526
+ }
527
+ setMaxZoom(maxZoom) {
528
+ return TileLayerSettings.copy({ ...this, maxZoom });
529
+ }
530
+ setMinZoom(minZoom) {
531
+ return TileLayerSettings.copy({ ...this, minZoom });
532
+ }
533
+ setOpacity(opacity) {
534
+ return TileLayerSettings.copy({ ...this, opacity });
535
+ }
536
+ setProjection(projection) {
537
+ return TileLayerSettings.copy({ ...this, projection });
538
+ }
539
+ isSame(model) {
540
+ if (this.maxZoom !== model.maxZoom)
541
+ return false;
542
+ if (this.minZoom !== model.minZoom)
543
+ return false;
544
+ if (this.url !== model.url)
545
+ return false;
546
+ if (this.projection !== model.projection)
547
+ return false;
548
+ if (this.opacity !== model.opacity)
549
+ return false;
550
+ return true;
551
+ }
552
+ }
553
+
554
+ class TileLayerFactory {
555
+ build(settings) {
556
+ const source = new XYZ({
557
+ tileSize: 256,
558
+ maxZoom: settings.maxZoom || 14,
559
+ minZoom: settings.minZoom || 1,
560
+ projection: get(settings.projection),
561
+ tileUrlFunction: this.getTileFunc(settings),
562
+ crossOrigin: 'Anonymous',
563
+ });
564
+ return new TileLayer({ source, opacity: settings.opacity });
565
+ }
566
+ getTileFunc(settings) {
567
+ return (tileCoord) => {
568
+ const zoom = tileCoord[0];
569
+ const x = tileCoord[1];
570
+ const y = tileCoord[2];
571
+ const normalizedCoord = this.getNormalizedCoord({ x: x, y: y }, zoom);
572
+ const bound = 1 << zoom;
573
+ return settings.url
574
+ .replace('{x}', String(normalizedCoord?.x || x))
575
+ .replace('{z}', String(zoom))
576
+ .replace('{y}', String(bound - (normalizedCoord?.y || y) - 1));
577
+ };
578
+ }
579
+ getNormalizedCoord(coord, zoom) {
580
+ const y = coord.y;
581
+ let x = coord.x;
582
+ const tileRange = 1 << zoom;
583
+ if (y < 0 || y >= tileRange)
584
+ return null;
585
+ if (x < 0 || x >= tileRange)
586
+ x = ((x % tileRange) + tileRange) % tileRange;
587
+ return { x: x, y: y };
588
+ }
589
+ }
590
+ TileLayerFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TileLayerFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
591
+ TileLayerFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TileLayerFactory, providedIn: 'root' });
592
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TileLayerFactory, decorators: [{
593
+ type: Injectable,
594
+ args: [{
595
+ providedIn: 'root',
596
+ }]
597
+ }] });
598
+
599
+ class TileLayerComponent extends DestructibleComponent {
600
+ constructor(postboy, factory) {
444
601
  super();
602
+ this.postboy = postboy;
603
+ this.factory = factory;
604
+ this._settings = new TileLayerSettings();
605
+ this.onDestroy = () => this.removeLayer();
606
+ }
607
+ ngOnInit() {
608
+ this.postboy
609
+ .subscribe(MapRenderedEvent.ID)
610
+ .pipe(filter((m) => !!m), first())
611
+ .subscribe((m) => this.initLayer());
612
+ }
613
+ set settings(value) {
614
+ if (!value || this._settings.isSame(value))
615
+ return;
616
+ this._settings = value;
617
+ this.initLayer();
618
+ }
619
+ initLayer() {
620
+ this.removeLayer();
621
+ this.layer = this.factory.build(this._settings);
622
+ this.postboy.fire(new AddTileCommand(this.layer));
623
+ }
624
+ removeLayer() {
625
+ if (this.layer)
626
+ this.postboy.fire(new RemoveTileCommand(this.layer));
445
627
  }
446
628
  }
447
- TileLayerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TileLayerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
448
- TileLayerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: TileLayerComponent, selector: "lib-tile-layer", usesInheritance: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
629
+ TileLayerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TileLayerComponent, deps: [{ token: MapPostboyService }, { token: TileLayerFactory }], target: i0.ɵɵFactoryTarget.Component });
630
+ TileLayerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: TileLayerComponent, selector: "lib-tile-layer", inputs: { settings: "settings" }, usesInheritance: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
449
631
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TileLayerComponent, decorators: [{
450
632
  type: Component,
451
633
  args: [{ selector: 'lib-tile-layer', template: '', changeDetection: ChangeDetectionStrategy.OnPush }]
452
- }], ctorParameters: function () { return []; } });
634
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: TileLayerFactory }]; }, propDecorators: { settings: [{
635
+ type: Input
636
+ }] } });
453
637
 
454
638
  class FeatureLayerSettings {
455
639
  constructor() {
@@ -603,7 +787,7 @@ MapModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.
603
787
  TileLayerComponent,
604
788
  OsmTileLayerComponent,
605
789
  FeatureLayerComponent,
606
- MarkersComponent], imports: [CommonModule], exports: [MapPlateComponent, FeatureLayerComponent, MarkersComponent] });
790
+ MarkersComponent], imports: [CommonModule], exports: [MapPlateComponent, FeatureLayerComponent, MarkersComponent, TileLayerComponent] });
607
791
  MapModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapModule, imports: [CommonModule] });
608
792
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapModule, decorators: [{
609
793
  type: NgModule,
@@ -617,51 +801,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
617
801
  FeatureLayerComponent,
618
802
  MarkersComponent,
619
803
  ],
620
- exports: [MapPlateComponent, FeatureLayerComponent, MarkersComponent],
804
+ exports: [MapPlateComponent, FeatureLayerComponent, MarkersComponent, TileLayerComponent],
621
805
  }]
622
806
  }] });
623
807
 
624
- class TileLayerSettings {
625
- constructor() {
626
- this.name = 'tiles';
627
- this.maxZoom = 19;
628
- this.minZoom = 0;
629
- this.opacity = 1;
630
- this.url = '';
631
- }
632
- static copy(model) {
633
- const result = new TileLayerSettings();
634
- result.name = model.name;
635
- result.maxZoom = model.maxZoom;
636
- result.minZoom = model.minZoom;
637
- result.url = model.url;
638
- return result;
639
- }
640
- setUrl(url) {
641
- return TileLayerSettings.copy({ ...this, url });
642
- }
643
- setName(name) {
644
- return TileLayerSettings.copy({ ...this, name });
645
- }
646
- setMaxZoom(maxZoom) {
647
- return TileLayerSettings.copy({ ...this, maxZoom });
648
- }
649
- setMinZoom(minZoom) {
650
- return TileLayerSettings.copy({ ...this, minZoom });
651
- }
652
- isSame(model) {
653
- if (this.maxZoom !== model.maxZoom)
654
- return false;
655
- if (this.minZoom !== model.minZoom)
656
- return false;
657
- if (this.url !== model.url)
658
- return false;
659
- if (this.name !== model.name)
660
- return false;
661
- return true;
662
- }
663
- }
664
-
665
808
  class MarkerStyleHelper {
666
809
  static fromSvg(svg, size = [30, 30], zIndex = 400) {
667
810
  let image = new Image();
@@ -693,5 +836,5 @@ class MarkerStyleHelper {
693
836
  * Generated bundle index. Do not edit.
694
837
  */
695
838
 
696
- export { CallbackMessage, FeatureLayerComponent, FeatureLayerSettings, GenericMessage, MapLyrs, MapLyrsLabel, MapModule, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, OsmTileLayerComponent, TileLayerComponent, TileLayerSettings };
839
+ export { CallbackMessage, FeatureLayerComponent, FeatureLayerSettings, GenericMessage, MapClickEvent, MapLyrs, MapLyrsLabel, MapModule, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, OsmTileLayerComponent, TileLayerComponent, TileLayerSettings };
697
840
  //# sourceMappingURL=maps-components-src-map.mjs.map