forked from MapComplete/MapComplete
Fix NaN issue in 'getClosestFeature', remove unused AspectedRouting metatagging
This commit is contained in:
parent
d4e63d90e4
commit
30bc620827
1 changed files with 13 additions and 36 deletions
|
@ -164,32 +164,13 @@ export class ExtraFunction {
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
private static readonly AspectedRouting = new ExtraFunction(
|
|
||||||
{
|
|
||||||
name: "score",
|
|
||||||
doc: "Given the path of an aspected routing json file, will calculate the score. This score is wrapped in a UIEventSource, so for further calculations, use `.map(score => ...)`" +
|
|
||||||
"\n\n" +
|
|
||||||
"For example: `_comfort_score=feat.score('https://raw.githubusercontent.com/pietervdvn/AspectedRouting/master/Examples/bicycle/aspects/bicycle.comfort.json')`",
|
|
||||||
args: ["path"]
|
|
||||||
},
|
|
||||||
(_, feature) => {
|
|
||||||
return (path) => {
|
|
||||||
return UIEventSourceTools.downloadJsonCached(path).map(config => {
|
|
||||||
if (config === undefined) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return new AspectedRouting(config).evaluate(feature.properties)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
private static readonly allFuncs: ExtraFunction[] = [
|
private static readonly allFuncs: ExtraFunction[] = [
|
||||||
ExtraFunction.DistanceToFunc,
|
ExtraFunction.DistanceToFunc,
|
||||||
ExtraFunction.OverlapFunc,
|
ExtraFunction.OverlapFunc,
|
||||||
ExtraFunction.ClosestObjectFunc,
|
ExtraFunction.ClosestObjectFunc,
|
||||||
ExtraFunction.ClosestNObjectFunc,
|
ExtraFunction.ClosestNObjectFunc,
|
||||||
ExtraFunction.Memberships,
|
ExtraFunction.Memberships
|
||||||
ExtraFunction.AspectedRouting
|
|
||||||
];
|
];
|
||||||
private readonly _name: string;
|
private readonly _name: string;
|
||||||
private readonly _args: string[];
|
private readonly _args: string[];
|
||||||
|
@ -254,22 +235,18 @@ export class ExtraFunction {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selfCenter = GeoOperations.centerpointCoordinates(feature)
|
||||||
let closestFeatures: { feat: any, distance: number }[] = [];
|
let closestFeatures: { feat: any, distance: number }[] = [];
|
||||||
for (const featureList of features) {
|
for (const featureList of features) {
|
||||||
for (const otherFeature of featureList) {
|
for (const otherFeature of featureList) {
|
||||||
if (otherFeature === feature || otherFeature.id === feature.id) {
|
if (otherFeature === feature || otherFeature.id === feature.id) {
|
||||||
continue; // We ignore self
|
continue; // We ignore self
|
||||||
}
|
}
|
||||||
let distance = undefined;
|
const distance = GeoOperations.distanceBetween(
|
||||||
if (otherFeature._lon !== undefined && otherFeature._lat !== undefined) {
|
|
||||||
distance = GeoOperations.distanceBetween([otherFeature._lon, otherFeature._lat], [feature._lon, feature._lat]);
|
|
||||||
} else {
|
|
||||||
distance = GeoOperations.distanceBetween(
|
|
||||||
GeoOperations.centerpointCoordinates(otherFeature),
|
GeoOperations.centerpointCoordinates(otherFeature),
|
||||||
[feature._lon, feature._lat]
|
selfCenter
|
||||||
)
|
)
|
||||||
}
|
if (distance === undefined || distance === null || isNaN(distance)) {
|
||||||
if (distance === undefined || distance === null) {
|
|
||||||
console.error("Could not calculate the distance between", feature, "and", otherFeature)
|
console.error("Could not calculate the distance between", feature, "and", otherFeature)
|
||||||
throw "Undefined distance!"
|
throw "Undefined distance!"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue