@artstesh/maps 5.1.1 → 5.1.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 (53) hide show
  1. package/dist/esm2022/map/map-plate/features/markers/markers.component.mjs +3 -3
  2. package/dist/esm2022/map/map-plate/features/polygons/polygons.component.mjs +2 -2
  3. package/dist/esm2022/map/map-plate/layers/feature-layer/feature-layer.settings.mjs +47 -1
  4. package/dist/esm2022/map/map-plate/map-plate.component.mjs +4 -1
  5. package/dist/esm2022/map/messages/commands/add-control.command.mjs +13 -0
  6. package/dist/esm2022/map/messages/commands/remove-control.command.mjs +13 -0
  7. package/dist/esm2022/map/messages/commands/set-map-center.command.mjs +26 -0
  8. package/dist/esm2022/map/messages/index.mjs +4 -1
  9. package/dist/esm2022/map/models/index.mjs +2 -1
  10. package/dist/esm2022/map/models/map-control.mjs +15 -0
  11. package/dist/esm2022/map/services/controls/controls.service.mjs +39 -0
  12. package/dist/esm2022/map/services/map-management.service.mjs +2 -2
  13. package/dist/esm2022/map/services/map-state.service.mjs +19 -4
  14. package/dist/esm2022/map/services/message-registrator.service.mjs +12 -5
  15. package/dist/esm2022/src/map/map-plate/features/markers/markers.component.mjs +3 -3
  16. package/dist/esm2022/src/map/map-plate/features/polygons/polygons.component.mjs +2 -2
  17. package/dist/esm2022/src/map/map-plate/layers/feature-layer/feature-layer.settings.mjs +47 -1
  18. package/dist/esm2022/src/map/map-plate/map-plate.component.mjs +4 -1
  19. package/dist/esm2022/src/map/messages/commands/add-control.command.mjs +13 -0
  20. package/dist/esm2022/src/map/messages/commands/remove-control.command.mjs +13 -0
  21. package/dist/esm2022/src/map/messages/commands/set-map-center.command.mjs +26 -0
  22. package/dist/esm2022/src/map/messages/index.mjs +4 -1
  23. package/dist/esm2022/src/map/models/index.mjs +2 -1
  24. package/dist/esm2022/src/map/models/map-control.mjs +15 -0
  25. package/dist/esm2022/src/map/services/controls/controls.service.mjs +39 -0
  26. package/dist/esm2022/src/map/services/map-management.service.mjs +2 -2
  27. package/dist/esm2022/src/map/services/map-state.service.mjs +19 -4
  28. package/dist/esm2022/src/map/services/message-registrator.service.mjs +12 -5
  29. package/dist/fesm2022/maps-components-src-map.mjs +173 -11
  30. package/dist/fesm2022/maps-components-src-map.mjs.map +1 -1
  31. package/dist/fesm2022/maps-components.mjs +173 -11
  32. package/dist/fesm2022/maps-components.mjs.map +1 -1
  33. package/dist/map/map-plate/layers/feature-layer/feature-layer.settings.d.ts +46 -0
  34. package/dist/map/messages/commands/add-control.command.d.ts +8 -0
  35. package/dist/map/messages/commands/remove-control.command.d.ts +8 -0
  36. package/dist/map/messages/commands/set-map-center.command.d.ts +18 -0
  37. package/dist/map/messages/index.d.ts +3 -0
  38. package/dist/map/models/index.d.ts +1 -0
  39. package/dist/map/models/map-control.d.ts +13 -0
  40. package/dist/map/services/controls/controls.service.d.ts +14 -0
  41. package/dist/map/services/map-state.service.d.ts +2 -0
  42. package/dist/map/services/message-registrator.service.d.ts +2 -1
  43. package/dist/src/map/map-plate/layers/feature-layer/feature-layer.settings.d.ts +46 -0
  44. package/dist/src/map/messages/commands/add-control.command.d.ts +8 -0
  45. package/dist/src/map/messages/commands/remove-control.command.d.ts +8 -0
  46. package/dist/src/map/messages/commands/set-map-center.command.d.ts +18 -0
  47. package/dist/src/map/messages/index.d.ts +3 -0
  48. package/dist/src/map/models/index.d.ts +1 -0
  49. package/dist/src/map/models/map-control.d.ts +13 -0
  50. package/dist/src/map/services/controls/controls.service.d.ts +14 -0
  51. package/dist/src/map/services/map-state.service.d.ts +2 -0
  52. package/dist/src/map/services/message-registrator.service.d.ts +2 -1
  53. 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';
