From bec1998a6d1470acf8a9a0b88ef2f02bd1700b53 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 29 Mar 2021 02:04:42 +0200 Subject: [PATCH] Fix incorrect imports due to refactoring --- Logic/Actors/UpdateFromOverpass.ts | 4 +- Logic/ExtraFunction.ts | 63 ++++++++++++++++++++++++++---- Logic/SimpleMetaTagger.ts | 6 +-- UI/BigComponents/SimpleAddUI.ts | 4 +- UI/Popup/FeatureInfoBox.ts | 3 +- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/Logic/Actors/UpdateFromOverpass.ts b/Logic/Actors/UpdateFromOverpass.ts index d7b470a..c75239a 100644 --- a/Logic/Actors/UpdateFromOverpass.ts +++ b/Logic/Actors/UpdateFromOverpass.ts @@ -1,12 +1,12 @@ import {UIEventSource} from "../UIEventSource"; import Loc from "../../Models/Loc"; -import {Or} from "../Or"; +import {Or} from "../Tags/Or"; import LayoutConfig from "../../Customizations/JSON/LayoutConfig"; import {Overpass} from "../Osm/Overpass"; import Bounds from "../../Models/Bounds"; import FeatureSource from "../FeatureSource/FeatureSource"; import {Utils} from "../../Utils"; -import {TagsFilter} from "../TagsFilter"; +import {TagsFilter} from "../Tags/TagsFilter"; export default class UpdateFromOverpass implements FeatureSource { diff --git a/Logic/ExtraFunction.ts b/Logic/ExtraFunction.ts index 432a549..e286d1d 100644 --- a/Logic/ExtraFunction.ts +++ b/Logic/ExtraFunction.ts @@ -61,13 +61,60 @@ Some advanced functions are available on feat as well: "Calculates the distance between the feature and a specified point", ["longitude", "latitude"], (featuresPerLayer, feature) => { - return (lon, lat) => { - // Feature._lon and ._lat is conveniently place by one of the other metatags - return GeoOperations.distanceBetween([lon, lat], [feature._lon, feature._lat]); + return (arg0, lat) => { + if(typeof arg0 === "number"){ + const lon = arg0 + // Feature._lon and ._lat is conveniently place by one of the other metatags + return GeoOperations.distanceBetween([lon, lat], [feature._lon, feature._lat]); + }else{ + // arg0 is probably a feature + return GeoOperations.distanceBetween(GeoOperations.centerpointCoordinates(arg0),[feature._lon, feature._lat]) + } + } } ) - private static readonly allFuncs: ExtraFunction[] = [ExtraFunction.DistanceToFunc, ExtraFunction.OverlapFunc]; + + private static ClosestObjectFunc = new ExtraFunction( + "closest", + "Given either a list of geojson features or a single layer name, gives the single object which is nearest to the feature. In the case of ways/polygons, only the centerpoint is considered.", + ["list of features"], + (featuresPerLayer, feature) => { + return (features) => { + if (typeof features === "string") { + features = featuresPerLayer.get(features) + } + let closestFeature = undefined; + let closestDistance = undefined; + for (const otherFeature of features) { + if(otherFeature == feature){ + continue; // We ignore self + } + let distance = undefined; + 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), + [feature._lon, feature._lat] + ) + } + if(distance === undefined){ + throw "Undefined distance!" + } + if(closestFeature === undefined || distance < closestDistance){ + console.log("Distance between ", feature.properties.id, "and", otherFeature.properties.id, "is", distance) + closestFeature = otherFeature + closestDistance = distance; + } + } + return closestFeature; + } + } + ) + + + private static readonly allFuncs: ExtraFunction[] = [ExtraFunction.DistanceToFunc, ExtraFunction.OverlapFunc, ExtraFunction.ClosestObjectFunc]; private readonly _name: string; private readonly _args: string[]; private readonly _doc: string; @@ -91,10 +138,10 @@ Some advanced functions are available on feat as well: return new Combine([ ExtraFunction.intro, "", ...ExtraFunction.allFuncs.map(func => diff --git a/Logic/SimpleMetaTagger.ts b/Logic/SimpleMetaTagger.ts index 4609939..ae77b7b 100644 --- a/Logic/SimpleMetaTagger.ts +++ b/Logic/SimpleMetaTagger.ts @@ -1,8 +1,8 @@ import {GeoOperations} from "./GeoOperations"; import State from "../State"; -import {And} from "./And"; -import {Tag} from "./Tag"; -import {Or} from "./Or"; +import {And} from "./Tags/And"; +import {Tag} from "./Tags/Tag"; +import {Or} from "./Tags/Or"; import {Utils} from "../Utils"; import opening_hours from "opening_hours"; import {UIElement} from "../UI/UIElement"; diff --git a/UI/BigComponents/SimpleAddUI.ts b/UI/BigComponents/SimpleAddUI.ts index 716f8fe..7530837 100644 --- a/UI/BigComponents/SimpleAddUI.ts +++ b/UI/BigComponents/SimpleAddUI.ts @@ -12,8 +12,8 @@ import {FixedUiElement} from "../Base/FixedUiElement"; import Translations from "../i18n/Translations"; import Constants from "../../Models/Constants"; import LayerConfig from "../../Customizations/JSON/LayerConfig"; -import {Tag} from "../../Logic/Tag"; -import {TagUtils} from "../../Logic/TagUtils"; +import {Tag} from "../../Logic/Tags/Tag"; +import {TagUtils} from "../../Logic/Tags/TagUtils"; export default class SimpleAddUI extends UIElement { private readonly _loginButton: UIElement; diff --git a/UI/Popup/FeatureInfoBox.ts b/UI/Popup/FeatureInfoBox.ts index 20c2e28..7cea701 100644 --- a/UI/Popup/FeatureInfoBox.ts +++ b/UI/Popup/FeatureInfoBox.ts @@ -8,8 +8,7 @@ import TagRenderingAnswer from "./TagRenderingAnswer"; import State from "../../State"; import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig"; import ScrollableFullScreen from "../Base/ScrollableFullScreen"; -import {Utils} from "../../Utils"; -import {Tag} from "../../Logic/Tag"; +import {Tag} from "../../Logic/Tags/Tag"; export default class FeatureInfoBox extends ScrollableFullScreen {