@artstesh/maps 1.0.9 → 1.0.10

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 (51) hide show
  1. package/dist/bundles/maps-components-src-map.umd.js +222 -17
  2. package/dist/bundles/maps-components-src-map.umd.js.map +1 -1
  3. package/dist/bundles/maps-components.umd.js +222 -17
  4. package/dist/bundles/maps-components.umd.js.map +1 -1
  5. package/dist/esm2015/map/map-plate/map-plate.component.js +4 -1
  6. package/dist/esm2015/map/messages/commands/draw-selection-area.command.js +14 -0
  7. package/dist/esm2015/map/messages/index.js +2 -1
  8. package/dist/esm2015/map/messages/queries/filter-features-in-area.query.js +13 -0
  9. package/dist/esm2015/map/messages/queries/get-features-in-area.query.js +13 -0
  10. package/dist/esm2015/map/models/dictionary.js +56 -0
  11. package/dist/esm2015/map/models/index.js +2 -1
  12. package/dist/esm2015/map/services/drawing/drawing.service.js +25 -3
  13. package/dist/esm2015/map/services/feature.service.js +29 -0
  14. package/dist/esm2015/map/services/map-management.service.js +39 -9
  15. package/dist/esm2015/map/services/message-registrator.service.js +12 -5
  16. package/dist/esm2015/src/map/map-plate/map-plate.component.js +4 -1
  17. package/dist/esm2015/src/map/messages/commands/draw-selection-area.command.js +14 -0
  18. package/dist/esm2015/src/map/messages/index.js +2 -1
  19. package/dist/esm2015/src/map/messages/queries/filter-features-in-area.query.js +13 -0
  20. package/dist/esm2015/src/map/messages/queries/get-features-in-area.query.js +13 -0
  21. package/dist/esm2015/src/map/models/dictionary.js +56 -0
  22. package/dist/esm2015/src/map/models/index.js +2 -1
  23. package/dist/esm2015/src/map/services/drawing/drawing.service.js +25 -3
  24. package/dist/esm2015/src/map/services/feature.service.js +29 -0
  25. package/dist/esm2015/src/map/services/map-management.service.js +39 -9
  26. package/dist/esm2015/src/map/services/message-registrator.service.js +12 -5
  27. package/dist/fesm2015/maps-components-src-map.js +183 -16
  28. package/dist/fesm2015/maps-components-src-map.js.map +1 -1
  29. package/dist/fesm2015/maps-components.js +183 -16
  30. package/dist/fesm2015/maps-components.js.map +1 -1
  31. package/dist/map/messages/commands/draw-selection-area.command.d.ts +12 -0
  32. package/dist/map/messages/index.d.ts +1 -0
  33. package/dist/map/messages/queries/filter-features-in-area.query.d.ts +10 -0
  34. package/dist/map/messages/queries/get-features-in-area.query.d.ts +11 -0
  35. package/dist/map/models/dictionary.d.ts +17 -0
  36. package/dist/map/models/index.d.ts +1 -0
  37. package/dist/map/services/drawing/drawing.service.d.ts +2 -0
  38. package/dist/map/services/feature.service.d.ts +11 -0
  39. package/dist/map/services/map-management.service.d.ts +1 -0
  40. package/dist/map/services/message-registrator.service.d.ts +2 -1
  41. package/dist/src/map/messages/commands/draw-selection-area.command.d.ts +12 -0
  42. package/dist/src/map/messages/index.d.ts +1 -0
  43. package/dist/src/map/messages/queries/filter-features-in-area.query.d.ts +10 -0
  44. package/dist/src/map/messages/queries/get-features-in-area.query.d.ts +11 -0
  45. package/dist/src/map/models/dictionary.d.ts +17 -0
  46. package/dist/src/map/models/index.d.ts +1 -0
  47. package/dist/src/map/services/drawing/drawing.service.d.ts +2 -0
  48. package/dist/src/map/services/feature.service.d.ts +11 -0
  49. package/dist/src/map/services/map-management.service.d.ts +1 -0
  50. package/dist/src/map/services/message-registrator.service.d.ts +2 -1
  51. package/package.json +2 -2
@@ -8,7 +8,8 @@ import { GeoJSON, WKT } from 'ol/format';
8
8
  import { getCenter, createEmpty, extend } from 'ol/extent';
