@artstesh/maps 4.1.23 → 4.1.25

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/esm2020/map/map-plate/features/polygons/polygons.component.mjs +6 -2
  2. package/dist/esm2020/map/map-plate/layers/feature-layer/feature-layer.settings.mjs +13 -1
  3. package/dist/esm2020/map/map-plate/map-plate.component.mjs +5 -1
  4. package/dist/esm2020/map/messages/events/map-feature-hovered.event.mjs +21 -0
  5. package/dist/esm2020/map/messages/events/map-pointer-move.event.mjs +20 -0
  6. package/dist/esm2020/map/messages/executors/polygon-self-intersection.executor.mjs +9 -0
  7. package/dist/esm2020/map/messages/index.mjs +4 -1
  8. package/dist/esm2020/map/models/map.constants.mjs +2 -1
  9. package/dist/esm2020/map/services/feature.service.mjs +53 -2
  10. package/dist/esm2020/map/services/map-feature.service.mjs +22 -2
  11. package/dist/esm2020/map/services/message-registrator.service.mjs +8 -2
  12. package/dist/esm2020/src/map/map-plate/features/polygons/polygons.component.mjs +6 -2
  13. package/dist/esm2020/src/map/map-plate/layers/feature-layer/feature-layer.settings.mjs +13 -1
  14. package/dist/esm2020/src/map/map-plate/map-plate.component.mjs +5 -1
  15. package/dist/esm2020/src/map/messages/events/map-feature-hovered.event.mjs +21 -0
  16. package/dist/esm2020/src/map/messages/events/map-pointer-move.event.mjs +20 -0
  17. package/dist/esm2020/src/map/messages/executors/polygon-self-intersection.executor.mjs +9 -0
  18. package/dist/esm2020/src/map/messages/index.mjs +4 -1
  19. package/dist/esm2020/src/map/models/map.constants.mjs +2 -1
  20. package/dist/esm2020/src/map/services/feature.service.mjs +53 -2
  21. package/dist/esm2020/src/map/services/map-feature.service.mjs +22 -2
  22. package/dist/esm2020/src/map/services/message-registrator.service.mjs +8 -2
  23. package/dist/fesm2015/maps-components-src-map.mjs +143 -6
  24. package/dist/fesm2015/maps-components-src-map.mjs.map +1 -1
  25. package/dist/fesm2015/maps-components.mjs +143 -6
  26. package/dist/fesm2015/maps-components.mjs.map +1 -1
  27. package/dist/fesm2020/maps-components-src-map.mjs +143 -6
  28. package/dist/fesm2020/maps-components-src-map.mjs.map +1 -1
  29. package/dist/fesm2020/maps-components.mjs +143 -6
  30. package/dist/fesm2020/maps-components.mjs.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 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';
