From 1a04f2e66168b4c389d37f66db307d5c099a5d70 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 31 May 2021 20:47:08 +0200 Subject: [PATCH] Move isPolygon into OsmObject as it is more appropriate there --- Folder.DotSettings.user | 5 ----- Logic/Osm/OsmObject.ts | 44 +++++++++++++++++++++++++++++++++++++++- Utils.ts | 40 +++--------------------------------- assets/contributors.json | 2 +- 4 files changed, 47 insertions(+), 44 deletions(-) delete mode 100644 Folder.DotSettings.user diff --git a/Folder.DotSettings.user b/Folder.DotSettings.user deleted file mode 100644 index e8c3e8ecb0..0000000000 --- a/Folder.DotSettings.user +++ /dev/null @@ -1,5 +0,0 @@ - - DoNotShowAndRun - <SessionState ContinuousTestingMode="0" IsActive="True" Name="Session" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Nothing /> -</SessionState> \ No newline at end of file diff --git a/Logic/Osm/OsmObject.ts b/Logic/Osm/OsmObject.ts index b303a30638..9b35b48266 100644 --- a/Logic/Osm/OsmObject.ts +++ b/Logic/Osm/OsmObject.ts @@ -1,5 +1,6 @@ import * as $ from "jquery" import {Utils} from "../../Utils"; +import * as polygon_features from "../../assets/polygon-features.json"; export abstract class OsmObject { @@ -11,6 +12,9 @@ export abstract class OsmObject { public changed: boolean = false; timestamp: Date; + + private static polygonFeatures = OsmObject.constructPolygonFeatures() + protected constructor(type: string, id: number) { this.id = id; this.type = type; @@ -67,6 +71,44 @@ export abstract class OsmObject { }) } + private static constructPolygonFeatures(): Map, blacklist: boolean }> { + const result = new Map, blacklist: boolean }>(); + + for (const polygonFeature of polygon_features) { + const key = polygonFeature.key; + + if (polygonFeature.polygon === "all") { + result.set(key, {values: null, blacklist: false}) + continue + } + + const blacklist = polygonFeature.polygon === "blacklist" + result.set(key, {values: new Set(polygonFeature.values), blacklist: blacklist}) + + } + + return result; + } + + + protected static isPolygon(tags: any): boolean { + for (const tagsKey in tags) { + if (!tags.hasOwnProperty(tagsKey)) { + continue + } + const polyGuide = OsmObject.polygonFeatures.get(tagsKey) + if (polyGuide === undefined) { + continue + } + if ((polyGuide.values === null)) { + // We match all + return !polyGuide.blacklist + } + // is the key contained? + return polyGuide.values.has(tags[tagsKey]) + } + } + // bounds should be: [[maxlat, minlon], [minlat, maxlon]] (same as Utils.tile_bounds) public static LoadArea(bounds: [[number, number], [number, number]], callback: (objects: OsmObject[]) => void) { const minlon = bounds[0][1] @@ -356,7 +398,7 @@ export class OsmWay extends OsmObject { if (this.coordinates[0] !== this.coordinates[this.coordinates.length - 1]) { return false; // Not closed } - return Utils.isPolygon(this.tags) + return OsmObject.isPolygon(this.tags) } } diff --git a/Utils.ts b/Utils.ts index bcf87a250e..9b41a260de 100644 --- a/Utils.ts +++ b/Utils.ts @@ -1,5 +1,4 @@ import * as colors from "./assets/colors.json" -import * as polygon_features from "./assets/polygon-features.json" export class Utils { @@ -10,28 +9,12 @@ export class Utils { */ public static runningFromConsole = false; public static readonly assets_path = "./assets/svg/"; - // Empty - private static polygonFeatures = Utils.constructPolygonFeatures() + + + private static knownKeys = ["addExtraTags", "and", "calculatedTags", "changesetmessage", "clustering", "color", "condition", "customCss", "dashArray", "defaultBackgroundId", "description", "descriptionTail", "doNotDownload", "enableAddNewPoints", "enableBackgroundLayerSelection", "enableGeolocation", "enableLayers", "enableMoreQuests", "enableSearch", "enableShareScreen", "enableUserBadge", "freeform", "hideFromOverview", "hideInAnswer", "icon", "iconOverlays", "iconSize", "id", "if", "ifnot", "isShown", "key", "language", "layers", "lockLocation", "maintainer", "mappings", "maxzoom", "maxZoom", "minNeededElements", "minzoom", "multiAnswer", "name", "or", "osmTags", "passAllFeatures", "presets", "question", "render", "roaming", "roamingRenderings", "rotation", "shortDescription", "socialImage", "source", "startLat", "startLon", "startZoom", "tagRenderings", "tags", "then", "title", "titleIcons", "type", "version", "wayHandling", "widenFactor", "width"] private static extraKeys = ["nl", "en", "fr", "de", "pt", "es", "name", "phone", "email", "amenity", "leisure", "highway", "building", "yes", "no", "true", "false"] - public static isPolygon(tags: any): boolean { - for (const tagsKey in tags) { - if (!tags.hasOwnProperty(tagsKey)) { - continue - } - const polyGuide = Utils.polygonFeatures.get(tagsKey) - if (polyGuide === undefined) { - continue - } - if ((polyGuide.values === null)) { - // We match all - return !polyGuide.blacklist - } - // is the key contained? - return polyGuide.values.has(tags[tagsKey]) - } - } static EncodeXmlValue(str) { if (typeof str !== "string") { @@ -346,24 +329,7 @@ export class Utils { return bestColor ?? hex; } - private static constructPolygonFeatures(): Map, blacklist: boolean }> { - const result = new Map, blacklist: boolean }>(); - for (const polygonFeature of polygon_features) { - const key = polygonFeature.key; - - if (polygonFeature.polygon === "all") { - result.set(key, {values: null, blacklist: false}) - continue - } - - const blacklist = polygonFeature.polygon === "blacklist" - result.set(key, {values: new Set(polygonFeature.values), blacklist: blacklist}) - - } - - return result; - } private static tile2long(x, z) { return (x / Math.pow(2, z) * 360 - 180); diff --git a/assets/contributors.json b/assets/contributors.json index 93ad779268..eda3444b78 100644 --- a/assets/contributors.json +++ b/assets/contributors.json @@ -1 +1 @@ -{"contributors":[{"contributor":"Pieter Vander Vennet", "commits":713},{"contributor":"pietervdvn", "commits":641},{"contributor":"Tobias", "commits":35},{"contributor":"Christian Neumann", "commits":33},{"contributor":"Win Olario", "commits":31},{"contributor":"Pieter Fiers", "commits":31},{"contributor":"Sebastian Kürten", "commits":16},{"contributor":"ToastHawaii", "commits":15},{"contributor":"Weblate", "commits":14},{"contributor":"Marco", "commits":14},{"contributor":"Bavo Vanderghote", "commits":12},{"contributor":"Joost", "commits":11},{"contributor":"Midgard", "commits":8},{"contributor":"Jacque Fresco", "commits":8},{"contributor":"Artem", "commits":8},{"contributor":"yopaseopor", "commits":7},{"contributor":"Flo Edelmann", "commits":7},{"contributor":"Binnette", "commits":7},{"contributor":"pelderson", "commits":6},{"contributor":"Mateusz Konieczny", "commits":6},{"contributor":"lvgx", "commits":6},{"contributor":"dependabot[bot]", "commits":6},{"contributor":"Alexey Shabanov", "commits":6},{"contributor":"SiegbjornSitumeang", "commits":4},{"contributor":"Polgár Sándor", "commits":4},{"contributor":"Léo Villeveygoux", "commits":3},{"contributor":"Hosted Weblate", "commits":3},{"contributor":"David Haberthür", "commits":3},{"contributor":"Wiktor Przybylski", "commits":2},{"contributor":"Stanislas Gueniffey", "commits":2},{"contributor":"Robin van der Linde", "commits":2},{"contributor":"riiga", "commits":2},{"contributor":"pbarban", "commits":2},{"contributor":"Leo Alcaraz", "commits":2},{"contributor":"Jan Zabel", "commits":2},{"contributor":"graveelius", "commits":2},{"contributor":"Vinicius", "commits":1},{"contributor":"Tomas Fiers", "commits":1},{"contributor":"Thibault Molleman", "commits":1},{"contributor":"tbowdecl97", "commits":1},{"contributor":"Schouppe Joost", "commits":1},{"contributor":"Noémie", "commits":1},{"contributor":"mozita", "commits":1},{"contributor":"Carlos Ramos Carreño", "commits":1}]} \ No newline at end of file +{"contributors":[{"contributor":"Pieter Vander Vennet", "commits":714},{"contributor":"pietervdvn", "commits":650},{"contributor":"Tobias", "commits":35},{"contributor":"Christian Neumann", "commits":33},{"contributor":"Win Olario", "commits":31},{"contributor":"Pieter Fiers", "commits":31},{"contributor":"Sebastian Kürten", "commits":16},{"contributor":"ToastHawaii", "commits":15},{"contributor":"Weblate", "commits":14},{"contributor":"Marco", "commits":14},{"contributor":"Bavo Vanderghote", "commits":12},{"contributor":"Joost", "commits":11},{"contributor":"Midgard", "commits":8},{"contributor":"Jacque Fresco", "commits":8},{"contributor":"Artem", "commits":8},{"contributor":"yopaseopor", "commits":7},{"contributor":"Flo Edelmann", "commits":7},{"contributor":"Binnette", "commits":7},{"contributor":"pelderson", "commits":6},{"contributor":"Mateusz Konieczny", "commits":6},{"contributor":"lvgx", "commits":6},{"contributor":"dependabot[bot]", "commits":6},{"contributor":"Alexey Shabanov", "commits":6},{"contributor":"SiegbjornSitumeang", "commits":4},{"contributor":"Polgár Sándor", "commits":4},{"contributor":"Léo Villeveygoux", "commits":3},{"contributor":"Hosted Weblate", "commits":3},{"contributor":"David Haberthür", "commits":3},{"contributor":"Wiktor Przybylski", "commits":2},{"contributor":"Stanislas Gueniffey", "commits":2},{"contributor":"Robin van der Linde", "commits":2},{"contributor":"riiga", "commits":2},{"contributor":"pbarban", "commits":2},{"contributor":"Leo Alcaraz", "commits":2},{"contributor":"Jan Zabel", "commits":2},{"contributor":"graveelius", "commits":2},{"contributor":"Vinicius", "commits":1},{"contributor":"Tomas Fiers", "commits":1},{"contributor":"Thibault Molleman", "commits":1},{"contributor":"tbowdecl97", "commits":1},{"contributor":"Schouppe Joost", "commits":1},{"contributor":"Noémie", "commits":1},{"contributor":"mozita", "commits":1},{"contributor":"Carlos Ramos Carreño", "commits":1},{"contributor":"Beardhatcode", "commits":1}]} \ No newline at end of file