9
9
  import { get, useGeographic, transform } from 'ol/proj';
10
10
  import { PostboyGenericMessage, PostboyCallbackMessage, PostboyService, PostboyAbstractRegistrator } from '@artstesh/postboy';
11
- import { first, filter, auditTime } from 'rxjs/operators';
11
+ import { forkJoin, combineLatest } from 'rxjs';
12
+ import { tap, first, filter, auditTime } from 'rxjs/operators';
12
13
  import { Vector, XYZ } from 'ol/source';
13
14
  import { Draw } from 'ol/interaction';
14
15
  import { createRegularPolygon } from 'ol/interaction/Draw';
@@ -18,7 +19,6 @@ import { Vector as Vector$1 } from 'ol/layer';
18
19
  import { bbox } from 'ol/loadingstrategy';
19
20
  import Polygon, { fromExtent } from 'ol/geom/Polygon';
20
21
  import Cluster from 'ol/source/Cluster';
21
- import { combineLatest } from 'rxjs';
22
22
  import Map from 'ol/Map';
23
23
  import View from 'ol/View';
24
24
  import Overlay from 'ol/Overlay';
@@ -188,6 +188,62 @@ var FeatureOutputFormat;
188
188
  FeatureOutputFormat[FeatureOutputFormat["WKT"] = 2] = "WKT";
189
189
  })(FeatureOutputFormat || (FeatureOutputFormat = {}));
190
190
 
