Themes: various fixes to velopark, see #1783
This commit is contained in:
parent
3b549a5a0b
commit
2583feef65
7 changed files with 261 additions and 202 deletions
|
@ -156,7 +156,7 @@ export class GeoOperations {
|
|||
const intersection = GeoOperations.calculateIntersection(
|
||||
feature,
|
||||
otherFeature,
|
||||
featureBBox
|
||||
featureBBox,
|
||||
)
|
||||
if (intersection === null) {
|
||||
continue
|
||||
|
@ -195,7 +195,7 @@ export class GeoOperations {
|
|||
console.error(
|
||||
"Could not correctly calculate the overlap of ",
|
||||
feature,
|
||||
": unsupported type"
|
||||
": unsupported type",
|
||||
)
|
||||
return result
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ export class GeoOperations {
|
|||
*/
|
||||
public static inside(
|
||||
pointCoordinate: [number, number] | Feature<Point>,
|
||||
feature: Feature
|
||||
feature: Feature,
|
||||
): boolean {
|
||||
// ray-casting algorithm based on
|
||||
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||
|
@ -302,7 +302,7 @@ export class GeoOperations {
|
|||
*/
|
||||
public static nearestPoint(
|
||||
way: Feature<LineString>,
|
||||
point: [number, number]
|
||||
point: [number, number],
|
||||
): Feature<
|
||||
Point,
|
||||
{
|
||||
|
@ -324,11 +324,11 @@ export class GeoOperations {
|
|||
public static forceLineString(way: Feature<LineString | Polygon>): Feature<LineString>
|
||||
|
||||
public static forceLineString(
|
||||
way: Feature<MultiLineString | MultiPolygon>
|
||||
way: Feature<MultiLineString | MultiPolygon>,
|
||||
): Feature<MultiLineString>
|
||||
|
||||
public static forceLineString(
|
||||
way: Feature<LineString | MultiLineString | Polygon | MultiPolygon>
|
||||
way: Feature<LineString | MultiLineString | Polygon | MultiPolygon>,
|
||||
): Feature<LineString | MultiLineString> {
|
||||
if (way.geometry.type === "Polygon") {
|
||||
way = { ...way }
|
||||
|
@ -352,8 +352,8 @@ export class GeoOperations {
|
|||
const headerValuesOrdered: string[] = []
|
||||
|
||||
function addH(key: string) {
|
||||
if(options?.ignoreTags){
|
||||
if(key.match(options.ignoreTags)){
|
||||
if (options?.ignoreTags) {
|
||||
if (key.match(options.ignoreTags)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ export class GeoOperations {
|
|||
*/
|
||||
public static LineIntersections(
|
||||
feature: Feature<LineString | MultiLineString | Polygon | MultiPolygon>,
|
||||
otherFeature: Feature<LineString | MultiLineString | Polygon | MultiPolygon>
|
||||
otherFeature: Feature<LineString | MultiLineString | Polygon | MultiPolygon>,
|
||||
): [number, number][] {
|
||||
return turf
|
||||
.lineIntersect(feature, otherFeature)
|
||||
|
@ -492,7 +492,7 @@ export class GeoOperations {
|
|||
locations:
|
||||
| Feature<LineString>
|
||||
| Feature<Point, { date?: string; altitude?: number | string }>[],
|
||||
title?: string
|
||||
title?: string,
|
||||
) {
|
||||
title = title?.trim()
|
||||
if (title === undefined || title === "") {
|
||||
|
@ -513,7 +513,7 @@ export class GeoOperations {
|
|||
type: "Point",
|
||||
coordinates: p,
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
for (const l of locationsWithMeta) {
|
||||
|
@ -528,7 +528,7 @@ export class GeoOperations {
|
|||
trackPoints.push(trkpt)
|
||||
}
|
||||
const header =
|
||||
'<gpx version="1.1" creator="mapcomplete.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
|
||||
"<gpx version=\"1.1\" creator=\"mapcomplete.org\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"
|
||||
return (
|
||||
header +
|
||||
"\n<name>" +
|
||||
|
@ -546,7 +546,7 @@ export class GeoOperations {
|
|||
*/
|
||||
public static toGpxPoints(
|
||||
locations: Feature<Point, { date?: string; altitude?: number | string }>[],
|
||||
title?: string
|
||||
title?: string,
|
||||
) {
|
||||
title = title?.trim()
|
||||
if (title === undefined || title === "") {
|
||||
|
@ -567,7 +567,7 @@ export class GeoOperations {
|
|||
trackPoints.push(trkpt)
|
||||
}
|
||||
const header =
|
||||
'<gpx version="1.1" creator="mapcomplete.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
|
||||
"<gpx version=\"1.1\" creator=\"mapcomplete.org\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"
|
||||
return (
|
||||
header +
|
||||
"\n<name>" +
|
||||
|
@ -655,7 +655,7 @@ export class GeoOperations {
|
|||
},
|
||||
},
|
||||
distanceMeter,
|
||||
{ units: "meters" }
|
||||
{ units: "meters" },
|
||||
).geometry.coordinates
|
||||
}
|
||||
|
||||
|
@ -690,7 +690,7 @@ export class GeoOperations {
|
|||
*/
|
||||
static completelyWithin(
|
||||
feature: Feature<Geometry, any>,
|
||||
possiblyEnclosingFeature: Feature<Polygon | MultiPolygon, any>
|
||||
possiblyEnclosingFeature: Feature<Polygon | MultiPolygon, any>,
|
||||
): boolean {
|
||||
return booleanWithin(feature, possiblyEnclosingFeature)
|
||||
}
|
||||
|
@ -746,7 +746,7 @@ export class GeoOperations {
|
|||
*/
|
||||
public static featureToCoordinateWithRenderingType(
|
||||
feature: Feature,
|
||||
location: "point" | "centroid" | "start" | "end" | "projected_centerpoint" | string
|
||||
location: "point" | "centroid" | "start" | "end" | "projected_centerpoint" | "polygon_centerpoint" | string,
|
||||
): [number, number] | undefined {
|
||||
switch (location) {
|
||||
case "point":
|
||||
|
@ -759,6 +759,11 @@ export class GeoOperations {
|
|||
return undefined
|
||||
}
|
||||
return GeoOperations.centerpointCoordinates(feature)
|
||||
case "polygon_centerpoint":
|
||||
if (feature.geometry.type === "Polygon") {
|
||||
return GeoOperations.centerpointCoordinates(feature)
|
||||
}
|
||||
return undefined
|
||||
case "projected_centerpoint":
|
||||
if (
|
||||
feature.geometry.type === "LineString" ||
|
||||
|
@ -767,7 +772,7 @@ export class GeoOperations {
|
|||
const centerpoint = GeoOperations.centerpointCoordinates(feature)
|
||||
const projected = GeoOperations.nearestPoint(
|
||||
<Feature<LineString>>feature,
|
||||
centerpoint
|
||||
centerpoint,
|
||||
)
|
||||
return <[number, number]>projected.geometry.coordinates
|
||||
}
|
||||
|
@ -944,7 +949,7 @@ export class GeoOperations {
|
|||
* GeoOperations.bearingToHuman(46) // => "NE"
|
||||
*/
|
||||
public static bearingToHuman(
|
||||
bearing: number
|
||||
bearing: number,
|
||||
): "N" | "NE" | "E" | "SE" | "S" | "SW" | "W" | "NW" {
|
||||
while (bearing < 0) {
|
||||
bearing += 360
|
||||
|
@ -970,7 +975,7 @@ export class GeoOperations {
|
|||
*
|
||||
*/
|
||||
public static bearingToHumanRelative(
|
||||
bearing: number
|
||||
bearing: number,
|
||||
):
|
||||
| "straight"
|
||||
| "slight_right"
|
||||
|
@ -995,12 +1000,12 @@ export class GeoOperations {
|
|||
private static pointInPolygonCoordinates(
|
||||
x: number,
|
||||
y: number,
|
||||
coordinates: [number, number][][]
|
||||
coordinates: [number, number][][],
|
||||
): boolean {
|
||||
const inside = GeoOperations.pointWithinRing(
|
||||
x,
|
||||
y,
|
||||
/*This is the outer ring of the polygon */ coordinates[0]
|
||||
/*This is the outer ring of the polygon */ coordinates[0],
|
||||
)
|
||||
if (!inside) {
|
||||
return false
|
||||
|
@ -1009,7 +1014,7 @@ export class GeoOperations {
|
|||
const inHole = GeoOperations.pointWithinRing(
|
||||
x,
|
||||
y,
|
||||
coordinates[i] /* These are inner rings, aka holes*/
|
||||
coordinates[i], /* These are inner rings, aka holes*/
|
||||
)
|
||||
if (inHole) {
|
||||
return false
|
||||
|
@ -1047,7 +1052,7 @@ export class GeoOperations {
|
|||
feature,
|
||||
otherFeature,
|
||||
featureBBox: BBox,
|
||||
otherFeatureBBox?: BBox
|
||||
otherFeatureBBox?: BBox,
|
||||
): number {
|
||||
if (feature.geometry.type === "LineString") {
|
||||
otherFeatureBBox = otherFeatureBBox ?? BBox.get(otherFeature)
|
||||
|
@ -1096,7 +1101,7 @@ export class GeoOperations {
|
|||
let intersection = turf.lineSlice(
|
||||
turf.point(intersectionPointsArray[0]),
|
||||
turf.point(intersectionPointsArray[1]),
|
||||
feature
|
||||
feature,
|
||||
)
|
||||
|
||||
if (intersection == null) {
|
||||
|
@ -1117,7 +1122,7 @@ export class GeoOperations {
|
|||
otherFeature,
|
||||
feature,
|
||||
otherFeatureBBox,
|
||||
featureBBox
|
||||
featureBBox,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1137,7 +1142,7 @@ export class GeoOperations {
|
|||
console.log("Applying fallback intersection...")
|
||||
const intersection = turf.intersect(
|
||||
turf.truncate(feature),
|
||||
turf.truncate(otherFeature)
|
||||
turf.truncate(otherFeature),
|
||||
)
|
||||
if (intersection == null) {
|
||||
return null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue