@artstesh/maps 1.1.2 → 1.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 (49) hide show
  1. package/dist/bundles/maps-components-src-map.umd.js +156 -12
  2. package/dist/bundles/maps-components-src-map.umd.js.map +1 -1
  3. package/dist/bundles/maps-components.umd.js +156 -12
  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/add-control.command.js +12 -0
  7. package/dist/esm2015/map/messages/commands/remove-control.command.js +12 -0
  8. package/dist/esm2015/map/messages/commands/set-map-center.command.js +23 -0
  9. package/dist/esm2015/map/messages/index.js +4 -1
  10. package/dist/esm2015/map/models/index.js +2 -1
  11. package/dist/esm2015/map/models/map-control.js +15 -0
  12. package/dist/esm2015/map/models/polygon.model.js +6 -3
  13. package/dist/esm2015/map/services/controls/controls.service.js +37 -0
  14. package/dist/esm2015/map/services/map-state.service.js +20 -4
  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/add-control.command.js +12 -0
  18. package/dist/esm2015/src/map/messages/commands/remove-control.command.js +12 -0
  19. package/dist/esm2015/src/map/messages/commands/set-map-center.command.js +23 -0
  20. package/dist/esm2015/src/map/messages/index.js +4 -1
  21. package/dist/esm2015/src/map/models/index.js +2 -1
  22. package/dist/esm2015/src/map/models/map-control.js +15 -0
  23. package/dist/esm2015/src/map/models/polygon.model.js +6 -3
  24. package/dist/esm2015/src/map/services/controls/controls.service.js +37 -0
  25. package/dist/esm2015/src/map/services/map-state.service.js +20 -4
  26. package/dist/esm2015/src/map/services/message-registrator.service.js +12 -5
  27. package/dist/fesm2015/maps-components-src-map.js +121 -9
  28. package/dist/fesm2015/maps-components-src-map.js.map +1 -1
  29. package/dist/fesm2015/maps-components.js +121 -9
  30. package/dist/fesm2015/maps-components.js.map +1 -1
  31. package/dist/map/messages/commands/add-control.command.d.ts +8 -0
  32. package/dist/map/messages/commands/remove-control.command.d.ts +8 -0
  33. package/dist/map/messages/commands/set-map-center.command.d.ts +18 -0
  34. package/dist/map/messages/index.d.ts +3 -0
  35. package/dist/map/models/index.d.ts +1 -0
  36. package/dist/map/models/map-control.d.ts +13 -0
  37. package/dist/map/services/controls/controls.service.d.ts +14 -0
  38. package/dist/map/services/map-state.service.d.ts +2 -0
  39. package/dist/map/services/message-registrator.service.d.ts +2 -1
  40. package/dist/src/map/messages/commands/add-control.command.d.ts +8 -0
  41. package/dist/src/map/messages/commands/remove-control.command.d.ts +8 -0
  42. package/dist/src/map/messages/commands/set-map-center.command.d.ts +18 -0
  43. package/dist/src/map/messages/index.d.ts +3 -0
  44. package/dist/src/map/models/index.d.ts +1 -0
  45. package/dist/src/map/models/map-control.d.ts +13 -0
  46. package/dist/src/map/services/controls/controls.service.d.ts +14 -0
  47. package/dist/src/map/services/map-state.service.d.ts +2 -0
  48. package/dist/src/map/services/message-registrator.service.d.ts +2 -1
  49. 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';
