@artstesh/maps 1.1.23 → 1.1.24

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.
@@ -1188,6 +1188,17 @@
1188
1188
  }(postboy.PostboyExecutor));
1189
1189
  GetMapPositionExecutor.ID = '52c95689-d09b-4082-ba58-9183ea96a213';
1190
1190
 
1191
+ var PolygonSelfIntersectionExecutor = /** @class */ (function (_super) {
1192
+ __extends(PolygonSelfIntersectionExecutor, _super);
1193
+ function PolygonSelfIntersectionExecutor(polygon) {
1194
+ var _this = _super.call(this) || this;
1195
+ _this.polygon = polygon;
1196
+ return _this;
1197
+ }
1198
+ return PolygonSelfIntersectionExecutor;
1199
+ }(postboy.PostboyGenericMessage));
1200
+ PolygonSelfIntersectionExecutor.ID = 'a4ef116d-fe40-4e92-9d4a-653f8b398c62';
1201
+
1191
1202
  /**
1192
1203
  * Class representing a query to get features within a specified geographical area.
1193
1204
  * The query optionally takes a set of layer names to ignore during the operation.
@@ -1364,6 +1375,20 @@
1364
1375
  return 0;
1365
1376
  return Sphere__namespace.getArea(g, { projection: 'EPSG:4326' });
1366
1377
  };
1378
+ FeatureService.polygonSelfIntersects = function (feature) {
1379
+ if (feature.getGeometry().getType() !== 'Polygon')
1380
+ return false;
1381
+ var intersections = 0;
1382
+ var segments = FeatureService.getSegmentsFromCoordinates(feature.getGeometry());
1383
+ for (var i = 0; i < segments.length; i++) {
1384
+ for (var z = i + 1; z < segments.length; z++) {
1385
+ if (!intersections && this.segmentIntersection(segments[i].getCoordinates(), segments[z].getCoordinates())) {
1386
+ intersections++;
1387
+ }
1388
+ }
1389
+ }
1390
+ return intersections !== 0;
1391
+ };
1367
1392
  FeatureService.booleanIntersects = function (g1, g2) {
1368
1393
  if (g2.getType() === 'Point')
1369
1394
  return g1.intersectsCoordinate(g2.getCoordinates());
@@ -1373,6 +1398,43 @@
1373
1398
  return g1.intersectsCoordinate(g2.getInteriorPoint().getCoordinates());
1374
1399
  return false;
1375
1400
  };
1401
+ FeatureService.getSegmentsFromCoordinates = function (geom$1) {
1402
+ if (!geom$1)
1403
+ return [];
1404
+ var coords = geom$1.getCoordinates();
1405
+ var line = new geom.LineString(coords[0]);
1406
+ var segments = [];
1407
+ line.forEachSegment(function (s1, s2) {
1408
+ var l = new geom.LineString([s1, s2]);
1409
+ l.scale(0.999); // bug of the OL, as I see
1410
+ segments.push(l);
1411
+ });
1412
+ return segments;
1413
+ };
1414
+ FeatureService.segmentIntersection = function (s1, s2) {
1415
+ var a = s1[0], b = s1[1], c = s2[0], d = s2[1];
1416
+ var o1 = this.orientation(a, b, c);
1417
+ var o2 = this.orientation(a, b, d);
1418
+ var o3 = this.orientation(c, d, a);
1419
+ var o4 = this.orientation(c, d, b);
1420
+ return ((o1 != o2 && o3 != o4) ||
1421
+ (o1 == 0 && this.onSegment(a, d, b)) ||
1422
+ (o2 == 0 && this.onSegment(a, d, b)) ||
1423
+ (o3 == 0 && this.onSegment(d, a, d)) ||
1424
+ (o4 == 0 && this.onSegment(d, b, d)));
1425
+ };
1426
+ FeatureService.orientation = function (p, q, r) {
1427
+ var val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1]);
1428
+ if (val == 0)
1429
+ return 0; // collinear
1430
+ return val > 0 ? 1 : 2; // clock or counterclock wise
1431
+ };
1432
+ FeatureService.onSegment = function (p, q, r) {
1433
+ return (q[0] <= (p[0] > r[0] ? p[0] : r[0]) &&
1434
+ q[0] >= (p[0] < r[0] ? p[0] : r[0]) &&
1435
+ q[1] <= (p[1] > r[1] ? p[1] : r[1]) &&
1436
+ q[1] >= (p[1] < r[1] ? p[1] : r[1]));
1437
+ };
1376
1438
  return FeatureService;
1377
1439
  }());
1378
1440
 
@@ -1974,6 +2036,7 @@
1974
2036
  this.recordExecutor(FilterFeaturesInAreaExecutor, function (e) { return FeatureService.filterFeaturesInArea(e); });
1975
2037
  this.recordExecutor(FilterFeaturesInPointExecutor, function (e) { return FeatureService.filterFeaturesInPoint(e); });
1976
2038
  this.recordExecutor(CalculateAreaExecutor, function (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()); });
2039
+ this.recordExecutor(PolygonSelfIntersectionExecutor, function (e) { return FeatureService.polygonSelfIntersects(e.polygon.feature); });
1977
2040
  this.recordExecutor(GenerateDrawExecutor, function (e) { return DrawingGenerationService.getDraw(e); });
1978
2041
  this.recordExecutor(GenerateZoomControlExecutor, function (e) { return ZoomControlFactory.build(e.settings); });
1979
2042
  this.recordExecutor(GetMapPositionExecutor, function () { return _this.state.getMapPosition(); });
@@ -3653,6 +3716,7 @@
3653
3716
  exports.ModifyFeatureCommand = ModifyFeatureCommand;
3654
3717
  exports.OsmTileLayerComponent = OsmTileLayerComponent;
3655
3718
  exports.PolygonModel = PolygonModel;
3719
+ exports.PolygonSelfIntersectionExecutor = PolygonSelfIntersectionExecutor;
3656
3720
  exports.PolygonStyleHelper = PolygonStyleHelper;
3657
3721
  exports.PolygonsComponent = PolygonsComponent;
3658
3722
  exports.RemoveControlCommand = RemoveControlCommand;