@artstesh/maps 5.1.2 → 5.1.4

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 (45) hide show
  1. package/dist/esm2022/map/map-plate/map-plate.component.mjs +4 -1
  2. package/dist/esm2022/map/messages/commands/add-control.command.mjs +13 -0
  3. package/dist/esm2022/map/messages/commands/remove-control.command.mjs +13 -0
  4. package/dist/esm2022/map/messages/commands/set-map-center.command.mjs +26 -0
  5. package/dist/esm2022/map/messages/index.mjs +4 -1
  6. package/dist/esm2022/map/models/index.mjs +2 -1
  7. package/dist/esm2022/map/models/map-control.mjs +15 -0
  8. package/dist/esm2022/map/models/polygon.model.mjs +4 -1
  9. package/dist/esm2022/map/services/controls/controls.service.mjs +39 -0
  10. package/dist/esm2022/map/services/map-state.service.mjs +19 -4
  11. package/dist/esm2022/map/services/message-registrator.service.mjs +12 -5
  12. package/dist/esm2022/src/map/map-plate/map-plate.component.mjs +4 -1
  13. package/dist/esm2022/src/map/messages/commands/add-control.command.mjs +13 -0
  14. package/dist/esm2022/src/map/messages/commands/remove-control.command.mjs +13 -0
  15. package/dist/esm2022/src/map/messages/commands/set-map-center.command.mjs +26 -0
  16. package/dist/esm2022/src/map/messages/index.mjs +4 -1
  17. package/dist/esm2022/src/map/models/index.mjs +2 -1
  18. package/dist/esm2022/src/map/models/map-control.mjs +15 -0
  19. package/dist/esm2022/src/map/models/polygon.model.mjs +4 -1
  20. package/dist/esm2022/src/map/services/controls/controls.service.mjs +39 -0
  21. package/dist/esm2022/src/map/services/map-state.service.mjs +19 -4
  22. package/dist/esm2022/src/map/services/message-registrator.service.mjs +12 -5
  23. package/dist/fesm2022/maps-components-src-map.mjs +125 -7
  24. package/dist/fesm2022/maps-components-src-map.mjs.map +1 -1
  25. package/dist/fesm2022/maps-components.mjs +125 -7
  26. package/dist/fesm2022/maps-components.mjs.map +1 -1
  27. package/dist/map/messages/commands/add-control.command.d.ts +8 -0
  28. package/dist/map/messages/commands/remove-control.command.d.ts +8 -0
  29. package/dist/map/messages/commands/set-map-center.command.d.ts +18 -0
  30. package/dist/map/messages/index.d.ts +3 -0
  31. package/dist/map/models/index.d.ts +1 -0
  32. package/dist/map/models/map-control.d.ts +13 -0
  33. package/dist/map/services/controls/controls.service.d.ts +14 -0
  34. package/dist/map/services/map-state.service.d.ts +2 -0
  35. package/dist/map/services/message-registrator.service.d.ts +2 -1
  36. package/dist/src/map/messages/commands/add-control.command.d.ts +8 -0
  37. package/dist/src/map/messages/commands/remove-control.command.d.ts +8 -0
  38. package/dist/src/map/messages/commands/set-map-center.command.d.ts +18 -0
  39. package/dist/src/map/messages/index.d.ts +3 -0
  40. package/dist/src/map/models/index.d.ts +1 -0
  41. package/dist/src/map/models/map-control.d.ts +13 -0
  42. package/dist/src/map/services/controls/controls.service.d.ts +14 -0
  43. package/dist/src/map/services/map-state.service.d.ts +2 -0
  44. package/dist/src/map/services/message-registrator.service.d.ts +2 -1
  45. package/package.json +1 -1
@@ -6,11 +6,11 @@ import { Feature, Collection } from 'ol';
6
6
  import { Point, LineString } from 'ol/geom';
7
7
  import { GeoJSON, WKT } from 'ol/format';
8
8
  import { getCenter, createEmpty, extend } from 'ol/extent';