@@ -156,11 +156,13 @@ class MarkerModel {
156
156
 
157
157
  class PolygonModel {
158
158
  constructor(feature, id, info) {
159
- var _a;
159
+ var _a, _b;
160
160
  this.info = info;
161
161
  this.id = id == null ? IdGenerator.get() : id;
162
162
  this._feature = feature;
163
- [this.lng, this.lat] = getCenter((_a = this._feature.getGeometry()) === null || _a === void 0 ? void 0 : _a.getExtent());
163
+ if (this.info)
164
+ (_a = this._feature) === null || _a === void 0 ? void 0 : _a.set(MapConstants.FeatureInfo, this.info);
165
+ [this.lng, this.lat] = getCenter((_b = this._feature.getGeometry()) === null || _b === void 0 ? void 0 : _b.getExtent());
164
166
  }
165
167
  static fromGeoJson(id, json, info) {
166
168
  let feature = new GeoJSON().readFeature(json);
@@ -247,6 +249,20 @@ class Dictionary {
247
249
  }
248
250
  }
249
251
 
252
+ /**
253
+ *
254
+ * 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.
255
+ * This is the base class for controls. You can use it for simple custom controls by creating the element with listeners, creating an instance:
256
+ * var myControl = new Control({element: myElement}); and then adding this to the map.
257
+ * 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.
258
+ * You can also extend this base for your own control class. See examples/custom-controls for an example of how to do this.
259
+ */
260
+ class MapControl extends Control {
261
+ constructor(options) {
262
+ super(options);
263
+ }
264
+ }
265
+
250
266
  class MapRenderedEvent extends PostboyGenericMessage {
251
267
  constructor(map) {
252
268
  super();
@@ -347,6 +363,50 @@ class CancelFeatureModificationCommand extends PostboyGenericMessage {
347
363
  }
348
364
  CancelFeatureModificationCommand.ID = '9c9fb40f-ea95-4704-8177-0e9ecabf36fa';
349
365
 
366
+ class AddControlCommand extends PostboyGenericMessage {
367
+ constructor(item) {
368
+ super();
369
+ this.item = item;
370
+ }
371
+ get id() {
372
+ return AddControlCommand.ID;
373
+ }
374
+ }
375
+ AddControlCommand.ID = '8e1c06eb-b395-4fe1-929c-ebf0805eeb49';
376
+
377
+ class RemoveControlCommand extends PostboyGenericMessage {
378
+ constructor(item) {
379
+ super();
380
+ this.item = item;
381
+ }
382
+ get id() {
383
+ return RemoveControlCommand.ID;
384
+ }
385
+ }
386
+ RemoveControlCommand.ID = '361641e0-804a-4930-8c27-0cea6330dbfc';
387
+
388
+ /**
389
+ * Forces map to move to a specific point
390
+ */
391
+ class SetMapCenterCommand extends PostboyGenericMessage {
392
+ /**
393
+ *
394
+ * @param lat - the desired latitude
395
+ * @param lng - the desired longitude
396
+ * @param zoom - the desired zoom; doesn't change zoom if undefined
397
+ */
398
+ constructor(lat, lng, zoom) {
399
+ super();
400
+ this.lat = lat;
401
+ this.lng = lng;
402
+ this.zoom = zoom;
403
+ }
404
+ get id() {
405
+ return SetMapCenterCommand.ID;
406
+ }
407
+ }
408
+ SetMapCenterCommand.ID = 'd50e89c9-6707-4f8c-ab57-65fcef232182';
409
+
350
410
  class AddLayerCommand extends PostboyGenericMessage {
351
411
  constructor(layer) {
352
412
  super();
@@ -640,7 +700,14 @@ class MapStateService {
640
700
  this.postboy = postboy;
641
701
  }
642
702
  up() {
643
- this.postboy.subscribe(MapRenderedEvent.ID).subscribe((ev) => {
703
+ this.observeMapRendering();
704
+ this.observeCenter();
705
+ }
706
+ observeMapRendering() {
707
+ this.postboy
708
+ .subscribe(MapRenderedEvent.ID)
709
+ .pipe(first())
710
+ .subscribe((ev) => {
644
711
  var _a;
645
712
  this.map = ev.map;
646
713
  (_a = this.map) === null || _a === void 0 ? void 0 : _a.on('moveend', () => {
@@ -651,6 +718,14 @@ class MapStateService {
651
718
  });
652
719
  });
653
720
  }
721
+ observeCenter() {
722
+ this.postboy.subscribe(SetMapCenterCommand.ID).subscribe((c) => {
723
+ var _a, _b;
724
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.getView().setCenter([c.lng, c.lat]);
725
+ if (c.zoom)
726
+ (_b = this.map) === null || _b === void 0 ? void 0 : _b.getView().setZoom(c.zoom);
727
+ });
728
+ }
654
729
  }
655
730
  MapStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapStateService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
656
731
  MapStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapStateService });
@@ -914,14 +989,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
914
989
  type: Injectable
915
990
  }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
916
991
 
992
+ class ControlsService {
993
+ constructor(postboy) {
994
+ this.postboy = postboy;
995
+ }
996
+ up() {
997
+ this.observeMapRender();
998
+ }
999
+ observeMapRender() {
1000
+ this.postboy
1001
+ .subscribe(MapRenderedEvent.ID)
1002
+ .pipe(first())
1003
+ .subscribe((m) => {
1004
+ this.map = m.map;
1005
+ this.observeAdding();
1006
+ this.observeRemoving();
1007
+ });
1008
+ }
1009
+ observeAdding() {
1010
+ this.postboy.subscribe(AddControlCommand.ID).subscribe((c) => { var _a; return (_a = this.map) === null || _a === void 0 ? void 0 : _a.addControl(c.item); });
1011
+ }
1012
+ observeRemoving() {
1013
+ this.postboy
1014
+ .subscribe(RemoveControlCommand.ID)
1015
+ .subscribe((c) => { var _a; return (_a = this.map) === null || _a === void 0 ? void 0 : _a.removeControl(c.item); });
1016
+ }
1017
+ }
1018
+ ControlsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ControlsService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
1019
+ ControlsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ControlsService });
1020
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ControlsService, decorators: [{
1021
+ type: Injectable
1022
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
1023
+
917
1024
  class MessageRegistratorService extends PostboyAbstractRegistrator {
918
- constructor(service, management, state, mapFeature, interaction, drawing, featureModification) {
1025
+ constructor(service, management, state, mapFeature, interaction, drawing, featureModification, controls) {
919
1026
  super(service);
920
- this.registerServices([management, state, interaction, mapFeature, drawing, featureModification]);
1027
+ this.registerServices([management, state, interaction, mapFeature, drawing, featureModification, controls]);
921
1028
  }
922
1029
  _up() {
923
1030
  this.registerReplay(MapRenderedEvent.ID);
924
1031
  this.registerReplay(PlaceLayerFeaturesCommand.ID);
1032
+ this.registerReplay(RemoveControlCommand.ID);
1033
+ this.registerReplay(AddControlCommand.ID);
1034
+ this.registerReplay(SetMapCenterCommand.ID);
925
1035
  this.registerSubject(AddLayerCommand.ID);
926
1036
  this.registerSubject(RemoveLayerCommand.ID);
927
1037
  this.registerSubject(AddTileCommand.ID);
@@ -946,11 +1056,11 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
946
1056
  this.registerExecutor(GenerateZoomControlExecutor.ID, (e) => ZoomControlFactory.build(e.settings));
947
1057
  }
948
1058
  }
949
- 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: FeatureModificationService }], target: i0.ɵɵFactoryTarget.Injectable });
1059
+ 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: FeatureModificationService }, { token: ControlsService }], target: i0.ɵɵFactoryTarget.Injectable });
950
1060
  MessageRegistratorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService });
951
1061
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService, decorators: [{
952
1062
  type: Injectable
953
- }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: FeatureModificationService }]; } });
1063
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: FeatureModificationService }, { type: ControlsService }]; } });
954
1064
 
955
1065
  class TileLayerSettings {
956
1066
  constructor() {
@@ -1573,6 +1683,7 @@ MapPlateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", vers
1573
1683
  DrawingGenerationService,
1574
1684
  FeatureService,
1575
1685
  FeatureModificationService,
1686
+ ControlsService,
1576
1687
  ], 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"], components: [{ type: OsmTileLayerComponent, selector: "art-osm-tile-layer", inputs: ["url", "map"] }, { type: FeatureLayerComponent, selector: "art-feature-layer", inputs: ["settings"] }], directives: [{ type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1577
1688
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapPlateComponent, decorators: [{
1578
1689
  type: Component,
@@ -1591,6 +1702,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1591
1702
  DrawingGenerationService,
1592
1703
  FeatureService,
1593
1704
  FeatureModificationService,
1705
+ ControlsService,
1594
1706
  ],
1595
1707
  }]
1596
1708
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MapPostboyService }, { type: MapPlateFactory }, { type: MessageRegistratorService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { settings: [{
@@ -2056,5 +2168,5 @@ class StringifyFeatureHelper {
2056
2168
  * Generated bundle index. Do not edit.
2057
2169
  */
2058
2170
 
2059
- 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 };
2171
+ 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 };
2060
2172
  //# sourceMappingURL=maps-components.js.map