@artstesh/maps 1.0.4 → 1.0.6

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 (69) hide show
  1. package/dist/bundles/maps-components-src-map.umd.js +259 -7
  2. package/dist/bundles/maps-components-src-map.umd.js.map +1 -1
  3. package/dist/bundles/maps-components.umd.js +259 -7
  4. package/dist/bundles/maps-components.umd.js.map +1 -1
  5. package/dist/esm2015/map/helpers/index.js +2 -1
  6. package/dist/esm2015/map/helpers/polygon-style.helper.js +16 -0
  7. package/dist/esm2015/map/map-plate/features/index.js +2 -1
  8. package/dist/esm2015/map/map-plate/features/polygons/polygons.component.js +47 -0
  9. package/dist/esm2015/map/map-plate/layers/feature-layer/feature-layer.component.js +1 -1
  10. package/dist/esm2015/map/map-plate/tooltips/index.js +3 -0
  11. package/dist/esm2015/map/map-plate/tooltips/tooltip/tooltip.component.js +84 -0
  12. package/dist/esm2015/map/map-plate/tooltips/tooltip/tooltip.settings.js +30 -0
  13. package/dist/esm2015/map/map.module.js +21 -3
  14. package/dist/esm2015/map/messages/commands/close-tooltip.command.js +12 -0
  15. package/dist/esm2015/map/messages/index.js +2 -1
  16. package/dist/esm2015/map/models/index.js +2 -1
  17. package/dist/esm2015/map/models/polygon.model.js +26 -0
  18. package/dist/esm2015/map/public-api.js +2 -1
  19. package/dist/esm2015/map/services/map-click.service.js +2 -2
  20. package/dist/esm2015/map/services/message-registrator.service.js +3 -1
  21. package/dist/esm2015/src/map/helpers/index.js +2 -1
  22. package/dist/esm2015/src/map/helpers/polygon-style.helper.js +16 -0
  23. package/dist/esm2015/src/map/map-plate/features/index.js +2 -1
  24. package/dist/esm2015/src/map/map-plate/features/polygons/polygons.component.js +47 -0
  25. package/dist/esm2015/src/map/map-plate/layers/feature-layer/feature-layer.component.js +1 -1
  26. package/dist/esm2015/src/map/map-plate/tooltips/index.js +3 -0
  27. package/dist/esm2015/src/map/map-plate/tooltips/tooltip/tooltip.component.js +84 -0
  28. package/dist/esm2015/src/map/map-plate/tooltips/tooltip/tooltip.settings.js +30 -0
  29. package/dist/esm2015/src/map/map.module.js +21 -3
  30. package/dist/esm2015/src/map/messages/commands/close-tooltip.command.js +12 -0
  31. package/dist/esm2015/src/map/messages/index.js +2 -1
  32. package/dist/esm2015/src/map/models/index.js +2 -1
  33. package/dist/esm2015/src/map/models/polygon.model.js +26 -0
  34. package/dist/esm2015/src/map/public-api.js +2 -1
  35. package/dist/esm2015/src/map/services/map-click.service.js +2 -2
  36. package/dist/esm2015/src/map/services/message-registrator.service.js +3 -1
  37. package/dist/fesm2015/maps-components-src-map.js +217 -5
  38. package/dist/fesm2015/maps-components-src-map.js.map +1 -1
  39. package/dist/fesm2015/maps-components.js +217 -5
  40. package/dist/fesm2015/maps-components.js.map +1 -1
  41. package/dist/map/helpers/index.d.ts +1 -0
  42. package/dist/map/helpers/polygon-style.helper.d.ts +4 -0
  43. package/dist/map/map-plate/features/index.d.ts +1 -0
  44. package/dist/map/map-plate/features/polygons/polygons.component.d.ts +16 -0
  45. package/dist/map/map-plate/layers/feature-layer/feature-layer.component.d.ts +1 -1
  46. package/dist/map/map-plate/tooltips/index.d.ts +2 -0
  47. package/dist/map/map-plate/tooltips/tooltip/tooltip.component.d.ts +26 -0
  48. package/dist/map/map-plate/tooltips/tooltip/tooltip.settings.d.ts +11 -0
  49. package/dist/map/map.module.d.ts +4 -2
  50. package/dist/map/messages/commands/close-tooltip.command.d.ts +7 -0
  51. package/dist/map/messages/index.d.ts +1 -0
  52. package/dist/map/models/index.d.ts +1 -0
  53. package/dist/map/models/polygon.model.d.ts +19 -0
  54. package/dist/map/public-api.d.ts +1 -0
  55. package/dist/src/map/helpers/index.d.ts +1 -0
  56. package/dist/src/map/helpers/polygon-style.helper.d.ts +4 -0
  57. package/dist/src/map/map-plate/features/index.d.ts +1 -0
  58. package/dist/src/map/map-plate/features/polygons/polygons.component.d.ts +16 -0
  59. package/dist/src/map/map-plate/layers/feature-layer/feature-layer.component.d.ts +1 -1
  60. package/dist/src/map/map-plate/tooltips/index.d.ts +2 -0
  61. package/dist/src/map/map-plate/tooltips/tooltip/tooltip.component.d.ts +26 -0
  62. package/dist/src/map/map-plate/tooltips/tooltip/tooltip.settings.d.ts +11 -0
  63. package/dist/src/map/map.module.d.ts +4 -2
  64. package/dist/src/map/messages/commands/close-tooltip.command.d.ts +7 -0
  65. package/dist/src/map/messages/index.d.ts +1 -0
  66. package/dist/src/map/models/index.d.ts +1 -0
  67. package/dist/src/map/models/polygon.model.d.ts +19 -0
  68. package/dist/src/map/public-api.d.ts +1 -0
  69. package/package.json +1 -1
@@ -1,9 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Component, Injectable, ChangeDetectionStrategy, Input, NgModule } from '@angular/core';
2
+ import { Component, Injectable, ChangeDetectionStrategy, Input, ViewChild, NgModule } from '@angular/core';
3
3
  import * as i5 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 { GeoJSON, WKT } from 'ol/format';
8
+ import { getCenter } from 'ol/extent';
7
9
  import { useGeographic, get } from 'ol/proj';
8
10
  import { Subject } from 'rxjs';
9
11
  import { PostboyService, PostboyAbstractRegistrator } from '@artstesh/postboy';
@@ -14,6 +16,7 @@ import OSM from 'ol/source/OSM';
14
16
  import { filter, first } from 'rxjs/operators';
15
17
  import { XYZ, Vector } from 'ol/source';
16
18
  import { Vector as Vector$1 } from 'ol/layer';
19
+ import Overlay from 'ol/Overlay';
17
20
  import Style from 'ol/style/Style';
18
21
  import { Icon, Circle, Fill, Stroke } from 'ol/style';
19
22
 
@@ -139,6 +142,29 @@ class MarkerModel {
139
142
  }
140
143
  }
141
144
 
145
+ class PolygonModel {
146
+ constructor(feature, id, info) {
147
+ var _a;
148
+ this.info = info;
149
+ this.id = id == null ? IdGenerator.get() : id;
150
+ this._feature = feature;
151
+ [this.lng, this.lat] = getCenter((_a = this._feature.getGeometry()) === null || _a === void 0 ? void 0 : _a.getExtent());
152
+ }
153
+ static fromGeoJson(id, json, info) {
154
+ let feature = new GeoJSON().readFeature(json);
155
+ feature.setId(id);
156
+ return new PolygonModel(feature, id, info);
157
+ }
158
+ static fromWKT(id, wkt, info) {
159
+ let feature = new WKT().readFeature(wkt);
160
+ feature.setId(id);
161
+ return new PolygonModel(feature, id, info);
162
+ }
163
+ get feature() {
164
+ return this._feature;
165
+ }
166
+ }
167
+
142
168
  class GenericMessage {
143
169
  }
144
170
  class CallbackMessage extends GenericMessage {
@@ -176,6 +202,17 @@ class MapClickEvent extends GenericMessage {
176
202
  }
177
203
  MapClickEvent.ID = '323df526-8d9c-49c6-83e8-6e9a1e7762f7';
178
204
 
205
+ class CloseTooltipCommand extends GenericMessage {
206
+ constructor(tooltipId) {
207
+ super();
208
+ this.tooltipId = tooltipId;
209
+ }
210
+ get id() {
211
+ return CloseTooltipCommand.ID;
212
+ }
213
+ }
214
+ CloseTooltipCommand.ID = '4896d52c-e34f-4994-bcfd-32832d12dbe4';
215
+
179
216
  class AddLayerCommand extends GenericMessage {
180
217
  constructor(layer) {
181
218
  super();
@@ -343,7 +380,7 @@ class MapClickService {
343
380
  const model = new MapClickEvent(ev.coordinate, {});
344
381
  (_a = this.map) === null || _a === void 0 ? void 0 : _a.forEachFeatureAtPixel(ev.pixel, (f, l) => {
345
382
  this.getFeatureCollectionWithInner([f])
346
- .filter((f) => !!f.getId())
383
+ .filter((f) => f.getId() != null)
347
384
  .forEach((fs) => {
348
385
  let layerName = l.get('name');
349
386
  if (!model.entities[layerName])
@@ -381,6 +418,7 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
381
418
  this.registerSubject(AddTileCommand.ID);
382
419
  this.registerSubject(RemoveTileCommand.ID);
383
420
  this.registerSubject(MapClickEvent.ID);
421
+ this.registerSubject(CloseTooltipCommand.ID);
384
422
  }
385
423
  }
386
424
  MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapClickService }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -814,6 +852,150 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
814
852
  type: Input
815
853
  }] } });