191
+ class Dictionary {
192
+ constructor() {
193
+ this.collection = {};
194
+ this._keys = new Set();
195
+ this.has = (key) => this._keys.has(key);
196
+ }
197
+ get keys() {
198
+ return Array.from(this._keys);
199
+ }
200
+ get size() {
201
+ return this._keys.size;
202
+ }
203
+ static clone(dic, action) {
204
+ return Dictionary.create(dic.collection, action);
205
+ }
206
+ static create(dic, action) {
207
+ let keyList = Object.keys(dic);
208
+ const result = new Dictionary();
209
+ for (let i = 0; i < keyList.length; i++) {
210
+ let key = keyList[i];
211
+ result._keys.add(key);
212
+ result.collection[key] = action ? action(dic[key], key) : dic[key];
213
+ }
214
+ return result;
215
+ }
216
+ find(predicate) {
217
+ let result = null;
218
+ this.forEach((e) => {
219
+ if (result === null && predicate(e))
220
+ result = e;
221
+ });
222
+ return result;
223
+ }
224
+ take(key) {
225
+ return this._keys.has(key) ? this.collection[key] : null;
226
+ }
227
+ put(key, value) {
228
+ if (value == null)
229
+ return;
230
+ this.collection[key] = value;
231
+ this._keys.add(key);
232
+ }
233
+ rmv(key) {
234
+ if (!this._keys.has(key))
235
+ return;
236
+ delete this.collection[key];
237
+ this._keys.delete(key);
238
+ }
239
+ forEach(callback) {
240
+ let keys = Object.keys(this.collection);
241
+ for (let i = 0; i < keys.length; i++) {
242
+ callback(this.collection[keys[i]], i);
243
+ }
244
+ }
245
+ }
246
+
191
247
  class MapRenderedEvent extends PostboyGenericMessage {
192
248
  constructor(map) {
193
249
  super();
@@ -255,6 +311,19 @@ class CancelDrawingCommand extends PostboyGenericMessage {
255
311
  }
256
312
  CancelDrawingCommand.ID = '7d38d983-feba-4176-a66b-18175e5ecd6b';
257
313
 
314
+ class DrawSelectionAreaCommand extends PostboyCallbackMessage {
315
+ constructor(type, style, ignore = new Set()) {
316
+ super();
317
+ this.type = type;
318
+ this.style = style;
319
+ this.ignore = ignore;
320
+ }
321
+ get id() {
322
+ return DrawSelectionAreaCommand.ID;
323
+ }
324
+ }
325
+ DrawSelectionAreaCommand.ID = '573d8a0d-f25b-42b7-9ad7-0ac6d86ac362';
326
+
258
327
  class AddLayerCommand extends PostboyGenericMessage {
259
328
  constructor(layer) {
260
329
  super();
@@ -357,6 +426,30 @@ class GenerateDrawQuery extends PostboyCallbackMessage {
357
426
  }
358
427
  GenerateDrawQuery.ID = 'f01c99ba-0953-4ab5-82f9-04e6fbb678c1';
359
428
 
429
+ class FilterFeaturesInAreaQuery extends PostboyCallbackMessage {
430
+ constructor(area, features) {
431
+ super();
432
+ this.area = area;
433
+ this.features = features;
434
+ }
435
+ get id() {
436
+ return FilterFeaturesInAreaQuery.ID;
437
+ }
438
+ }
439
+ FilterFeaturesInAreaQuery.ID = '36bb2d94-8028-4512-90dd-2386af3fc67c';
440
+
441
+ class GetFeaturesInAreaQuery extends PostboyCallbackMessage {
442
+ constructor(area, ignore = new Set()) {
443
+ super();
444
+ this.area = area;
445
+ this.ignore = ignore;
446
+ }
447
+ get id() {
448
+ return GetFeaturesInAreaQuery.ID;
449
+ }
450
+ }
451
+ GetFeaturesInAreaQuery.ID = 'efcf4271-a07a-40e0-9f02-d4dade40b8ac';
452
+
360
453
  class MapPostboyService extends PostboyService {
361
454
  constructor() {
362
455
  super();
@@ -372,7 +465,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
372
465
  class MapManagementService {
373
466
  constructor(postboy) {
374
467
  this.postboy = postboy;
375
- this.layers = {};
468
+ this.layers = new Dictionary();
376
469
  }
377
470
  up() {
378
471
  this.observeMapRender();
@@ -382,6 +475,7 @@ class MapManagementService {
382
475
  this.observeAddTile();
383
476
  this.observeRemoveTile();
384
477
  this.observeLayerQuery();
478
+ this.observeFeaturesInArea();
385
479
  }
386
480
  observeRemoveTile() {
387
481
  this.postboy.subscribe(RemoveTileCommand.ID).subscribe((c) => {
@@ -391,7 +485,7 @@ class MapManagementService {
391
485
  });
392
486
  }
393
487
  observeLayerQuery() {
394
- this.postboy.subscribe(GetLayerQuery.ID).subscribe((ev) => { var _a; return ev.finish((_a = this.layers[ev.name]) !== null && _a !== void 0 ? _a : null); });
488
+ this.postboy.subscribe(GetLayerQuery.ID).subscribe((ev) => ev.finish(this.layers.take(ev.name)));
395
489
  }
396
490
  observeAddTile() {
397
491
  this.postboy.subscribe(AddTileCommand.ID).subscribe((c) => {
@@ -409,18 +503,18 @@ class MapManagementService {
409
503
  this.postboy.subscribe(AddLayerCommand.ID).subscribe((c) => {
410
504
  if (!this.map)
411
505
  return;
412
- this.layers[c.layer.get('name')] = c.layer;
506
+ this.layers.put(c.layer.get('name'), c.layer);
413
507
  this.map.addLayer(c.layer);
414
508
  });
415
509
  }
416
510
  observePlaceFeatures() {
417
511
  this.postboy.subscribe(PlaceLayerFeaturesCommand.ID).subscribe((c) => {
418
- var _a, _b;
419
- if (!this.layers[c.layer])
512
+ var _a;
513
+ if (!this.layers.has(c.layer))
420
514
  return;
421
- let source = (_a = this.layers[c.layer]) === null || _a === void 0 ? void 0 : _a.getSource();
515
+ let source = this.layers.take(c.layer).getSource();
422
516
  if (!!source['getSource'])
423
- source = (_b = source) === null || _b === void 0 ? void 0 : _b.getSource();
517
+ source = (_a = source) === null || _a === void 0 ? void 0 : _a.getSource();
424
518
  source === null || source === void 0 ? void 0 : source.clear();
425
519
  source === null || source === void 0 ? void 0 : source.addFeatures(c.features);
426
520
  });
@@ -429,10 +523,33 @@ class MapManagementService {
429
523
  this.postboy.subscribe(RemoveLayerCommand.ID).subscribe((c) => {
430
524
  if (!this.map)
431
525
  return;
432
- delete this.layers[c.layer.get('name')];
526
+ this.layers.rmv(c.layer.get('name'));
433
527
  this.map.removeLayer(c.layer);
434
528
  });
435
529
  }
530
+ observeFeaturesInArea() {
531
+ this.postboy.subscribe(GetFeaturesInAreaQuery.ID).subscribe((qr) => {
532
+ let result = new Dictionary();
533
+ const queue = [];
534
+ const queries = [];
535
+ this.layers.forEach((l) => {
536
+ var _a, _b;
537
+ let layerName = l.get('name');
538
+ if (qr.ignore.has(layerName) || layerName === MapConstants.DrawingLayerId)
539
+ return;
540
+ let source = l.getSource();
541
+ if (!!source['getSource'])
542
+ source = (_a = source) === null || _a === void 0 ? void 0 : _a.getSource();
543
+ const query = new FilterFeaturesInAreaQuery(qr.area, (_b = source === null || source === void 0 ? void 0 : source.getFeatures()) !== null && _b !== void 0 ? _b : []);
544
+ queue.push(query.result.pipe(tap((r) => {
545
+ result.put(l.get('name'), r.map((e) => (Object.assign({ id: e.getId() }, e.get(MapConstants.FeatureInfo)))));
546
+ })));
547
+ queries.push(query);
548
+ });
549
+ forkJoin(queue).subscribe(() => qr.finish(result));
550
+ queries.forEach((q) => this.postboy.fire(q));
551
+ });
552
+ }
436
553
  }
437
554
  MapManagementService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapManagementService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
438
555
  MapManagementService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapManagementService });
@@ -550,6 +667,27 @@ class DrawingService {
550
667
  this.postboy = postboy;
551
668
  }
552
669
  up() {
670
+ this.observeDrawing();
671
+ this.observeSelectArea();
672
+ this.observeMapRender();
673
+ }
674
+ observeSelectArea() {
675
+ this.postboy.subscribe(DrawSelectionAreaCommand.ID).subscribe((ev) => {
676
+ const drawingCommand = new StartDrawingCommand(ev.type, ev.style);
677
+ drawingCommand.result.subscribe((r) => {
678
+ if (!r) {
679
+ ev.finish(new Dictionary());
680
+ return;
681
+ }
682
+ const area = PolygonModel.fromGeoJson(1, r).feature.getGeometry();
683
+ const getFeaturesCommand = new GetFeaturesInAreaQuery(area, ev.ignore);
684
+ getFeaturesCommand.result.subscribe((result) => ev.finish(result));
685
+ this.postboy.fire(getFeaturesCommand);
686
+ });
687
+ this.postboy.fire(drawingCommand);
688
+ });
689
+ }
690
+ observeDrawing() {
553
691
  this.postboy.subscribe(StartDrawingCommand.ID).subscribe((ev) => {
554
692
  this.draw((l) => {
555
693
  if (!l || !this.map) {
@@ -570,7 +708,6 @@ class DrawingService {
570
708
  this.postboy.fire(drawQuery);
571
709
  });
572
710
  });
573
- this.observeMapRender();
574
711
  }
575
712
  onEnd(evt, command, layer) {
576
713
  command.finish(command.format === FeatureOutputFormat.GeoJson
@@ -633,10 +770,35 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
633
770
  type: Injectable
634
771
  }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
635
772
 
773
+ class FeatureService {
774
+ constructor(postboy) {
775
+ this.postboy = postboy;
776
+ }
777
+ up() {
778
+ this.postboy.subscribe(FilterFeaturesInAreaQuery.ID).subscribe((qr) => {
779
+ qr.finish(qr.features.filter((f) => FeatureService.booleanIntersects(qr.area, f.getGeometry())));
780
+ });
781
+ }
782
+ static booleanIntersects(g1, g2) {
783
+ if (g2.getType() === 'Point')
784
+ return g1.intersectsCoordinate(g2.getCoordinates());
785
+ if (g2.getType() === 'Circle')
786
+ return g1.intersectsCoordinate(g2.getCenter());
787
+ if (g2.getType() === 'Polygon')
788
+ return g1.intersectsCoordinate(g2.getInteriorPoint().getCoordinates());
789
+ return false;
790
+ }
791
+ }
792
+ FeatureService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FeatureService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
793
+ FeatureService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FeatureService });
794
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FeatureService, decorators: [{
795
+ type: Injectable
796
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
797
+
636
798
  class MessageRegistratorService extends PostboyAbstractRegistrator {
637
- constructor(service, management, state, feature, interaction, drawing, drawGenerator) {
799
+ constructor(service, management, state, mapFeature, interaction, drawing, drawGenerator, feature) {
638
800
  super(service);
639
- this.registerServices([management, state, interaction, feature, drawing, drawGenerator]);
801
+ this.registerServices([management, state, interaction, mapFeature, drawing, drawGenerator, feature]);
640
802
  }
641
803
  _up() {
642
804
  this.registerReplay(MapRenderedEvent.ID);
@@ -654,13 +816,16 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
654
816
  this.registerSubject(GetLayerQuery.ID);
655
817
  this.registerSubject(DrawingFinishedEvent.ID);
656
818
  this.registerSubject(GenerateDrawQuery.ID);
819
+ this.registerSubject(FilterFeaturesInAreaQuery.ID);
820
+ this.registerSubject(GetFeaturesInAreaQuery.ID);
821
+ this.registerSubject(DrawSelectionAreaCommand.ID);
657
822
  }
658
823
  }
659
- MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapFeatureService }, { token: MapClickService }, { token: DrawingService }, { token: DrawingGenerationService }], target: i0.ɵɵFactoryTarget.Injectable });
824
+ MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapFeatureService }, { token: MapClickService }, { token: DrawingService }, { token: DrawingGenerationService }, { token: FeatureService }], target: i0.ɵɵFactoryTarget.Injectable });
660
825
  MessageRegistratorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService });
661
826
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService, decorators: [{
662
827
  type: Injectable
663
- }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: DrawingGenerationService }]; } });
828
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: DrawingGenerationService }, { type: FeatureService }]; } });
664
829
 