@@ -251,6 +251,20 @@ class Dictionary {
251
251
  }
252
252
  }
253
253
 
254
+ /**
255
+ *
256
+ * 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.
257
+ * This is the base class for controls. You can use it for simple custom controls by creating the element with listeners, creating an instance:
258
+ * var myControl = new Control({element: myElement}); and then adding this to the map.
259
+ * 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.
260
+ * You can also extend this base for your own control class. See examples/custom-controls for an example of how to do this.
261
+ */
262
+ class MapControl extends Control {
263
+ constructor(options) {
264
+ super(options);
265
+ }
266
+ }
267
+
254
268
  class MapRenderedEvent extends PostboyGenericMessage {
255
269
  map;
256
270
  static ID = 'b6121807-3b89-4cd3-82cf-089d2cefdc4f';
@@ -367,6 +381,55 @@ class CancelFeatureModificationCommand extends PostboyGenericMessage {
367
381
  }
368
382
  }
369
383
 
384
+ class AddControlCommand extends PostboyGenericMessage {
385
+ item;
386
+ static ID = '8e1c06eb-b395-4fe1-929c-ebf0805eeb49';
387
+ constructor(item) {
388
+ super();
389
+ this.item = item;
390
+ }
391
+ get id() {
392
+ return AddControlCommand.ID;
393
+ }
394
+ }
395
+
396
+ class RemoveControlCommand extends PostboyGenericMessage {
397
+ item;
398
+ static ID = '361641e0-804a-4930-8c27-0cea6330dbfc';
399
+ constructor(item) {
400
+ super();
401
+ this.item = item;
402
+ }
403
+ get id() {
404
+ return RemoveControlCommand.ID;
405
+ }
406
+ }
407
+
408
+ /**
409
+ * Forces map to move to a specific point
410
+ */
411
+ class SetMapCenterCommand extends PostboyGenericMessage {
412
+ lat;
413
+ lng;
414
+ zoom;
415
+ static ID = 'd50e89c9-6707-4f8c-ab57-65fcef232182';
416
+ /**
417
+ *
418
+ * @param lat - the desired latitude
419
+ * @param lng - the desired longitude
420
+ * @param zoom - the desired zoom; doesn't change zoom if undefined
421
+ */
422
+ constructor(lat, lng, zoom) {
423
+ super();
424
+ this.lat = lat;
425
+ this.lng = lng;
426
+ this.zoom = zoom;
427
+ }
428
+ get id() {
429
+ return SetMapCenterCommand.ID;
430
+ }
431
+ }
432
+
370
433
  class AddLayerCommand extends PostboyGenericMessage {
371
434
  layer;
372
435
  static ID = 'd93e250f-92bc-43ac-9c6a-46c521a1aaa5';
@@ -638,7 +701,7 @@ class MapManagementService {
638
701
  if (!!source['getSource'])
639
702
  source = source?.getSource();
640
703
  source?.clear();
641
- source?.addFeatures(c.features);
704
+ !!c.features?.length && source?.addFeatures(c.features);
642
705
  });
643
706
  }
644
707
  observeRemoveLayer() {
@@ -679,7 +742,14 @@ class MapStateService {
679
742
  this.postboy = postboy;
680
743
  }
681
744
  up() {
682
- this.postboy.subscribe(MapRenderedEvent.ID).subscribe((ev) => {
745
+ this.observeMapRendering();
746
+ this.observeCenter();
747
+ }
748
+ observeMapRendering() {
749
+ this.postboy
750
+ .subscribe(MapRenderedEvent.ID)
751
+ .pipe(first())
752
+ .subscribe((ev) => {
683
753
  this.map = ev.map;
684
754
  this.map?.on('moveend', () => {
685
755
  const zoom = Math.floor(this.map?.getView().getZoom() || -1);
@@ -688,6 +758,13 @@ class MapStateService {
688
758
  });
689
759
  });
690
760
  }
761
+ observeCenter() {
762
+ this.postboy.subscribe(SetMapCenterCommand.ID).subscribe((c) => {
763
+ this.map?.getView().setCenter([c.lng, c.lat]);
764
+ if (c.zoom)
765
+ this.map?.getView().setZoom(c.zoom);
766
+ });
767
+ }
691
768
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MapStateService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
692
769
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MapStateService });
693
770
  }
@@ -953,14 +1030,51 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
953
1030
  type: Injectable
954
1031
  }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
