@artstesh/maps 6.1.3 → 6.1.5

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 (29) hide show
  1. package/dist/esm2022/map/messages/commands/modify-feature.command.mjs +8 -5
  2. package/dist/esm2022/map/messages/executors/polygon-self-intersection.executor.mjs +10 -0
  3. package/dist/esm2022/map/messages/index.mjs +2 -1
  4. package/dist/esm2022/map/public-api.mjs +2 -1
  5. package/dist/esm2022/map/services/drawing/feature-modification.service.mjs +3 -2
  6. package/dist/esm2022/map/services/feature.service.mjs +53 -2
  7. package/dist/esm2022/map/services/message-registrator.service.mjs +3 -2
  8. package/dist/esm2022/src/map/messages/commands/modify-feature.command.mjs +8 -5
  9. package/dist/esm2022/src/map/messages/executors/polygon-self-intersection.executor.mjs +10 -0
  10. package/dist/esm2022/src/map/messages/index.mjs +2 -1
  11. package/dist/esm2022/src/map/public-api.mjs +2 -1
  12. package/dist/esm2022/src/map/services/drawing/feature-modification.service.mjs +3 -2
  13. package/dist/esm2022/src/map/services/feature.service.mjs +53 -2
  14. package/dist/esm2022/src/map/services/message-registrator.service.mjs +3 -2
  15. package/dist/fesm2022/maps-components-src-map.mjs +73 -7
  16. package/dist/fesm2022/maps-components-src-map.mjs.map +1 -1
  17. package/dist/fesm2022/maps-components.mjs +73 -7
  18. package/dist/fesm2022/maps-components.mjs.map +1 -1
  19. package/dist/map/messages/commands/modify-feature.command.d.ts +6 -4
  20. package/dist/map/messages/executors/polygon-self-intersection.executor.d.ts +7 -0
  21. package/dist/map/messages/index.d.ts +1 -0
  22. package/dist/map/public-api.d.ts +1 -0
  23. package/dist/map/services/feature.service.d.ts +5 -0
  24. package/dist/src/map/messages/commands/modify-feature.command.d.ts +6 -4
  25. package/dist/src/map/messages/executors/polygon-self-intersection.executor.d.ts +7 -0
  26. package/dist/src/map/messages/index.d.ts +1 -0
  27. package/dist/src/map/public-api.d.ts +1 -0
  28. package/dist/src/map/services/feature.service.d.ts +5 -0
  29. 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';
@@ -27,6 +27,7 @@ import View from 'ol/View';
27
27
  import Overlay from 'ol/Overlay';
28
28
  import Style from 'ol/style/Style';
29
29
  import { Icon, Circle, Fill, Stroke, Text } from 'ol/style';
30
+ export { Style } from 'ol/style';
30
31
  import { METERS_PER_UNIT } from 'ol/proj/epsg4326';
31
32
 
32
33
  class DestructibleComponent {
@@ -402,19 +403,22 @@ class ModifyFeatureCommand extends PostboyCallbackMessage {
402
403
  model;
403
404
  style;
404
405
  format;
406
+ draggable;
405
407
  static ID = '8f76507e-f18d-4232-bab7-f3d4e3d707bb';
406
408
  /**
407
409
  * Constructs an instance of the class.
408
410
  *
409
- * @param {PolygonModel} model - The polygon model to be used.
410
- * @param {Style} style - The style configuration for the polygon.
411
- * @param {FeatureOutputFormat} [format=FeatureOutputFormat.GeoJson] - The output format of the features. Default is GeoJson.
411
+ * @param {PolygonModel} model - The model representing the polygon data.
412
+ * @param {Style} style - The style to be applied to the polygon.
413
+ * @param {FeatureOutputFormat} [format=FeatureOutputFormat.GeoJson] - The output format of the feature, defaults to GeoJson.
414
+ * @param {boolean} [draggable=true] - Determines whether the polygon is draggable, defaults to true.
412
415
  */
413
- constructor(model, style, format = FeatureOutputFormat.GeoJson) {
416
+ constructor(model, style, format = FeatureOutputFormat.GeoJson, draggable = true) {
414
417
  super();
415
418
  this.model = model;
416
419
  this.style = style;
417
420
  this.format = format;
421
+ this.draggable = draggable;
418
422
  }
419
423
  }
420
424
 
@@ -664,6 +668,15 @@ class GetMapPositionExecutor extends PostboyExecutor {
664
668
  }
665
669
  }
666
670
 
671
+ class PolygonSelfIntersectionExecutor extends PostboyGenericMessage {
672
+ polygon;
673
+ static ID = 'a4ef116d-fe40-4e92-9d4a-653f8b398c62';
674
+ constructor(polygon) {
675
+ super();
676
+ this.polygon = polygon;
677
+ }
678
+ }
679
+
667
680
  /**
668
681
  * Class representing a query to get features within a specified geographical area.
669
682
  * The query optionally takes a set of layer names to ignore during the operation.
@@ -815,6 +828,20 @@ class FeatureService {
815
828
  return 0;
816
829
  return Sphere.getArea(g, { projection: 'EPSG:4326' });
817
830
  }
831
+ static polygonSelfIntersects(feature) {
832
+ if (feature.getGeometry().getType() !== 'Polygon')
833
+ return false;
834
+ let intersections = 0;
835
+ const segments = FeatureService.getSegmentsFromCoordinates(feature.getGeometry());
836
+ for (let i = 0; i < segments.length; i++) {
837
+ for (let z = i + 1; z < segments.length; z++) {
838
+ if (!intersections && this.segmentIntersection(segments[i].getCoordinates(), segments[z].getCoordinates())) {
839
+ intersections++;
840
+ }
841
+ }
842
+ }
843
+ return intersections !== 0;
844
+ }
818
845
  static booleanIntersects(g1, g2) {
819
846
  if (g2.getType() === 'Point')
820
847
  return g1.intersectsCoordinate(g2.getCoordinates());
@@ -824,6 +851,43 @@ class FeatureService {
824
851
  return g1.intersectsCoordinate(g2.getInteriorPoint().getCoordinates());
825
852
  return false;
826
853
  }
854
+ static getSegmentsFromCoordinates(geom) {
855
+ if (!geom)
856
+ return [];
857
+ const coords = geom.getCoordinates();
858
+ const line = new LineString(coords[0]);
859
+ const segments = [];
860
+ line.forEachSegment((s1, s2) => {
861
+ const l = new LineString([s1, s2]);
862
+ l.scale(0.999); // bug of the OL, as I see
863
+ segments.push(l);
864
+ });
865
+ return segments;
866
+ }
867
+ static segmentIntersection(s1, s2) {
868
+ const a = s1[0], b = s1[1], c = s2[0], d = s2[1];
869
+ const o1 = this.orientation(a, b, c);
870
+ const o2 = this.orientation(a, b, d);
871
+ const o3 = this.orientation(c, d, a);
872
+ const o4 = this.orientation(c, d, b);
873
+ return ((o1 != o2 && o3 != o4) ||
874
+ (o1 == 0 && this.onSegment(a, d, b)) ||
875
+ (o2 == 0 && this.onSegment(a, d, b)) ||
876
+ (o3 == 0 && this.onSegment(d, a, d)) ||
877
+ (o4 == 0 && this.onSegment(d, b, d)));
878
+ }
879
+ static orientation(p, q, r) {
880
+ const val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1]);
881
+ if (val == 0)
882
+ return 0; // collinear
883
+ return val > 0 ? 1 : 2; // clock or counterclock wise
884
+ }
885
+ static onSegment(p, q, r) {
886
+ return (q[0] <= (p[0] > r[0] ? p[0] : r[0]) &&
887
+ q[0] >= (p[0] < r[0] ? p[0] : r[0]) &&
888
+ q[1] <= (p[1] > r[1] ? p[1] : r[1]) &&
889
+ q[1] >= (p[1] < r[1] ? p[1] : r[1]));
890
+ }
827
891
  }
828
892
 
829
893
  class GenerateDrawExecutor extends PostboyExecutor {
@@ -1238,7 +1302,8 @@ class FeatureModificationService {
1238
1302
  this.observeCancelation(ev, l);
1239
1303
  this.initFeature(l, ev.model.feature);
1240
1304
  this.addModify(ev);
1241
- this.addDragging(ev);
1305
+ if (ev.draggable)
1306
+ this.addDragging(ev);
1242
1307
  });
1243
1308
  });
1244
1309
  }
@@ -1377,6 +1442,7 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
1377
1442
  this.recordExecutor(FilterFeaturesInAreaExecutor, (e) => FeatureService.filterFeaturesInArea(e));
1378
1443
  this.recordExecutor(FilterFeaturesInPointExecutor, (e) => FeatureService.filterFeaturesInPoint(e));
1379
1444
  this.recordExecutor(CalculateAreaExecutor, (e) => FeatureService.calculateArea(e.polygon?.feature?.getGeometry()));
1445
+ this.recordExecutor(PolygonSelfIntersectionExecutor, (e) => FeatureService.polygonSelfIntersects(e.polygon.feature));
1380
1446
  this.recordExecutor(GenerateDrawExecutor, (e) => DrawingGenerationService.getDraw(e));
1381
1447
  this.recordExecutor(GenerateZoomControlExecutor, (e) => ZoomControlFactory.build(e.settings));
1382
1448
  this.recordExecutor(GetMapPositionExecutor, () => this.state.getMapPosition());
@@ -2888,5 +2954,5 @@ class StringifyFeatureHelper {
2888
2954
  * Generated bundle index. Do not edit.
2889
2955
  */
2890
2956
 
2891
- 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 };
2957
+ 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 };
2892
2958
  //# sourceMappingURL=maps-components.mjs.map