9
+ import { Control, Zoom } from 'ol/control';
9
10
  import { get, useGeographic, transform } from 'ol/proj';
10
11
  import { PostboyGenericMessage, PostboyCallbackMessage, PostboyExecutor, PostboyService, PostboyAbstractRegistrator } from '@artstesh/postboy';
11
12
  import { Draw, Modify, Translate } from 'ol/interaction';
12
13
  import { createRegularPolygon, createBox } from 'ol/interaction/Draw';
13
- import { Zoom } from 'ol/control';
14
14
  import { first, filter, auditTime } from 'rxjs/operators';
15
15
  import { Vector, XYZ } from 'ol/source';
16
16
  import TileLayer from 'ol/layer/Tile';
@@ -176,6 +176,8 @@ class PolygonModel {
176
176
  this.info = info;
177
177
  this.id = id == null ? IdGenerator.get() : id;
178
178
  this._feature = feature;
179
+ if (this.info)
180
+ this._feature?.set(MapConstants.FeatureInfo, this.info);
179
181
  [this.lng, this.lat] = getCenter(this._feature.getGeometry()?.getExtent());
180
182
  }
181
183
  get feature() {
@@ -251,6 +253,20 @@ class Dictionary {
251
253
  }
252
254
  }
253
255
 
256
+ /**
257
+ *
258
+ * A control is a visible widget with a DOM element in a fixed position on the screen. They can involve user input (buttons), or be informational only; the position is determined using CSS. By default these are placed in the container with CSS class name ol-overlaycontainer-stopevent, but can use any outside DOM element.
259
+ * This is the base class for controls. You can use it for simple custom controls by creating the element with listeners, creating an instance:
260
+ * var myControl = new Control({element: myElement}); and then adding this to the map.
261
+ * The main advantage of having this as a control rather than a simple separate DOM element is that preventing propagation is handled for you. Controls will also be objects in a module:ol/Collection~Collection, so you can use their methods.
262
+ * You can also extend this base for your own control class. See examples/custom-controls for an example of how to do this.
263
+ */
264
+ class MapControl extends Control {
265
+ constructor(options) {
266
+ super(options);
267
+ }
268
+ }
269
+
254
270
  class MapRenderedEvent extends PostboyGenericMessage {
255
271
  map;
256
272
  static ID = 'b6121807-3b89-4cd3-82cf-089d2cefdc4f';
@@ -367,6 +383,55 @@ class CancelFeatureModificationCommand extends PostboyGenericMessage {
367
383
  }
368
384
  }
369
385
 
386
+ class AddControlCommand extends PostboyGenericMessage {
387
+ item;
388
+ static ID = '8e1c06eb-b395-4fe1-929c-ebf0805eeb49';
389
+ constructor(item) {
390
+ super();
391
+ this.item = item;
392
+ }
393
+ get id() {
394
+ return AddControlCommand.ID;
395
+ }
396
+ }
397
+
398
+ class RemoveControlCommand extends PostboyGenericMessage {
399
+ item;
400
+ static ID = '361641e0-804a-4930-8c27-0cea6330dbfc';
401
+ constructor(item) {
402
+ super();
403
+ this.item = item;
404
+ }
405
+ get id() {
406
+ return RemoveControlCommand.ID;
407
+ }
408
+ }
409
+
410
+ /**
411
+ * Forces map to move to a specific point
412
+ */
413
+ class SetMapCenterCommand extends PostboyGenericMessage {
414
+ lat;
415
+ lng;
416
+ zoom;
417
+ static ID = 'd50e89c9-6707-4f8c-ab57-65fcef232182';
418
+ /**
419
+ *
420
+ * @param lat - the desired latitude
421
+ * @param lng - the desired longitude
422
+ * @param zoom - the desired zoom; doesn't change zoom if undefined
423
+ */
424
+ constructor(lat, lng, zoom) {
425
+ super();
426
+ this.lat = lat;
427
+ this.lng = lng;
428
+ this.zoom = zoom;
429
+ }
430
+ get id() {
431
+ return SetMapCenterCommand.ID;
432
+ }
433
+ }
434
+
370
435
  class AddLayerCommand extends PostboyGenericMessage {
371
436
  layer;
372
437
  static ID = 'd93e250f-92bc-43ac-9c6a-46c521a1aaa5';
@@ -679,7 +744,14 @@ class MapStateService {
679
744
  this.postboy = postboy;
680
745
  }
681
746
  up() {
682
- this.postboy.subscribe(MapRenderedEvent.ID).subscribe((ev) => {
747
+ this.observeMapRendering();
748
+ this.observeCenter();
749
+ }
750
+ observeMapRendering() {
751
+ this.postboy
752
+ .subscribe(MapRenderedEvent.ID)
753
+ .pipe(first())
754
+ .subscribe((ev) => {
683
755
  this.map = ev.map;
684
756
  this.map?.on('moveend', () => {
685
757
  const zoom = Math.floor(this.map?.getView().getZoom() || -1);
@@ -688,6 +760,13 @@ class MapStateService {
688
760
  });
689
761
  });
690
762
  }
763
+ observeCenter() {
764
+ this.postboy.subscribe(SetMapCenterCommand.ID).subscribe((c) => {
765
+ this.map?.getView().setCenter([c.lng, c.lat]);
766
+ if (c.zoom)
767
+ this.map?.getView().setZoom(c.zoom);
768
+ });
769
+ }
691
770
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MapStateService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
692
771
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MapStateService });
693
772
  }
@@ -953,14 +1032,51 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
953
1032
  type: Injectable
954
1033
  }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