955
1032
 
1033
+ class ControlsService {
1034
+ postboy;
1035
+ map;
1036
+ constructor(postboy) {
1037
+ this.postboy = postboy;
1038
+ }
1039
+ up() {
1040
+ this.observeMapRender();
1041
+ }
1042
+ observeMapRender() {
1043
+ this.postboy
1044
+ .subscribe(MapRenderedEvent.ID)
1045
+ .pipe(first())
1046
+ .subscribe((m) => {
1047
+ this.map = m.map;
1048
+ this.observeAdding();
1049
+ this.observeRemoving();
1050
+ });
1051
+ }
1052
+ observeAdding() {
1053
+ this.postboy.subscribe(AddControlCommand.ID).subscribe((c) => this.map?.addControl(c.item));
1054
+ }
1055
+ observeRemoving() {
1056
+ this.postboy
1057
+ .subscribe(RemoveControlCommand.ID)
1058
+ .subscribe((c) => this.map?.removeControl(c.item));
1059
+ }
1060
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ControlsService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
1061
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ControlsService });
1062
+ }
1063
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ControlsService, decorators: [{
1064
+ type: Injectable
1065
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
1066
+
956
1067
  class MessageRegistratorService extends PostboyAbstractRegistrator {
957
- constructor(service, management, state, mapFeature, interaction, drawing, featureModification) {
1068
+ constructor(service, management, state, mapFeature, interaction, drawing, featureModification, controls) {
958
1069
  super(service);
959
- this.registerServices([management, state, interaction, mapFeature, drawing, featureModification]);
1070
+ this.registerServices([management, state, interaction, mapFeature, drawing, featureModification, controls]);
960
1071
  }
961
1072
  _up() {
962
1073
  this.registerReplay(MapRenderedEvent.ID);
963
1074
  this.registerReplay(PlaceLayerFeaturesCommand.ID);
1075
+ this.registerReplay(RemoveControlCommand.ID);
1076
+ this.registerReplay(AddControlCommand.ID);
1077
+ this.registerReplay(SetMapCenterCommand.ID);
964
1078
  this.registerSubject(AddLayerCommand.ID);
965
1079
  this.registerSubject(RemoveLayerCommand.ID);
966
1080
  this.registerSubject(AddTileCommand.ID);
@@ -984,12 +1098,12 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
984
1098
  this.registerExecutor(GenerateDrawExecutor.ID, (e) => DrawingGenerationService.getDraw(e));
985
1099
  this.registerExecutor(GenerateZoomControlExecutor.ID, (e) => ZoomControlFactory.build(e.settings));
986
1100
  }
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 });
1101
+ 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
1102
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageRegistratorService });
989
1103
  }
990
1104
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageRegistratorService, decorators: [{
991
1105
  type: Injectable
992
- }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: FeatureModificationService }]; } });
1106
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: FeatureModificationService }, { type: ControlsService }]; } });
993
1107
 
994
1108
  class TileLayerSettings {
995
1109
  maxZoom = 19;
@@ -1175,12 +1289,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
1175
1289
  type: Input
1176
1290
  }] } });
1177
1291
 