816
854
 
855
+ class TooltipSettings {
856
+ constructor(id) {
857
+ this.containerClass = 'custom-tooltip-class';
858
+ this.show = (e) => true;
859
+ this.id = id !== null && id !== void 0 ? id : IdGenerator.get();
860
+ }
861
+ static copy(model) {
862
+ const result = new TooltipSettings(model.id);
863
+ result.show = model.show;
864
+ result.containerClass = model.containerClass;
865
+ return result;
866
+ }
867
+ setShow(show) {
868
+ return TooltipSettings.copy(Object.assign(Object.assign({}, this), { show }));
869
+ }
870
+ setClass(containerClass) {
871
+ return TooltipSettings.copy(Object.assign(Object.assign({}, this), { containerClass }));
872
+ }
873
+ isSame(model) {
874
+ if (this.show !== model.show)
875
+ return false;
876
+ if (this.containerClass !== model.containerClass)
877
+ return false;
878
+ if (this.id !== model.id)
879
+ return false;
880
+ return true;
881
+ }
882
+ }
883
+
884
+ class TooltipComponent extends DestructibleComponent {
885
+ constructor(postboy, detector) {
886
+ super();
887
+ this.postboy = postboy;
888
+ this.detector = detector;
889
+ this._settings = new TooltipSettings();
890
+ this.show = false;
891
+ this.removeOverlay = () => {
892
+ var _a;
893
+ !!this.overlay && ((_a = this.map) === null || _a === void 0 ? void 0 : _a.removeOverlay(this.overlay));
894
+ this.show = false;
895
+ };
896
+ this.options = (coordinates) => {
897
+ var _a;
898
+ return {
899
+ element: (_a = this.container) === null || _a === void 0 ? void 0 : _a.nativeElement,
900
+ autoPan: false,
901
+ autoPanAnimation: { duration: 0 },
902
+ position: coordinates,
903
+ };
904
+ };
905
+ }
906
+ set settings(value) {
907
+ if (!value || this._settings.isSame(value))
908
+ return;
909
+ this._settings = value;
910
+ this.detector.detectChanges();
911
+ }
912
+ ngOnInit() {
913
+ this.subs.push(this.observeMapRender());
914
+ this.subs.push(this.observeMapClick());
915
+ this.subs.push(this.observeClose());
916
+ }
917
+ observeMapClick() {
918
+ return this.postboy.subscribe(MapClickEvent.ID).subscribe((ev) => {
919
+ this._settings.show(ev) ? this.addOverlay(ev.coordinates) : this.removeOverlay();
920
+ });
921
+ }
922
+ observeClose() {
923
+ return this.postboy
924
+ .subscribe(CloseTooltipCommand.ID)
925
+ .pipe(filter((ev) => ev.tooltipId === this._settings.id))
926
+ .subscribe(() => this.removeOverlay());
927
+ }
928
+ observeMapRender() {
929
+ return this.postboy.subscribe(MapRenderedEvent.ID).subscribe((m) => {
930
+ this.map = m.map;
931
+ });
932
+ }
933
+ addOverlay(coordinates) {
934
+ var _a;
935
+ this.removeOverlay();
936
+ this.overlay = new Overlay(this.options(coordinates));
937
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.addOverlay(this.overlay);
938
+ this.show = true;
939
+ this.detector.detectChanges();
940
+ }
941
+ }
942
+ TooltipComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: TooltipComponent, deps: [{ token: MapPostboyService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
943
+ TooltipComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: TooltipComponent, selector: "lib-tooltip", inputs: { settings: "settings" }, viewQueries: [{ propertyName: "container", first: true, predicate: ["tip"], descendants: true }], usesInheritance: true, ngImport: i0, template: "<div #tip [class]=\"['tooltip-wrapper', _settings.containerClass]\" [hidden]=\"!show\">\r\n <ng-content></ng-content>\r\n</div>\r\n", styles: [".tooltip-wrapper{position:absolute}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
944
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: TooltipComponent, decorators: [{
945
+ type: Component,
946
+ args: [{
947
+ selector: 'lib-tooltip',
948
+ templateUrl: './tooltip.component.html',
949
+ styleUrls: ['./tooltip.component.scss'],
950
+ changeDetection: ChangeDetectionStrategy.OnPush,
951
+ }]
952
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { container: [{
953
+ type: ViewChild,
954
+ args: ['tip']
955
+ }], settings: [{
956
+ type: Input
957
+ }] } });
958
+
959
+ class PolygonsComponent extends DestructibleComponent {
960
+ constructor(postboy) {
961
+ super();
962
+ this.postboy = postboy;
963
+ this.layerName = '';
964
+ this._polygons = [];
965
+ }
966
+ set polygons(value) {
967
+ this._polygons = value;
968
+ this.putPolygons();
969
+ }
970
+ ngOnInit() {
971
+ this.postboy
972
+ .subscribe(MapRenderedEvent.ID)
973
+ .pipe(filter((m) => !!m), first())
974
+ .subscribe(() => this.putPolygons());
975
+ }
976
+ putPolygons() {
977
+ var _a;
978
+ if (!((_a = this._polygons) === null || _a === void 0 ? void 0 : _a.length))
979
+ return;
980
+ this.postboy.fire(new PlaceLayerFeaturesCommand(this.layerName, this._polygons.map((m) => m.feature)));
981
+ }
982
+ }
983
+ PolygonsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PolygonsComponent, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Component });
984
+ PolygonsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: PolygonsComponent, selector: "lib-polygons", inputs: { layerName: "layerName", polygons: "polygons" }, usesInheritance: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
985
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PolygonsComponent, decorators: [{
986
+ type: Component,
987
+ args: [{
988
+ selector: 'lib-polygons',
989
+ template: '',
990
+ styleUrls: [],
991
+ changeDetection: ChangeDetectionStrategy.OnPush,
992
+ }]
993
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; }, propDecorators: { layerName: [{
994
+ type: Input
995
+ }], polygons: [{
996
+ type: Input
997
+ }] } });
998
+
817
999
  class MapModule {
818
1000
  }
819
1001
  MapModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -822,7 +1004,14 @@ MapModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.
822
1004
  TileLayerComponent,
823
1005
  OsmTileLayerComponent,
824
1006
  FeatureLayerComponent,
825
- MarkersComponent], imports: [CommonModule], exports: [MapPlateComponent, FeatureLayerComponent, MarkersComponent, TileLayerComponent] });
1007
+ MarkersComponent,
1008
+ TooltipComponent,
1009
+ PolygonsComponent], imports: [CommonModule], exports: [MapPlateComponent,
1010
+ FeatureLayerComponent,
1011
+ MarkersComponent,
1012
+ TileLayerComponent,
1013
+ TooltipComponent,
1014
+ PolygonsComponent] });
826
1015
  MapModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapModule, imports: [[CommonModule]] });
827
1016
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapModule, decorators: [{
828
1017
  type: NgModule,
@@ -835,8 +1024,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
835
1024
  OsmTileLayerComponent,
836
1025
  FeatureLayerComponent,
837
1026
  MarkersComponent,
1027
+ TooltipComponent,
1028
+ PolygonsComponent,
1029
+ ],
1030
+ exports: [
1031
+ MapPlateComponent,
1032
+ FeatureLayerComponent,
1033
+ MarkersComponent,
1034
+ TileLayerComponent,
1035
+ TooltipComponent,
1036
+ PolygonsComponent,
838
1037
  ],
839
- exports: [MapPlateComponent, FeatureLayerComponent, MarkersComponent, TileLayerComponent],
840
1038
  }]
841
1039
  }] });
842
1040
 
@@ -863,6 +1061,20 @@ class MarkerStyleHelper {
863
1061
  }
864
1062
  }
865
1063
 
1064
+ class PolygonStyleHelper {
1065
+ static simple(fill, stroke, strokeWidth = 1) {
1066
+ return new Style({
1067
+ fill: new Fill({
1068
+ color: fill,
1069
+ }),
1070
+ stroke: new Stroke({
1071
+ color: stroke,
1072
+ width: strokeWidth,
1073
+ }),
1074
+ });
1075
+ }
1076
+ }
1077
+
866
1078
  /*
867
1079
  * Public API Surface of maps
868
1080
  */
@@ -875,5 +1087,5 @@ class MarkerStyleHelper {
875
1087
  * Generated bundle index. Do not edit.
876
1088
  */
877
1089
 
878
- export { CallbackMessage, FeatureLayerComponent, FeatureLayerSettings, GenericMessage, MapClickEvent, MapLyrs, MapLyrsLabel, MapModule, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, OsmTileLayerComponent, TileLayerComponent, TileLayerSettings };
1090
+ export { CallbackMessage, CloseTooltipCommand, FeatureLayerComponent, FeatureLayerSettings, GenericMessage, MapClickEvent, MapLyrs, MapLyrsLabel, MapModule, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, OsmTileLayerComponent, PolygonModel, PolygonStyleHelper, PolygonsComponent, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings };
879
1091
  //# sourceMappingURL=maps-components.js.map