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
|
@ -135,10 +135,10 @@ export class ExtraFunction {
|
||||||
args: ["list of features or layer name", "amount of features", "unique tag key (optional)", "maxDistanceInMeters (optional)"]
|
args: ["list of features or layer name", "amount of features", "unique tag key (optional)", "maxDistanceInMeters (optional)"]
|
||||||
},
|
},
|
||||||
(params, feature) => {
|
(params, feature) => {
|
||||||
|
|
||||||
return (features, amount, uniqueTag, maxDistanceInMeters) => {
|
return (features, amount, uniqueTag, maxDistanceInMeters) => {
|
||||||
let distance : number = Number(maxDistanceInMeters)
|
let distance: number = Number(maxDistanceInMeters)
|
||||||
if(isNaN(distance)){
|
if (isNaN(distance)) {
|
||||||
distance = undefined
|
distance = undefined
|
||||||
}
|
}
|
||||||
return ExtraFunction.GetClosestNFeatures(params, feature, features, {
|
return ExtraFunction.GetClosestNFeatures(params, feature, features, {
|
||||||
|
@ -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[];
|
||||||
|
@ -247,29 +228,25 @@ export class ExtraFunction {
|
||||||
const name = features
|
const name = features
|
||||||
const bbox = GeoOperations.bbox(GeoOperations.buffer(GeoOperations.bbox(feature), maxDistance))
|
const bbox = GeoOperations.bbox(GeoOperations.buffer(GeoOperations.bbox(feature), maxDistance))
|
||||||
features = params.getFeaturesWithin(name, new BBox(bbox.geometry.coordinates))
|
features = params.getFeaturesWithin(name, new BBox(bbox.geometry.coordinates))
|
||||||
}else{
|
} else {
|
||||||
features = [features]
|
features = [features]
|
||||||
}
|
}
|
||||||
if (features === undefined) {
|
if (features === undefined) {
|
||||||
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) {
|
GeoOperations.centerpointCoordinates(otherFeature),
|
||||||
distance = GeoOperations.distanceBetween([otherFeature._lon, otherFeature._lat], [feature._lon, feature._lat]);
|
selfCenter
|
||||||
} else {
|
)
|
||||||
distance = GeoOperations.distanceBetween(
|
if (distance === undefined || distance === null || isNaN(distance)) {
|
||||||
GeoOperations.centerpointCoordinates(otherFeature),
|
|
||||||
[feature._lon, feature._lat]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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