665
830
  class TileLayerSettings {
666
831
  constructor() {
@@ -1238,6 +1403,7 @@ MapPlateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", vers
1238
1403
  MapFeatureService,
1239
1404
  DrawingService,
1240
1405
  DrawingGenerationService,
1406
+ FeatureService,
1241
1407
  ], usesInheritance: true, ngImport: i0, template: "<ng-content></ng-content>\r\n<lib-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></lib-osm-tile-layer>\r\n<lib-feature-layer *ngIf=\"map\" [settings]=\"drawingLayerSettings\"></lib-feature-layer>\r\n", styles: ["lib-map-plate{position:relative;display:flex;flex-direction:column;height:100%}\n"], components: [{ type: OsmTileLayerComponent, selector: "lib-osm-tile-layer", inputs: ["url", "map"] }, { type: FeatureLayerComponent, selector: "lib-feature-layer", inputs: ["settings"] }], directives: [{ type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1242
1408
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapPlateComponent, decorators: [{
1243
1409
  type: Component,
@@ -1254,6 +1420,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1254
1420
  MapFeatureService,
1255
1421
  DrawingService,
1256
1422
  DrawingGenerationService,
1423
+ FeatureService,
1257
1424
  ],
1258
1425
  }]
1259
1426
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MapPostboyService }, { type: MapPlateFactory }, { type: MessageRegistratorService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { settings: [{
@@ -1606,5 +1773,5 @@ class StringifyFeatureHelper {
1606
1773
  * Generated bundle index. Do not edit.
1607
1774
  */
1608
1775
 
1609
- export { CancelDrawingCommand, CloseTooltipCommand, ClusterLayerComponent, ClusterLayerSettings, DrawingType, FeatureLayerComponent, FeatureLayerSettings, FeatureOutputFormat, MapClickEvent, MapLyrs, MapLyrsLabel, MapModule, MapMoveEndEvent, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, OsmTileLayerComponent, PolygonModel, PolygonStyleHelper, PolygonsComponent, StartDrawingCommand, StringifyFeatureHelper, TextStyleHelper, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings };
1776
+ export { CancelDrawingCommand, CloseTooltipCommand, ClusterLayerComponent, ClusterLayerSettings, Dictionary, DrawSelectionAreaCommand, DrawingType, FeatureLayerComponent, FeatureLayerSettings, FeatureOutputFormat, MapClickEvent, MapLyrs, MapLyrsLabel, MapModule, MapMoveEndEvent, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, OsmTileLayerComponent, PolygonModel, PolygonStyleHelper, PolygonsComponent, StartDrawingCommand, StringifyFeatureHelper, TextStyleHelper, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings };
1610
1777
  //# sourceMappingURL=maps-components.js.map