Move isPolygon into OsmObject as it is more appropriate there
This commit is contained in:
parent
8564a1a5b0
commit
1a04f2e661
4 changed files with 47 additions and 44 deletions
|
@ -1,5 +0,0 @@
|
||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
|
||||||
<s:String x:Key="/Default/CodeInspection/Highlighting/SweaWarningsMode/@EntryValue">DoNotShowAndRun</s:String>
|
|
||||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d2f95dca_002Defa2_002D40b6_002D8190_002D724496f13a75/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Session" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
|
||||||
<Nothing />
|
|
||||||
</SessionState></s:String></wpf:ResourceDictionary>
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as $ from "jquery"
|
import * as $ from "jquery"
|
||||||
import {Utils} from "../../Utils";
|
import {Utils} from "../../Utils";
|
||||||
|
import * as polygon_features from "../../assets/polygon-features.json";
|
||||||
|
|
||||||
|
|
||||||
export abstract class OsmObject {
|
export abstract class OsmObject {
|
||||||
|
@ -11,6 +12,9 @@ export abstract class OsmObject {
|
||||||
public changed: boolean = false;
|
public changed: boolean = false;
|
||||||
timestamp: Date;
|
timestamp: Date;
|
||||||
|
|
||||||
|
|
||||||
|
private static polygonFeatures = OsmObject.constructPolygonFeatures()
|
||||||
|
|
||||||
protected constructor(type: string, id: number) {
|
protected constructor(type: string, id: number) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -67,6 +71,44 @@ export abstract class OsmObject {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static constructPolygonFeatures(): Map<string, { values: Set<string>, blacklist: boolean }> {
|
||||||
|
const result = new Map<string, { values: Set<string>, 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<string>(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)
|
// bounds should be: [[maxlat, minlon], [minlat, maxlon]] (same as Utils.tile_bounds)
|
||||||
public static LoadArea(bounds: [[number, number], [number, number]], callback: (objects: OsmObject[]) => void) {
|
public static LoadArea(bounds: [[number, number], [number, number]], callback: (objects: OsmObject[]) => void) {
|
||||||
const minlon = bounds[0][1]
|
const minlon = bounds[0][1]
|
||||||
|
@ -356,7 +398,7 @@ export class OsmWay extends OsmObject {
|
||||||
if (this.coordinates[0] !== this.coordinates[this.coordinates.length - 1]) {
|
if (this.coordinates[0] !== this.coordinates[this.coordinates.length - 1]) {
|
||||||
return false; // Not closed
|
return false; // Not closed
|
||||||
}
|
}
|
||||||
return Utils.isPolygon(this.tags)
|
return OsmObject.isPolygon(this.tags)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
Utils.ts
40
Utils.ts
|
@ -1,5 +1,4 @@
|
||||||
import * as colors from "./assets/colors.json"
|
import * as colors from "./assets/colors.json"
|
||||||
import * as polygon_features from "./assets/polygon-features.json"
|
|
||||||
|
|
||||||
export class Utils {
|
export class Utils {
|
||||||
|
|
||||||
|
@ -10,28 +9,12 @@ export class Utils {
|
||||||
*/
|
*/
|
||||||
public static runningFromConsole = false;
|
public static runningFromConsole = false;
|
||||||
public static readonly assets_path = "./assets/svg/";
|
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 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"]
|
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) {
|
static EncodeXmlValue(str) {
|
||||||
if (typeof str !== "string") {
|
if (typeof str !== "string") {
|
||||||
|
@ -346,24 +329,7 @@ export class Utils {
|
||||||
return bestColor ?? hex;
|
return bestColor ?? hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static constructPolygonFeatures(): Map<string, { values: Set<string>, blacklist: boolean }> {
|
|
||||||
const result = new Map<string, { values: Set<string>, 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<string>(polygonFeature.values), blacklist: blacklist})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static tile2long(x, z) {
|
private static tile2long(x, z) {
|
||||||
return (x / Math.pow(2, z) * 360 - 180);
|
return (x / Math.pow(2, z) * 360 - 180);
|
||||||
|
|
|
@ -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}]}
|
{"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}]}
|
Loading…
Add table
Reference in a new issue