1292
+ /**
1293
+ * A layer that is responsible for showing and styling main features on the map, such as markers and polygons
1294
+ */
1178
1295
  class FeatureLayerSettings {
1296
+ /**
1297
+ * The identifier of the field, it is autogenerated by default, but can be set manually
1298
+ */
1179
1299
  name = IdGenerator.get();
1300
+ /**
1301
+ * The priority of showing - layers with higher zIndex cover others in case of collisions
1302
+ */
1180
1303
  zIndex = 1;
1304
+ /**
1305
+ * The maximum zoom at which the layer is visible. 19 by default
1306
+ */
1181
1307
  maxZoom = 19;
1308
+ /**
1309
+ * The minimum zoom at which the layer is visible. 0 by default
1310
+ */
1182
1311
  minZoom = 0;
1312
+ /**
1313
+ * The styling definition of layer's features. The easiest way is to use {@link PolygonStyleHelper},{@link MarkerStyleHelper}
1314
+ */
1183
1315
  style;
1316
+ /**
1317
+ * Creates a clone of the existing settings
1318
+ * @param model
1319
+ */
1184
1320
  static copy(model) {
1185
1321
  const result = new FeatureLayerSettings();
1186
1322
  result.name = model.name;
@@ -1190,21 +1326,45 @@ class FeatureLayerSettings {
1190
1326
  result.style = model.style;
1191
1327
  return result;
1192
1328
  }
1329
+ /**
1330
+ Setter for {@link FeatureLayerSettings.zIndex}
1331
+ * @param zIndex
1332
+ */
1193
1333
  setZIndex(zIndex) {
1194
1334
  return FeatureLayerSettings.copy({ ...this, zIndex });
1195
1335
  }
1336
+ /**
1337
+ * Setter for {@link FeatureLayerSettings.name}
1338
+ * @param name
1339
+ */
1196
1340
  setName(name) {
1197
1341
  return FeatureLayerSettings.copy({ ...this, name });
1198
1342
  }
1343
+ /**
1344
+ * Setter for {@link FeatureLayerSettings.maxZoom}
1345
+ * @param maxZoom
1346
+ */
1199
1347
  setMaxZoom(maxZoom) {
1200
1348
  return FeatureLayerSettings.copy({ ...this, maxZoom });
1201
1349
  }
1350
+ /**
1351
+ * Setter for {@link FeatureLayerSettings.minZoom}
1352
+ * @param minZoom
1353
+ */
1202
1354
  setMinZoom(minZoom) {
1203
1355
  return FeatureLayerSettings.copy({ ...this, minZoom });
1204
1356
  }
1357
+ /**
1358
+ * Setter for {@link FeatureLayerSettings.style}
1359
+ * @param style
1360
+ */
1205
1361
  setStyle(style) {
1206
1362
  return FeatureLayerSettings.copy({ ...this, style });
1207
1363
  }
1364
+ /**
1365
+ * Checks if the model has the same content
1366
+ * @param model - the object to compare
1367
+ */
1208
1368
  isSame(model) {
1209
1369
  if (this.maxZoom !== model.maxZoom)
1210
1370
  return false;
@@ -1557,6 +1717,7 @@ class MapPlateComponent extends DestructibleComponent {
1557
1717
  DrawingGenerationService,
1558
1718
  FeatureService,
1559
1719
  FeatureModificationService,
1720
+ ControlsService,
1560
1721
  ], 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 });
1561
1722
  }
1562
1723
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MapPlateComponent, decorators: [{
@@ -1571,6 +1732,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
1571
1732
  DrawingGenerationService,
1572
1733
  FeatureService,
1573
1734
  FeatureModificationService,
1735
+ ControlsService,
1574
1736
  ], 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"] }]
1575
1737
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MapPostboyService }, { type: MapPlateFactory }, { type: MessageRegistratorService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { settings: [{
1576
1738
  type: Input
@@ -1585,7 +1747,7 @@ class MarkersComponent extends DestructibleComponent {
1585
1747
  }
1586
1748
  _markers = [];
1587
1749
  set markers(value) {
1588
- this._markers = value;
1750
+ this._markers = value ?? [];
1589
1751
  this.putMarkers();
1590
1752
  }
1591
1753
  ngOnInit() {
@@ -1595,7 +1757,7 @@ class MarkersComponent extends DestructibleComponent {
1595
1757
  .subscribe(() => this.putMarkers());
1596
1758
  }
1597
1759
  putMarkers() {
1598
- if (!this._markers?.length)
1760
+ if (!this._markers)
1599
1761
  return;
1600
1762
  this.postboy.fire(new PlaceLayerFeaturesCommand(this.layerName, this._markers.map((m) => m.feature)));
1601
1763
  }
@@ -1722,7 +1884,7 @@ class PolygonsComponent extends DestructibleComponent {
1722
1884
  }
1723
1885
  _polygons = [];
1724
1886
  set polygons(value) {
1725
- this._polygons = value;
1887
+ this._polygons = value ?? [];
1726
1888
  this.putPolygons();
1727
1889
  }
1728
1890
  ngOnInit() {
@@ -2021,5 +2183,5 @@ class StringifyFeatureHelper {
2021
2183
  * Generated bundle index. Do not edit.
2022
2184
  */
2023
2185
 
2024
- 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 };
2186
+ 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 };
2025
2187
  //# sourceMappingURL=maps-components.mjs.map