@artstesh/maps 4.1.24 → 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.
@@ -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';
@@ -627,6 +627,14 @@ class GetMapPositionExecutor extends PostboyExecutor {
627
627
  }
628
628
  GetMapPositionExecutor.ID = '52c95689-d09b-4082-ba58-9183ea96a213';
629
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
+
630
638
  /**
631
639
  * Class representing a query to get features within a specified geographical area.
632
640
  * The query optionally takes a set of layer names to ignore during the operation.
@@ -764,6 +772,20 @@ class FeatureService {
764
772
  return 0;
765
773
  return Sphere.getArea(g, { projection: 'EPSG:4326' });
766
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
+ }
767
789
  static booleanIntersects(g1, g2) {
768
790
  if (g2.getType() === 'Point')
769
791
  return g1.intersectsCoordinate(g2.getCoordinates());
@@ -773,6 +795,43 @@ class FeatureService {
773
795
  return g1.intersectsCoordinate(g2.getInteriorPoint().getCoordinates());
774
796
  return false;
775
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
+ }
776
835
  }
777
836
 
778
837
  class GenerateDrawExecutor extends PostboyExecutor {
@@ -1320,6 +1379,7 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1320
1379
  this.recordExecutor(FilterFeaturesInAreaExecutor, (e) => FeatureService.filterFeaturesInArea(e));
1321
1380
  this.recordExecutor(FilterFeaturesInPointExecutor, (e) => FeatureService.filterFeaturesInPoint(e));
1322
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));
1323
1383
  this.recordExecutor(GenerateDrawExecutor, (e) => DrawingGenerationService.getDraw(e));
1324
1384
  this.recordExecutor(GenerateZoomControlExecutor, (e) => ZoomControlFactory.build(e.settings));
1325
1385
  this.recordExecutor(GetMapPositionExecutor, () => this.state.getMapPosition());
@@ -2798,5 +2858,5 @@ class StringifyFeatureHelper {
2798
2858
  * Generated bundle index. Do not edit.
2799
2859
  */
2800
2860
 
2801
- 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, PolygonStyleHelper, PolygonsComponent, RemoveControlCommand, SetMapCenterCommand, StartDrawingCommand, StringifyFeatureHelper, TextStyleHelper, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings, ZoomControlSettings };
2861
+ 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 };
2802
2862
  //# sourceMappingURL=maps-components.mjs.map