955
1034
 
1035
+ class ControlsService {
1036
+ postboy;
1037
+ map;
1038
+ constructor(postboy) {
1039
+ this.postboy = postboy;
1040
+ }
1041
+ up() {
1042
+ this.observeMapRender();
1043
+ }
1044
+ observeMapRender() {
1045
+ this.postboy
1046
+ .subscribe(MapRenderedEvent.ID)
1047
+ .pipe(first())
1048
+ .subscribe((m) => {
1049
+ this.map = m.map;
1050
+ this.observeAdding();
1051
+ this.observeRemoving();
1052
+ });
1053
+ }
1054
+ observeAdding() {
1055
+ this.postboy.subscribe(AddControlCommand.ID).subscribe((c) => this.map?.addControl(c.item));
1056
+ }
1057
+ observeRemoving() {
1058
+ this.postboy
1059
+ .subscribe(RemoveControlCommand.ID)
1060
+ .subscribe((c) => this.map?.removeControl(c.item));
1061
+ }
1062
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ControlsService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
1063
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ControlsService });
1064
+ }
1065
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ControlsService, decorators: [{
1066
+ type: Injectable
1067
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
1068
+
956
1069
  class MessageRegistratorService extends PostboyAbstractRegistrator {
957
- constructor(service, management, state, mapFeature, interaction, drawing, featureModification) {
1070
+ constructor(service, management, state, mapFeature, interaction, drawing, featureModification, controls) {
958
1071
  super(service);
959
- this.registerServices([management, state, interaction, mapFeature, drawing, featureModification]);
1072
+ this.registerServices([management, state, interaction, mapFeature, drawing, featureModification, controls]);
960
1073
  }
961
1074
  _up() {
962
1075
  this.registerReplay(MapRenderedEvent.ID);
963
1076
  this.registerReplay(PlaceLayerFeaturesCommand.ID);
1077
+ this.registerReplay(RemoveControlCommand.ID);
1078
+ this.registerReplay(AddControlCommand.ID);
1079
+ this.registerReplay(SetMapCenterCommand.ID);
964
1080
  this.registerSubject(AddLayerCommand.ID);
965
1081
  this.registerSubject(RemoveLayerCommand.ID);
966
1082
  this.registerSubject(AddTileCommand.ID);
@@ -984,12 +1100,12 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
984
1100
  this.registerExecutor(GenerateDrawExecutor.ID, (e) => DrawingGenerationService.getDraw(e));
985
1101
  this.registerExecutor(GenerateZoomControlExecutor.ID, (e) => ZoomControlFactory.build(e.settings));
986
1102
  }
987
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapFeatureService }, { token: MapClickService }, { token: DrawingService }, { token: FeatureModificationService }], target: i0.ɵɵFactoryTarget.Injectable });
1103
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapFeatureService }, { token: MapClickService }, { token: DrawingService }, { token: FeatureModificationService }, { token: ControlsService }], target: i0.ɵɵFactoryTarget.Injectable });
988
1104
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageRegistratorService });
989
1105
  }
