@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';
@@ -626,6 +626,14 @@ class GetMapPositionExecutor extends PostboyExecutor {
626
626
  }
627
627
  GetMapPositionExecutor.ID = '52c95689-d09b-4082-ba58-9183ea96a213';
628
628
 
629
+ class PolygonSelfIntersectionExecutor extends PostboyGenericMessage {
630
+ constructor(polygon) {
631
+ super();
632
+ this.polygon = polygon;
633
+ }
634
+ }
635
+ PolygonSelfIntersectionExecutor.ID = 'a4ef116d-fe40-4e92-9d4a-653f8b398c62';
636
+
629
637
  /**
630
638
  * Class representing a query to get features within a specified geographical area.
631
639
  * The query optionally takes a set of layer names to ignore during the operation.
@@ -763,6 +771,20 @@ class FeatureService {
763
771
  return 0;
764
772
  return Sphere.getArea(g, { projection: 'EPSG:4326' });
765
773
  }
774
+ static polygonSelfIntersects(feature) {
775
+ if (feature.getGeometry().getType() !== 'Polygon')
776
+ return false;
777
+ let intersections = 0;
778
+ const segments = FeatureService.getSegmentsFromCoordinates(feature.getGeometry());
779
+ for (let i = 0; i < segments.length; i++) {
780
+ for (let z = i + 1; z < segments.length; z++) {
781
+ if (!intersections && this.segmentIntersection(segments[i].getCoordinates(), segments[z].getCoordinates())) {
782
+ intersections++;
783
+ }
784
+ }
785
+ }
786
+ return intersections !== 0;
787
+ }
766
788
  static booleanIntersects(g1, g2) {
767
789
  if (g2.getType() === 'Point')
768
790
  return g1.intersectsCoordinate(g2.getCoordinates());
@@ -772,6 +794,43 @@ class FeatureService {
772
794
  return g1.intersectsCoordinate(g2.getInteriorPoint().getCoordinates());
773
795
  return false;
774
796
  }
797
+ static getSegmentsFromCoordinates(geom) {
798
+ if (!geom)
799
+ return [];
800
+ const coords = geom.getCoordinates();
801
+ const line = new LineString(coords[0]);
802
+ const segments = [];
803
+ line.forEachSegment((s1, s2) => {
804
+ const l = new LineString([s1, s2]);
805
+ l.scale(0.999); // bug of the OL, as I see
806
+ segments.push(l);
807
+ });
808
+ return segments;
809
+ }
810
+ static segmentIntersection(s1, s2) {
811
+ const a = s1[0], b = s1[1], c = s2[0], d = s2[1];
812
+ const o1 = this.orientation(a, b, c);
813
+ const o2 = this.orientation(a, b, d);
814
+ const o3 = this.orientation(c, d, a);
815
+ const o4 = this.orientation(c, d, b);
816
+ return ((o1 != o2 && o3 != o4) ||
817
+ (o1 == 0 && this.onSegment(a, d, b)) ||
818
+ (o2 == 0 && this.onSegment(a, d, b)) ||
819
+ (o3 == 0 && this.onSegment(d, a, d)) ||
820
+ (o4 == 0 && this.onSegment(d, b, d)));
821
+ }
822
+ static orientation(p, q, r) {
823
+ const val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1]);
824
+ if (val == 0)
825
+ return 0; // collinear
826
+ return val > 0 ? 1 : 2; // clock or counterclock wise
827
+ }
828
+ static onSegment(p, q, r) {
829
+ return (q[0] <= (p[0] > r[0] ? p[0] : r[0]) &&
830
+ q[0] >= (p[0] < r[0] ? p[0] : r[0]) &&
831
+ q[1] <= (p[1] > r[1] ? p[1] : r[1]) &&
832
+ q[1] >= (p[1] < r[1] ? p[1] : r[1]));
833
+ }
775
834
  }
776
835
 
777
836
  class GenerateDrawExecutor extends PostboyExecutor {
@@ -1305,6 +1364,7 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1305
1364
  this.recordExecutor(FilterFeaturesInAreaExecutor, (e) => FeatureService.filterFeaturesInArea(e));
1306
1365
  this.recordExecutor(FilterFeaturesInPointExecutor, (e) => FeatureService.filterFeaturesInPoint(e));
1307
1366
  this.recordExecutor(CalculateAreaExecutor, (e) => FeatureService.calculateArea(e.polygon?.feature?.getGeometry()));
1367
+ this.recordExecutor(PolygonSelfIntersectionExecutor, (e) => FeatureService.polygonSelfIntersects(e.polygon.feature));
1308
1368
  this.recordExecutor(GenerateDrawExecutor, (e) => DrawingGenerationService.getDraw(e));
1309
1369
  this.recordExecutor(GenerateZoomControlExecutor, (e) => ZoomControlFactory.build(e.settings));
1310
1370
  this.recordExecutor(GetMapPositionExecutor, () => this.state.getMapPosition());
@@ -2775,5 +2835,5 @@ class StringifyFeatureHelper {
2775
2835
  * Generated bundle index. Do not edit.
2776
2836
  */
2777
2837
 
2778
- 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 };
2838
+ 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 };
2779
2839
  //# sourceMappingURL=maps-components.mjs.map