@@ -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 {
@@ -938,6 +1037,7 @@ class MapFeatureService {
938
1037
  this.observeMapRender();
939
1038
  this.observeFitToFeatures();
940
1039
  this.observeFitToPolygons();
1040
+ this.observePointerMove();
941
1041
  }
942
1042
  observeMapRender() {
943
1043
  this.postboy.sub(MapRenderedEvent).subscribe((m) => {
@@ -946,6 +1046,22 @@ class MapFeatureService {
946
1046
  this.postboy.fire(this.fitPolygonsWaiting);
947
1047
  });
948
1048
  }
1049
+ observePointerMove() {
1050
+ this.postboy.sub(MapPointerMoveEvent).subscribe((ev) => {
1051
+ if (!this.map)
1052
+ return;
1053
+ let featureFound = false;
1054
+ this.map.forEachFeatureAtPixel(ev.point, (f) => {
1055
+ if (f instanceof Feature) {
1056
+ this.postboy.fire(new MapFeatureHoveredEvent(f, f.get(MapConstants.FeatureLayerName)));
1057
+ featureFound = true;
1058
+ }
1059
+ return true;
1060
+ });
1061
+ if (!featureFound)
1062
+ this.postboy.fire(new MapFeatureHoveredEvent(null, null));
1063
+ });
1064
+ }
949
1065
  observeFitToFeatures() {
950
1066
  this.postboy.sub(FitToFeaturesCommand).subscribe((cmd) => {
951
1067
  this.fitToGeometries(cmd.features.map((f) => f.getGeometry()), cmd.zoomAfter);
@@ -1249,6 +1365,8 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1249
1365
  this.recordSubject(CancelDrawingCommand);
1250
1366
  this.recordSubject(StartDrawingCommand);
1251
1367
  this.recordSubject(GetLayerQuery);
1368
+ this.recordSubject(MapFeatureHoveredEvent);
1369
+ this.recordWithPipe(MapPointerMoveEvent, new Subject(), (s) => s.pipe(debounceTime(150)));
1252
1370
  this.recordSubject(DrawingFinishedEvent);
1253
1371
  this.recordSubject(GetFeaturesInAreaQuery);
1254
1372
  this.recordSubject(DrawSelectionAreaCommand);
@@ -1261,6 +1379,7 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1261
1379
  this.recordExecutor(FilterFeaturesInAreaExecutor, (e) => FeatureService.filterFeaturesInArea(e));
1262
1380
  this.recordExecutor(FilterFeaturesInPointExecutor, (e) => FeatureService.filterFeaturesInPoint(e));
1263
1381
  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()); });
1382
+ this.recordExecutor(PolygonSelfIntersectionExecutor, (e) => FeatureService.polygonSelfIntersects(e.polygon.feature));
1264
1383
  this.recordExecutor(GenerateDrawExecutor, (e) => DrawingGenerationService.getDraw(e));
1265
1384
  this.recordExecutor(GenerateZoomControlExecutor, (e) => ZoomControlFactory.build(e.settings));
1266
1385
  this.recordExecutor(GetMapPositionExecutor, () => this.state.getMapPosition());
@@ -1606,6 +1725,7 @@ class FeatureLayerSettings {
1606
1725
  result.minZoom = model.minZoom;
1607
1726
  result.zIndex = model.zIndex;
1608
1727
  result.style = model.style;
1728
+ result.featureHoverStyle = model.featureHoverStyle;
1609
1729
  return result;
1610
1730
  }
1611
1731
  /**
@@ -1654,6 +1774,15 @@ class FeatureLayerSettings {
1654
1774
  setStyle(style) {
1655
1775
  return FeatureLayerSettings.copy(Object.assign(Object.assign({}, this), { style }));
1656
1776
  }
1777
+ /**
1778
+ * Sets the style to apply to features when they are hovered over.
1779
+ *
1780
+ * @param {Style | StyleFunction} featureHoverStyle - The style or style function to use for hovered features.
1781
+ * @return {FeatureLayerSettings} A new instance of FeatureLayerSettings with the updated hover style.
1782
+ */
1783
+ setFeatureHoverStyle(featureHoverStyle) {
1784
+ return FeatureLayerSettings.copy(Object.assign(Object.assign({}, this), { featureHoverStyle }));
1785
+ }
1657
1786
  /**
1658
1787
  * Checks if the given FeatureLayerSettings object is identical to the current object.
1659
1788
  *
@@ -1671,6 +1800,8 @@ class FeatureLayerSettings {
1671
1800
  return false;
1672
1801
  if (this.style !== model.style)
1673
1802
  return false;
1803
+ if (this.featureHoverStyle !== model.featureHoverStyle)
1804
+ return false;
1674
1805
  return true;
1675
1806
  }
1676
1807
  }
@@ -2071,6 +2202,9 @@ class MapPlateComponent extends DestructibleComponent {
2071
2202
  this.map.updateSize();
2072
2203
  this.postboy.fire(new MapRenderedEvent(this.map));
2073
2204
  });
2205
+ this.map.on('pointermove', (ev) => {
2206
+ this.postboy.fire(new MapPointerMoveEvent(ev.pixel));
2207
+ });
2074
2208
  this.setOsm();
2075
2209
  }
2076
2210
  setOsm() {
@@ -2285,7 +2419,10 @@ class PolygonsComponent extends DestructibleComponent {
2285
2419
  putPolygons() {
2286
2420
  if (!this._polygons)
2287
2421
  return;
2288
- this.postboy.fire(new PlaceLayerFeaturesCommand(this.layerName, this._polygons.map((m) => m.feature)));
2422
+ this.postboy.fire(new PlaceLayerFeaturesCommand(this.layerName, this._polygons.map((m) => {
2423
+ m.feature.set(MapConstants.FeatureLayerName, this.layerName);
2424
+ return m.feature;
2425
+ })));
2289
2426
  }
2290
2427
  }
2291
2428
  PolygonsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: PolygonsComponent, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Component });
@@ -2717,5 +2854,5 @@ class StringifyFeatureHelper {
2717
2854
  * Generated bundle index. Do not edit.
2718
2855
  */
2719
2856
 
2720
- 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 };
2857
+ 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 };
2721
2858
  //# sourceMappingURL=maps-components-src-map.mjs.map