refactoring: fix basic flow to add a new point

This commit is contained in:
Pieter Vander Vennet 2023-04-06 01:33:08 +02:00
parent 52a0810ea9
commit 0241f89d3d
109 changed files with 1931 additions and 1446 deletions

View file

@ -1,7 +1,7 @@
import { BBox } from "./BBox"
import LayerConfig from "../Models/ThemeConfig/LayerConfig"
import * as turf from "@turf/turf"
import { AllGeoJSON, booleanWithin, Coord } from "@turf/turf"
import { AllGeoJSON, booleanWithin, Coord, Lines } from "@turf/turf"
import {
Feature,
GeoJSON,
@ -273,7 +273,7 @@ export class GeoOperations {
* @param point Point defined as [lon, lat]
*/
public static nearestPoint(
way: Feature<LineString | MultiLineString | Polygon | MultiPolygon>,
way: Feature<LineString>,
point: [number, number]
): Feature<
Point,
@ -951,4 +951,24 @@ export class GeoOperations {
}
throw "CalculateIntersection fallthrough: can not calculate an intersection between features"
}
/**
* Creates a linestring object based on the outer ring of the given polygon
*
* Returns the argument if not a polygon
* @param p
*/
public static outerRing<P>(p: Feature<Polygon | LineString, P>): Feature<LineString, P> {
if (p.geometry.type !== "Polygon") {
return <Feature<LineString, P>>p
}
return {
type: "Feature",
properties: p.properties,
geometry: {
type: "LineString",
coordinates: p.geometry.coordinates[0],
},
}
}
}