@artstesh/maps 5.2.1 → 5.2.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 (43) hide show
  1. package/dist/esm2022/map/map-plate/features/polygons/polygons.component.mjs +6 -2
  2. package/dist/esm2022/map/map-plate/layers/feature-layer/feature-layer.settings.mjs +28 -1
  3. package/dist/esm2022/map/map-plate/map-plate.component.mjs +5 -1
  4. package/dist/esm2022/map/messages/events/map-feature-hovered.event.mjs +23 -0
  5. package/dist/esm2022/map/messages/events/map-pointer-move.event.mjs +21 -0
  6. package/dist/esm2022/map/messages/executors/polygon-self-intersection.executor.mjs +10 -0
  7. package/dist/esm2022/map/messages/index.mjs +4 -1
  8. package/dist/esm2022/map/models/map.constants.mjs +2 -1
  9. package/dist/esm2022/map/services/feature.service.mjs +53 -2
  10. package/dist/esm2022/map/services/map-feature.service.mjs +22 -2
  11. package/dist/esm2022/map/services/message-registrator.service.mjs +8 -2
  12. package/dist/esm2022/src/map/map-plate/features/polygons/polygons.component.mjs +6 -2
  13. package/dist/esm2022/src/map/map-plate/layers/feature-layer/feature-layer.settings.mjs +28 -1
  14. package/dist/esm2022/src/map/map-plate/map-plate.component.mjs +5 -1
  15. package/dist/esm2022/src/map/messages/events/map-feature-hovered.event.mjs +23 -0
  16. package/dist/esm2022/src/map/messages/events/map-pointer-move.event.mjs +21 -0
  17. package/dist/esm2022/src/map/messages/executors/polygon-self-intersection.executor.mjs +10 -0
  18. package/dist/esm2022/src/map/messages/index.mjs +4 -1
  19. package/dist/esm2022/src/map/models/map.constants.mjs +2 -1
  20. package/dist/esm2022/src/map/services/feature.service.mjs +53 -2
  21. package/dist/esm2022/src/map/services/map-feature.service.mjs +22 -2
  22. package/dist/esm2022/src/map/services/message-registrator.service.mjs +8 -2
  23. package/dist/fesm2022/maps-components-src-map.mjs +161 -5
  24. package/dist/fesm2022/maps-components-src-map.mjs.map +1 -1
  25. package/dist/fesm2022/maps-components.mjs +161 -5
  26. package/dist/fesm2022/maps-components.mjs.map +1 -1
  27. package/dist/map/map-plate/layers/feature-layer/feature-layer.settings.d.ts +22 -0
  28. package/dist/map/messages/events/map-feature-hovered.event.d.ts +19 -0
  29. package/dist/map/messages/events/map-pointer-move.event.d.ts +17 -0
  30. package/dist/map/messages/executors/polygon-self-intersection.executor.d.ts +7 -0
  31. package/dist/map/messages/index.d.ts +3 -0
  32. package/dist/map/models/map.constants.d.ts +1 -0
  33. package/dist/map/services/feature.service.d.ts +5 -0
  34. package/dist/map/services/map-feature.service.d.ts +1 -0
  35. package/dist/src/map/map-plate/layers/feature-layer/feature-layer.settings.d.ts +22 -0
  36. package/dist/src/map/messages/events/map-feature-hovered.event.d.ts +19 -0
  37. package/dist/src/map/messages/events/map-pointer-move.event.d.ts +17 -0
  38. package/dist/src/map/messages/executors/polygon-self-intersection.executor.d.ts +7 -0
  39. package/dist/src/map/messages/index.d.ts +3 -0
  40. package/dist/src/map/models/map.constants.d.ts +1 -0
  41. package/dist/src/map/services/feature.service.d.ts +5 -0
  42. package/dist/src/map/services/map-feature.service.d.ts +1 -0
  43. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { Component, Injectable, ChangeDetectionStrategy, Input, ViewChild, NgMod
3
3
  import * as i4 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';
@@ -191,6 +191,7 @@ class IdGenerator {
191
191
  class MapConstants {
192
192
  static FeatureInfo = 'f-info';
193
193
  static DrawingLayerId = '93a981756ec7';
194
+ static FeatureLayerName = 'L-253';
194
195
  }
195
196
 
196
197
  class MarkerModel {
@@ -547,6 +548,48 @@ class MapMoveEndEvent extends PostboyGenericMessage {
547
548
  }
548
549
  }
549
550
 
551
+ /**
552
+ * Represents an event that is triggered when the pointer moves on a map.
553
+ * This class extends PostboyGenericMessage.
554
+ *
555
+ * It contains information about the coordinates of the pointer when the event occurs.
556
+ */
557
+ class MapPointerMoveEvent extends PostboyGenericMessage {
558
+ point;
559
+ static ID = '193cb41d-2489-45cc-b349-59c3ec18ed72';
560
+ /**
561
+ * Constructor for initializing an instance with a given point.
562
+ *
563
+ * @param {Array<number>} point - An array representing the coordinates of the point.
564
+ */
565
+ constructor(point) {
566
+ super();
567
+ this.point = point;
568
+ }
569
+ }
570
+
571
+ /**
572
+ * Represents an event triggered when a map feature is hovered over.
573
+ * This event contains information about the hovered feature and its associated layer.
574
+ * Extends the PostboyGenericMessage class.
575
+ */
576
+ class MapFeatureHoveredEvent extends PostboyGenericMessage {
577
+ feature;
578
+ layer;
579
+ static ID = 'eb9b032a-1616-4823-a628-0fd8ffc3b57a';
580
+ /**
581
+ * Constructs an instance of the class.
582
+ *
583
+ * @param {Feature|null} feature - The feature associated with this instance. Can be null.
584
+ * @param {string|null} layer - The layer associated with this instance. Can be null.
585
+ */
586
+ constructor(feature, layer) {
587
+ super();
588
+ this.feature = feature;
589
+ this.layer = layer;
590
+ }
591
+ }
592
+
550
593
  /**
551
594
  * A class responsible for executing filtering of geographical features
552
595
  * based on a specific geographical point (latitude and longitude).
@@ -621,6 +664,15 @@ class GetMapPositionExecutor extends PostboyExecutor {
621
664
  }
622
665
  }
623
666
 
667
+ class PolygonSelfIntersectionExecutor extends PostboyGenericMessage {
668
+ polygon;
669
+ static ID = 'a4ef116d-fe40-4e92-9d4a-653f8b398c62';
670
+ constructor(polygon) {
671
+ super();
672
+ this.polygon = polygon;
673
+ }
674
+ }
675
+
624
676
  /**
625
677
  * Class representing a query to get features within a specified geographical area.
626
678
  * The query optionally takes a set of layer names to ignore during the operation.
@@ -772,6 +824,20 @@ class FeatureService {
772
824
  return 0;
773
825
  return Sphere.getArea(g, { projection: 'EPSG:4326' });
774
826
  }
827
+ static polygonSelfIntersects(feature) {
828
+ if (feature.getGeometry().getType() !== 'Polygon')
829
+ return false;
830
+ let intersections = 0;
831
+ const segments = FeatureService.getSegmentsFromCoordinates(feature.getGeometry());
832
+ for (let i = 0; i < segments.length; i++) {
833
+ for (let z = i + 1; z < segments.length; z++) {
834
+ if (!intersections && this.segmentIntersection(segments[i].getCoordinates(), segments[z].getCoordinates())) {
835
+ intersections++;
836
+ }
837
+ }
838
+ }
839
+ return intersections !== 0;
840
+ }
775
841
  static booleanIntersects(g1, g2) {
776
842
  if (g2.getType() === 'Point')
777
843
  return g1.intersectsCoordinate(g2.getCoordinates());
@@ -781,6 +847,43 @@ class FeatureService {
781
847
  return g1.intersectsCoordinate(g2.getInteriorPoint().getCoordinates());
782
848
  return false;
783
849
  }
850
+ static getSegmentsFromCoordinates(geom) {
851
+ if (!geom)
852
+ return [];
853
+ const coords = geom.getCoordinates();
854
+ const line = new LineString(coords[0]);
855
+ const segments = [];
856
+ line.forEachSegment((s1, s2) => {
857
+ const l = new LineString([s1, s2]);
858
+ l.scale(0.999); // bug of the OL, as I see
859
+ segments.push(l);
860
+ });
861
+ return segments;
862
+ }
863
+ static segmentIntersection(s1, s2) {
864
+ const a = s1[0], b = s1[1], c = s2[0], d = s2[1];
865
+ const o1 = this.orientation(a, b, c);
866
+ const o2 = this.orientation(a, b, d);
867
+ const o3 = this.orientation(c, d, a);
868
+ const o4 = this.orientation(c, d, b);
869
+ return ((o1 != o2 && o3 != o4) ||
870
+ (o1 == 0 && this.onSegment(a, d, b)) ||
871
+ (o2 == 0 && this.onSegment(a, d, b)) ||
872
+ (o3 == 0 && this.onSegment(d, a, d)) ||
873
+ (o4 == 0 && this.onSegment(d, b, d)));
874
+ }
875
+ static orientation(p, q, r) {
876
+ const val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1]);
877
+ if (val == 0)
878
+ return 0; // collinear
879
+ return val > 0 ? 1 : 2; // clock or counterclock wise
880
+ }
881
+ static onSegment(p, q, r) {
882
+ return (q[0] <= (p[0] > r[0] ? p[0] : r[0]) &&
883
+ q[0] >= (p[0] < r[0] ? p[0] : r[0]) &&
884
+ q[1] <= (p[1] > r[1] ? p[1] : r[1]) &&
885
+ q[1] >= (p[1] < r[1] ? p[1] : r[1]));
886
+ }
784
887
  }
785
888
 
786
889
  class GenerateDrawExecutor extends PostboyExecutor {
@@ -987,6 +1090,7 @@ class MapFeatureService {
987
1090
  this.observeMapRender();
988
1091
  this.observeFitToFeatures();
989
1092
  this.observeFitToPolygons();
1093
+ this.observePointerMove();
990
1094
  }
991
1095
  observeMapRender() {
992
1096
  this.postboy.sub(MapRenderedEvent).subscribe((m) => {
@@ -995,6 +1099,22 @@ class MapFeatureService {
995
1099
  this.postboy.fire(this.fitPolygonsWaiting);
996
1100
  });
997
1101
  }
1102
+ observePointerMove() {
1103
+ this.postboy.sub(MapPointerMoveEvent).subscribe((ev) => {
1104
+ if (!this.map)
1105
+ return;
1106
+ let featureFound = false;
1107
+ this.map.forEachFeatureAtPixel(ev.point, (f) => {
1108
+ if (f instanceof Feature) {
1109
+ this.postboy.fire(new MapFeatureHoveredEvent(f, f.get(MapConstants.FeatureLayerName)));
1110
+ featureFound = true;
1111
+ }
1112
+ return true;
1113
+ });
1114
+ if (!featureFound)
1115
+ this.postboy.fire(new MapFeatureHoveredEvent(null, null));
1116
+ });
1117
+ }
998
1118
  observeFitToFeatures() {
999
1119
  this.postboy.sub(FitToFeaturesCommand).subscribe((cmd) => {
1000
1120
  this.fitToGeometries(cmd.features.map((f) => f.getGeometry()), cmd.zoomAfter);
@@ -1303,6 +1423,8 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1303
1423
  this.recordSubject(CancelDrawingCommand);
1304
1424
  this.recordSubject(StartDrawingCommand);
1305
1425
  this.recordSubject(GetLayerQuery);
1426
+ this.recordSubject(MapFeatureHoveredEvent);
1427
+ this.recordWithPipe(MapPointerMoveEvent, new Subject(), (s) => s.pipe(debounceTime(150)));
1306
1428
  this.recordSubject(DrawingFinishedEvent);
1307
1429
  this.recordSubject(GetFeaturesInAreaQuery);
1308
1430
  this.recordSubject(DrawSelectionAreaCommand);
@@ -1315,6 +1437,7 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1315
1437
  this.recordExecutor(FilterFeaturesInAreaExecutor, (e) => FeatureService.filterFeaturesInArea(e));
1316
1438
  this.recordExecutor(FilterFeaturesInPointExecutor, (e) => FeatureService.filterFeaturesInPoint(e));
1317
1439
  this.recordExecutor(CalculateAreaExecutor, (e) => FeatureService.calculateArea(e.polygon?.feature?.getGeometry()));
1440
+ this.recordExecutor(PolygonSelfIntersectionExecutor, (e) => FeatureService.polygonSelfIntersects(e.polygon.feature));
1318
1441
  this.recordExecutor(GenerateDrawExecutor, (e) => DrawingGenerationService.getDraw(e));
1319
1442
  this.recordExecutor(GenerateZoomControlExecutor, (e) => ZoomControlFactory.build(e.settings));
1320
1443
  this.recordExecutor(GetMapPositionExecutor, () => this.state.getMapPosition());
@@ -1651,6 +1774,21 @@ class FeatureLayerSettings {
1651
1774
  * The styling definition of layer's features. The easiest way is to use {@link PolygonStyleHelper},{@link MarkerStyleHelper}
1652
1775
  */
1653
1776
  style;
1777
+ /**
1778
+ * Defines the style applied to a feature when it is hovered over.
1779
+ *
1780
+ * This property can accept either a static style object or a dynamic style function.
1781
+ * When a `StyleFunction` is provided, it will determine the style dynamically
1782
+ * based on the feature being hovered.
1783
+ *
1784
+ * The style is applied temporarily, specifically for the hovered feature,
1785
+ * and overrides any default or predefined styles for that feature.
1786
+ *
1787
+ * Optional property.
1788
+ *
1789
+ * @type {(Style | StyleFunction)}
1790
+ */
1791
+ featureHoverStyle;
1654
1792
  /**
1655
1793
  * Copies the given FeatureLayerSettings object
1656
1794
  *
@@ -1664,6 +1802,7 @@ class FeatureLayerSettings {
1664
1802
  result.minZoom = model.minZoom;
1665
1803
  result.zIndex = model.zIndex;
1666
1804
  result.style = model.style;
1805
+ result.featureHoverStyle = model.featureHoverStyle;
1667
1806
  return result;
1668
1807
  }
1669
1808
  /**
@@ -1712,6 +1851,15 @@ class FeatureLayerSettings {
1712
1851
  setStyle(style) {
1713
1852
  return FeatureLayerSettings.copy({ ...this, style });
1714
1853
  }
1854
+ /**
1855
+ * Sets the style to apply to features when they are hovered over.
1856
+ *
1857
+ * @param {Style | StyleFunction} featureHoverStyle - The style or style function to use for hovered features.
1858
+ * @return {FeatureLayerSettings} A new instance of FeatureLayerSettings with the updated hover style.
1859
+ */
1860
+ setFeatureHoverStyle(featureHoverStyle) {
1861
+ return FeatureLayerSettings.copy({ ...this, featureHoverStyle });
1862
+ }
1715
1863
  /**
1716
1864
  * Checks if the given FeatureLayerSettings object is identical to the current object.
1717
1865
  *
@@ -1729,6 +1877,8 @@ class FeatureLayerSettings {
1729
1877
  return false;
1730
1878
  if (this.style !== model.style)
1731
1879
  return false;
1880
+ if (this.featureHoverStyle !== model.featureHoverStyle)
1881
+ return false;
1732
1882
  return true;
1733
1883
  }
1734
1884
  }
@@ -2134,6 +2284,9 @@ class MapPlateComponent extends DestructibleComponent {
2134
2284
  this.map.updateSize();
2135
2285
  this.postboy.fire(new MapRenderedEvent(this.map));
2136
2286
  });
2287
+ this.map.on('pointermove', (ev) => {
2288
+ this.postboy.fire(new MapPointerMoveEvent(ev.pixel));
2289
+ });
2137
2290
  this.setOsm();
2138
2291
  }
2139
2292
  onDestroy = () => {
@@ -2356,7 +2509,10 @@ class PolygonsComponent extends DestructibleComponent {
2356
2509
  putPolygons() {
2357
2510
  if (!this._polygons)
2358
2511
  return;
2359
- this.postboy.fire(new PlaceLayerFeaturesCommand(this.layerName, this._polygons.map((m) => m.feature)));
2512
+ this.postboy.fire(new PlaceLayerFeaturesCommand(this.layerName, this._polygons.map((m) => {
2513
+ m.feature.set(MapConstants.FeatureLayerName, this.layerName);
2514
+ return m.feature;
2515
+ })));
2360
2516
  }
2361
2517
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PolygonsComponent, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Component });
2362
2518
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: PolygonsComponent, selector: "art-polygons", inputs: { layerName: "layerName", polygons: "polygons" }, usesInheritance: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
@@ -2793,5 +2949,5 @@ class StringifyFeatureHelper {
2793
2949
  * Generated bundle index. Do not edit.
2794
2950
  */
2795
2951
 
2796
- 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 };
2952
+ 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 };
2797
2953
  //# sourceMappingURL=maps-components.mjs.map