@artstesh/maps 1.1.22 → 1.1.24

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 (47) hide show
  1. package/dist/bundles/maps-components-src-map.umd.js +157 -6
  2. package/dist/bundles/maps-components-src-map.umd.js.map +1 -1
  3. package/dist/bundles/maps-components.umd.js +157 -6
  4. package/dist/bundles/maps-components.umd.js.map +1 -1
  5. package/dist/esm2015/map/map-plate/features/polygons/polygons.component.js +6 -2
  6. package/dist/esm2015/map/map-plate/layers/feature-layer/feature-layer.settings.js +13 -1
  7. package/dist/esm2015/map/map-plate/map-plate.component.js +5 -1
  8. package/dist/esm2015/map/messages/events/map-feature-hovered.event.js +21 -0
  9. package/dist/esm2015/map/messages/events/map-pointer-move.event.js +20 -0
  10. package/dist/esm2015/map/messages/executors/polygon-self-intersection.executor.js +9 -0
  11. package/dist/esm2015/map/messages/index.js +4 -1
  12. package/dist/esm2015/map/models/map.constants.js +2 -1
  13. package/dist/esm2015/map/services/feature.service.js +53 -2
  14. package/dist/esm2015/map/services/map-feature.service.js +22 -2
  15. package/dist/esm2015/map/services/message-registrator.service.js +8 -2
  16. package/dist/esm2015/src/map/map-plate/features/polygons/polygons.component.js +6 -2
  17. package/dist/esm2015/src/map/map-plate/layers/feature-layer/feature-layer.settings.js +13 -1
  18. package/dist/esm2015/src/map/map-plate/map-plate.component.js +5 -1
  19. package/dist/esm2015/src/map/messages/events/map-feature-hovered.event.js +21 -0
  20. package/dist/esm2015/src/map/messages/events/map-pointer-move.event.js +20 -0
  21. package/dist/esm2015/src/map/messages/executors/polygon-self-intersection.executor.js +9 -0
  22. package/dist/esm2015/src/map/messages/index.js +4 -1
  23. package/dist/esm2015/src/map/models/map.constants.js +2 -1
  24. package/dist/esm2015/src/map/services/feature.service.js +53 -2
  25. package/dist/esm2015/src/map/services/map-feature.service.js +22 -2
  26. package/dist/esm2015/src/map/services/message-registrator.service.js +8 -2
  27. package/dist/fesm2015/maps-components-src-map.js +143 -6
  28. package/dist/fesm2015/maps-components-src-map.js.map +1 -1
  29. package/dist/fesm2015/maps-components.js +143 -6
  30. package/dist/fesm2015/maps-components.js.map +1 -1
  31. package/dist/map/map-plate/layers/feature-layer/feature-layer.settings.d.ts +22 -0
  32. package/dist/map/messages/events/map-feature-hovered.event.d.ts +19 -0
  33. package/dist/map/messages/events/map-pointer-move.event.d.ts +17 -0
  34. package/dist/map/messages/executors/polygon-self-intersection.executor.d.ts +7 -0
  35. package/dist/map/messages/index.d.ts +3 -0
  36. package/dist/map/models/map.constants.d.ts +1 -0
  37. package/dist/map/services/feature.service.d.ts +5 -0
  38. package/dist/map/services/map-feature.service.d.ts +1 -0
  39. package/dist/src/map/map-plate/layers/feature-layer/feature-layer.settings.d.ts +22 -0
  40. package/dist/src/map/messages/events/map-feature-hovered.event.d.ts +19 -0
  41. package/dist/src/map/messages/events/map-pointer-move.event.d.ts +17 -0
  42. package/dist/src/map/messages/executors/polygon-self-intersection.executor.d.ts +7 -0
  43. package/dist/src/map/messages/index.d.ts +3 -0
  44. package/dist/src/map/models/map.constants.d.ts +1 -0
  45. package/dist/src/map/services/feature.service.d.ts +5 -0
  46. package/dist/src/map/services/map-feature.service.d.ts +1 -0
  47. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { Component, Injectable, ChangeDetectionStrategy, Input, ViewChild, NgMod
3
3
  import * as i6 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
5
  import { Feature, Collection } from 'ol';
6
- import { Point } from 'ol/geom';
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
9
  import Polygon, { circular, fromExtent } from 'ol/geom/Polygon';
@@ -13,15 +13,15 @@ import { PostboyGenericMessage, PostboyCallbackMessage, PostboyExecutor, Postboy
13
13
  import { Draw, Modify, Translate, defaults } from 'ol/interaction';
14
14
  import { createRegularPolygon, createBox } from 'ol/interaction/Draw';
15
15
  import * as Sphere from 'ol/sphere';
16
+ import { Subject, combineLatest } from 'rxjs';
17
+ import { first, debounceTime, filter, auditTime } from 'rxjs/operators';
16
18
  import { Dictionary } from '@artstesh/collections';
17
- import { first, filter, auditTime } from 'rxjs/operators';
18
19
  import { Vector, XYZ } from 'ol/source';
19
20
  import TileLayer from 'ol/layer/Tile';
20
21
  import OSM from 'ol/source/OSM';
21
22
  import { Vector as Vector$1 } from 'ol/layer';
22
23
  import { bbox } from 'ol/loadingstrategy';
23
24
  import Cluster from 'ol/source/Cluster';
24
- import { combineLatest } from 'rxjs';
25
25
  import Map from 'ol/Map';
26
26
  import View from 'ol/View';
27
27
  import Overlay from 'ol/Overlay';
@@ -194,7 +194,8 @@ IdGenerator.collection = 'ABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789'.split('');
194
194
  class MapConstants {
195
195
  }
196
196
  MapConstants.FeatureInfo = 'f-info';
197
- MapConstants.DrawingLayerId = '93a981756ec7';
197
+ MapConstants.DrawingLayerId = '93a981756ec7';
198
+ MapConstants.FeatureLayerName = 'L-253';
198
199
 
199
200
  class MarkerModel {
200
201
  constructor(lat, lng, id, info) {
@@ -519,6 +520,45 @@ class MapMoveEndEvent extends PostboyGenericMessage {
519
520
  }
520
521
  MapMoveEndEvent.ID = 'd210ec7e-032f-4ce8-8a39-7b816519eaae';
521
522
 
523
+ /**
524
+ * Represents an event that is triggered when the pointer moves on a map.
525
+ * This class extends PostboyGenericMessage.
526
+ *
527
+ * It contains information about the coordinates of the pointer when the event occurs.
528
+ */
529
+ class MapPointerMoveEvent extends PostboyGenericMessage {
530
+ /**
531
+ * Constructor for initializing an instance with a given point.
532
+ *
533
+ * @param {Array<number>} point - An array representing the coordinates of the point.
534
+ */
535
+ constructor(point) {
536
+ super();
537
+ this.point = point;
538
+ }
539
+ }
540
+ MapPointerMoveEvent.ID = '193cb41d-2489-45cc-b349-59c3ec18ed72';
541
+
542
+ /**
543
+ * Represents an event triggered when a map feature is hovered over.
544
+ * This event contains information about the hovered feature and its associated layer.
545
+ * Extends the PostboyGenericMessage class.
546
+ */
547
+ class MapFeatureHoveredEvent extends PostboyGenericMessage {
548
+ /**
549
+ * Constructs an instance of the class.
550
+ *
551
+ * @param {Feature|null} feature - The feature associated with this instance. Can be null.
552
+ * @param {string|null} layer - The layer associated with this instance. Can be null.
553
+ */
554
+ constructor(feature, layer) {
555
+ super();
556
+ this.feature = feature;
557
+ this.layer = layer;
558
+ }
559
+ }
560
+ MapFeatureHoveredEvent.ID = 'eb9b032a-1616-4823-a628-0fd8ffc3b57a';
561
+
522
562
  /**
523
563
  * A class responsible for executing filtering of geographical features
524
564
  * based on a specific geographical point (latitude and longitude).
@@ -587,6 +627,14 @@ class GetMapPositionExecutor extends PostboyExecutor {
587
627
  }
588
628
  GetMapPositionExecutor.ID = '52c95689-d09b-4082-ba58-9183ea96a213';
589
629
 
630
+ class PolygonSelfIntersectionExecutor extends PostboyGenericMessage {
631
+ constructor(polygon) {
632
+ super();
633
+ this.polygon = polygon;
634
+ }
635
+ }
636
+ PolygonSelfIntersectionExecutor.ID = 'a4ef116d-fe40-4e92-9d4a-653f8b398c62';
637
+
590
638
  /**
591
639
  * Class representing a query to get features within a specified geographical area.
592
640
  * The query optionally takes a set of layer names to ignore during the operation.
@@ -724,6 +772,20 @@ class FeatureService {
724
772
  return 0;
725
773
  return Sphere.getArea(g, { projection: 'EPSG:4326' });
726
774
  }
775
+ static polygonSelfIntersects(feature) {
776
+ if (feature.getGeometry().getType() !== 'Polygon')
777
+ return false;
778
+ let intersections = 0;
779
+ const segments = FeatureService.getSegmentsFromCoordinates(feature.getGeometry());
780
+ for (let i = 0; i < segments.length; i++) {
781
+ for (let z = i + 1; z < segments.length; z++) {
782
+ if (!intersections && this.segmentIntersection(segments[i].getCoordinates(), segments[z].getCoordinates())) {
783
+ intersections++;
784
+ }
785
+ }
786
+ }
787
+ return intersections !== 0;
788
+ }
727
789
  static booleanIntersects(g1, g2) {
728
790
  if (g2.getType() === 'Point')
729
791
  return g1.intersectsCoordinate(g2.getCoordinates());
@@ -733,6 +795,43 @@ class FeatureService {
733
795
  return g1.intersectsCoordinate(g2.getInteriorPoint().getCoordinates());
734
796
  return false;
735
797
  }
798
+ static getSegmentsFromCoordinates(geom) {
799
+ if (!geom)
800
+ return [];
801
+ const coords = geom.getCoordinates();
802
+ const line = new LineString(coords[0]);
803
+ const segments = [];
804
+ line.forEachSegment((s1, s2) => {
805
+ const l = new LineString([s1, s2]);
806
+ l.scale(0.999); // bug of the OL, as I see
807
+ segments.push(l);
808
+ });
809
+ return segments;
810
+ }
811
+ static segmentIntersection(s1, s2) {
812
+ const a = s1[0], b = s1[1], c = s2[0], d = s2[1];
813
+ const o1 = this.orientation(a, b, c);
814
+ const o2 = this.orientation(a, b, d);
815
+ const o3 = this.orientation(c, d, a);
816
+ const o4 = this.orientation(c, d, b);
817
+ return ((o1 != o2 && o3 != o4) ||
818
+ (o1 == 0 && this.onSegment(a, d, b)) ||
819
+ (o2 == 0 && this.onSegment(a, d, b)) ||
820
+ (o3 == 0 && this.onSegment(d, a, d)) ||
821
+ (o4 == 0 && this.onSegment(d, b, d)));
822
+ }
823
+ static orientation(p, q, r) {
824
+ const val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1]);
825
+ if (val == 0)
826
+ return 0; // collinear
827
+ return val > 0 ? 1 : 2; // clock or counterclock wise
828
+ }
829
+ static onSegment(p, q, r) {
830
+ return (q[0] <= (p[0] > r[0] ? p[0] : r[0]) &&
831
+ q[0] >= (p[0] < r[0] ? p[0] : r[0]) &&
832
+ q[1] <= (p[1] > r[1] ? p[1] : r[1]) &&
833
+ q[1] >= (p[1] < r[1] ? p[1] : r[1]));
834
+ }
736
835
  }
737
836
 
738
837
  class GenerateDrawExecutor extends PostboyExecutor {
@@ -939,6 +1038,7 @@ class MapFeatureService {
939
1038
  this.observeMapRender();
940
1039
  this.observeFitToFeatures();
941
1040
  this.observeFitToPolygons();
1041
+ this.observePointerMove();
942
1042
  }
943
1043
  observeMapRender() {
944
1044
  this.postboy.sub(MapRenderedEvent).subscribe((m) => {
@@ -947,6 +1047,22 @@ class MapFeatureService {
947
1047
  this.postboy.fire(this.fitPolygonsWaiting);
948
1048
  });
949
1049
  }
1050
+ observePointerMove() {
1051
+ this.postboy.sub(MapPointerMoveEvent).subscribe((ev) => {
1052
+ if (!this.map)
1053
+ return;
1054
+ let featureFound = false;
1055
+ this.map.forEachFeatureAtPixel(ev.point, (f) => {
1056
+ if (f instanceof Feature) {
1057
+ this.postboy.fire(new MapFeatureHoveredEvent(f, f.get(MapConstants.FeatureLayerName)));
1058
+ featureFound = true;
1059
+ }
1060
+ return true;
1061
+ });
1062
+ if (!featureFound)
1063
+ this.postboy.fire(new MapFeatureHoveredEvent(null, null));
1064
+ });
1065
+ }
950
1066
  observeFitToFeatures() {
951
1067
  this.postboy.sub(FitToFeaturesCommand).subscribe((cmd) => {
952
1068
  this.fitToGeometries(cmd.features.map((f) => f.getGeometry()), cmd.zoomAfter);
@@ -1250,6 +1366,8 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1250
1366
  this.recordSubject(CancelDrawingCommand);
1251
1367
  this.recordSubject(StartDrawingCommand);
1252
1368
  this.recordSubject(GetLayerQuery);
1369
+ this.recordSubject(MapFeatureHoveredEvent);
1370
+ this.recordWithPipe(MapPointerMoveEvent, new Subject(), (s) => s.pipe(debounceTime(150)));
1253
1371
  this.recordSubject(DrawingFinishedEvent);
1254
1372
  this.recordSubject(GetFeaturesInAreaQuery);
1255
1373
  this.recordSubject(DrawSelectionAreaCommand);
@@ -1262,6 +1380,7 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1262
1380
  this.recordExecutor(FilterFeaturesInAreaExecutor, (e) => FeatureService.filterFeaturesInArea(e));
1263
1381
  this.recordExecutor(FilterFeaturesInPointExecutor, (e) => FeatureService.filterFeaturesInPoint(e));
1264
1382
  this.recordExecutor(CalculateAreaExecutor, (e) => { var _a, _b; return FeatureService.calculateArea((_b = (_a = e.polygon) === null || _a === void 0 ? void 0 : _a.feature) === null || _b === void 0 ? void 0 : _b.getGeometry()); });
1383
+ this.recordExecutor(PolygonSelfIntersectionExecutor, (e) => FeatureService.polygonSelfIntersects(e.polygon.feature));
1265
1384
  this.recordExecutor(GenerateDrawExecutor, (e) => DrawingGenerationService.getDraw(e));
1266
1385
  this.recordExecutor(GenerateZoomControlExecutor, (e) => ZoomControlFactory.build(e.settings));
1267
1386
  this.recordExecutor(GetMapPositionExecutor, () => this.state.getMapPosition());
@@ -1617,6 +1736,7 @@ class FeatureLayerSettings {
1617
1736
  result.minZoom = model.minZoom;
1618
1737
  result.zIndex = model.zIndex;
1619
1738
  result.style = model.style;
1739
+ result.featureHoverStyle = model.featureHoverStyle;
1620
1740
  return result;
1621
1741
  }
1622
1742
  /**
@@ -1665,6 +1785,15 @@ class FeatureLayerSettings {
1665
1785
  setStyle(style) {
1666
1786
  return FeatureLayerSettings.copy(Object.assign(Object.assign({}, this), { style }));
1667
1787
  }
1788
+ /**
1789
+ * Sets the style to apply to features when they are hovered over.
1790
+ *
1791
+ * @param {Style | StyleFunction} featureHoverStyle - The style or style function to use for hovered features.
1792
+ * @return {FeatureLayerSettings} A new instance of FeatureLayerSettings with the updated hover style.
1793
+ */
1794
+ setFeatureHoverStyle(featureHoverStyle) {
1795
+ return FeatureLayerSettings.copy(Object.assign(Object.assign({}, this), { featureHoverStyle }));
1796
+ }
1668
1797
  /**
1669
1798
  * Checks if the given FeatureLayerSettings object is identical to the current object.
1670
1799
  *
@@ -1682,6 +1811,8 @@ class FeatureLayerSettings {
1682
1811
  return false;
1683
1812
  if (this.style !== model.style)
1684
1813
  return false;
1814
+ if (this.featureHoverStyle !== model.featureHoverStyle)
1815
+ return false;
1685
1816
  return true;
1686
1817
  }
1687
1818
  }
@@ -2092,6 +2223,9 @@ class MapPlateComponent extends DestructibleComponent {
2092
2223
  this.map.updateSize();
2093
2224
  this.postboy.fire(new MapRenderedEvent(this.map));
2094
2225
  });
2226
+ this.map.on('pointermove', (ev) => {
2227
+ this.postboy.fire(new MapPointerMoveEvent(ev.pixel));
2228
+ });
2095
2229
  this.setOsm();
2096
2230
  }
2097
2231
  setOsm() {
@@ -2322,7 +2456,10 @@ class PolygonsComponent extends DestructibleComponent {
2322
2456
  putPolygons() {
2323
2457
  if (!this._polygons)
2324
2458
  return;
2325
- this.postboy.fire(new PlaceLayerFeaturesCommand(this.layerName, this._polygons.map((m) => m.feature)));
2459
+ this.postboy.fire(new PlaceLayerFeaturesCommand(this.layerName, this._polygons.map((m) => {
2460
+ m.feature.set(MapConstants.FeatureLayerName, this.layerName);
2461
+ return m.feature;
2462
+ })));
2326
2463
  }
2327
2464
  }
2328
2465
  PolygonsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PolygonsComponent, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Component });
@@ -2768,5 +2905,5 @@ class StringifyFeatureHelper {
2768
2905
  * Generated bundle index. Do not edit.
2769
2906
  */
2770
2907
 
2771
- export { AddControlCommand, CalculateAreaExecutor, CancelDrawingCommand, CancelFeatureModificationCommand, CloseTooltipCommand, ClusterLayerComponent, ClusterLayerSettings, DrawSelectionAreaCommand, DrawingType, FeatureLayerComponent, FeatureLayerSettings, FeatureOutputFormat, FilterFeaturesInAreaExecutor, FilterFeaturesInPointExecutor, FitToFeaturesCommand, FitToPolygonsCommand, GetFeaturesInAreaQuery, GetFeaturesInPointQuery, GetMapPositionExecutor, MapClickEvent, MapConstants, 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 };
2908
+ export { AddControlCommand, CalculateAreaExecutor, CancelDrawingCommand, CancelFeatureModificationCommand, CloseTooltipCommand, ClusterLayerComponent, ClusterLayerSettings, DrawSelectionAreaCommand, DrawingType, FeatureLayerComponent, FeatureLayerSettings, FeatureOutputFormat, FilterFeaturesInAreaExecutor, FilterFeaturesInPointExecutor, FitToFeaturesCommand, FitToPolygonsCommand, GetFeaturesInAreaQuery, GetFeaturesInPointQuery, GetMapPositionExecutor, MapClickEvent, MapConstants, MapControl, MapControlZoomComponent, MapFeatureHoveredEvent, MapLyrs, MapLyrsLabel, MapModule, MapMoveEndEvent, MapPlateComponent, MapPointerMoveEvent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, ModifyFeatureCommand, OsmTileLayerComponent, PolygonModel, PolygonSelfIntersectionExecutor, PolygonStyleHelper, PolygonsComponent, RemoveControlCommand, SetMapCenterCommand, StartDrawingCommand, StringifyFeatureHelper, TextStyleHelper, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings, ZoomControlSettings };
2772
2909
  //# sourceMappingURL=maps-components.js.map