990
1106
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageRegistratorService, decorators: [{
991
1107
  type: Injectable
992
- }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: FeatureModificationService }]; } });
1108
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: FeatureModificationService }, { type: ControlsService }]; } });
993
1109
 
994
1110
  class TileLayerSettings {
995
1111
  maxZoom = 19;
@@ -1603,6 +1719,7 @@ class MapPlateComponent extends DestructibleComponent {
1603
1719
  DrawingGenerationService,
1604
1720
  FeatureService,
1605
1721
  FeatureModificationService,
1722
+ ControlsService,
1606
1723
  ], usesInheritance: true, ngImport: i0, template: "<ng-content></ng-content>\r\n<art-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></art-osm-tile-layer>\r\n<art-feature-layer *ngIf=\"map\" [settings]=\"drawingLayerSettings\"></art-feature-layer>\r\n", styles: ["art-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: "art-osm-tile-layer", inputs: ["url", "map"] }, { kind: "component", type: FeatureLayerComponent, selector: "art-feature-layer", inputs: ["settings"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1607
1724
  }
1608
1725
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MapPlateComponent, decorators: [{
@@ -1617,6 +1734,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
1617
1734
  DrawingGenerationService,
1618
1735
  FeatureService,
1619
1736
  FeatureModificationService,
1737
+ ControlsService,
1620
1738
  ], template: "<ng-content></ng-content>\r\n<art-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></art-osm-tile-layer>\r\n<art-feature-layer *ngIf=\"map\" [settings]=\"drawingLayerSettings\"></art-feature-layer>\r\n", styles: ["art-map-plate{position:relative;display:flex;flex-direction:column;height:100%}\n"] }]
1621
1739
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MapPostboyService }, { type: MapPlateFactory }, { type: MessageRegistratorService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { settings: [{
1622
1740
  type: Input
@@ -2067,5 +2185,5 @@ class StringifyFeatureHelper {
2067
2185
  * Generated bundle index. Do not edit.
2068
2186
  */
2069
2187
 
2070
- export { CancelDrawingCommand, CancelFeatureModificationCommand, CloseTooltipCommand, ClusterLayerComponent, ClusterLayerSettings, Dictionary, DrawSelectionAreaCommand, DrawingType, FeatureLayerComponent, FeatureLayerSettings, FeatureOutputFormat, MapClickEvent, MapControlZoomComponent, MapLyrs, MapLyrsLabel, MapModule, MapMoveEndEvent, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, ModifyFeatureCommand, OsmTileLayerComponent, PolygonModel, PolygonStyleHelper, PolygonsComponent, StartDrawingCommand, StringifyFeatureHelper, TextStyleHelper, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings, ZoomControlSettings };
2188
+ export { AddControlCommand, CancelDrawingCommand, CancelFeatureModificationCommand, CloseTooltipCommand, ClusterLayerComponent, ClusterLayerSettings, Dictionary, DrawSelectionAreaCommand, DrawingType, FeatureLayerComponent, FeatureLayerSettings, FeatureOutputFormat, MapClickEvent, MapControl, MapControlZoomComponent, MapLyrs, MapLyrsLabel, MapModule, MapMoveEndEvent, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, ModifyFeatureCommand, OsmTileLayerComponent, PolygonModel, PolygonStyleHelper, PolygonsComponent, RemoveControlCommand, SetMapCenterCommand, StartDrawingCommand, StringifyFeatureHelper, TextStyleHelper, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings, ZoomControlSettings };
2071
2189
  //# sourceMappingURL=maps-components.mjs.map