From c2b1f6643b574b01370eb1f401de20faff3f00bf Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 4 Dec 2020 21:30:35 +0100 Subject: [PATCH] Use latlon2country instead of codegrid --- Logic/MetaTagging.ts | 23 +++++++++-------------- Logic/Web/QueryParameters.ts | 8 ++++++-- State.ts | 2 +- package-lock.json | 17 +++++++++++++++++ package.json | 1 + test.ts | 23 ++++++++++------------- 6 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Logic/MetaTagging.ts b/Logic/MetaTagging.ts index d2991ea..cec759e 100644 --- a/Logic/MetaTagging.ts +++ b/Logic/MetaTagging.ts @@ -4,6 +4,7 @@ import State from "../State"; import opening_hours from "opening_hours"; import {And, Or, Tag} from "./Tags"; import {Utils} from "../Utils"; +import CountryCoder from "latlon2country/lib/countryCoder"; class SimpleMetaTagger { @@ -61,28 +62,22 @@ export default class MetaTagging { }) ); private static country = new SimpleMetaTagger( - ["_country"], "The country code of the point", + ["_country"], "", ((feature, index) => { + const coder = new CountryCoder("https://pietervdvn.github.io/latlon2country/"); const centerPoint = GeoOperations.centerpoint(feature); const lat = centerPoint.geometry.coordinates[1]; const lon = centerPoint.geometry.coordinates[0] // But the codegrid SHOULD be a number! - CodeGrid.getCode(lat, lon, (error, code) => { - if (error === null) { - feature.properties["_country"] = code; - - // There is a huge performance issue: if there are ~1000 features receiving a ping at the same time, - // The application hangs big time - // So we disable pinging all together - - } else { - console.warn("Could not determine country for", feature.properties.id, error); - } + coder.CountryCodeFor(lon, lat, (countries) => { + feature.properties["_country"] = countries[0]; + console.log("Country is ",countries.join(";")) }); }) ) private static isOpen = new SimpleMetaTagger( - ["_isOpen", "_isOpen:description"], "If 'opening_hours' is present, it will add the current state of the feature (being 'yes' or 'no')", + ["_isOpen", "_isOpen:description"], + "If 'opening_hours' is present, it will add the current state of the feature (being 'yes' or 'no')", (feature => { const tagsSource = State.state.allElements.addOrGetElement(feature); tagsSource.addCallback(tags => { @@ -98,7 +93,7 @@ export default class MetaTagging { lat: tags._lat, lon: tags._lon, address: { - country_code: tags._country + country_code: tags._country.toLowerCase() } }, {tag_key: "opening_hours"}); diff --git a/Logic/Web/QueryParameters.ts b/Logic/Web/QueryParameters.ts index dd8456e..08cd37a 100644 --- a/Logic/Web/QueryParameters.ts +++ b/Logic/Web/QueryParameters.ts @@ -27,7 +27,6 @@ export class QueryParameters { this.initialized = true; if (window?.location?.search) { - console.log("Window.location.search is",window.location.search) const params = window.location.search.substr(1).split("&"); for (const param of params) { const kv = param.split("="); @@ -51,7 +50,12 @@ export class QueryParameters { if (QueryParameters.knownSources[key].data === undefined) { continue; } - + + if (QueryParameters.knownSources[key].data === "undefined") { + continue; + } + + if (QueryParameters.knownSources[key].data == QueryParameters.defaults[key]) { continue; } diff --git a/State.ts b/State.ts index 143d4da..91d6c49 100644 --- a/State.ts +++ b/State.ts @@ -23,7 +23,7 @@ export default class State { // The singleton of the global state public static state: State; - public static vNumber = "0.2.3b"; + public static vNumber = "0.2.3d"; // The user journey states thresholds when a new feature gets unlocked public static userJourney = { diff --git a/package-lock.json b/package-lock.json index 21245de..b43b070 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4291,6 +4291,23 @@ "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==" }, + "latlon2country": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/latlon2country/-/latlon2country-1.0.3.tgz", + "integrity": "sha512-cIm43mCve6PcIoHIkyw/14YdyEyn+G6+m5wkbM6FR9/bZSHUDV4uQayFp3+kHLfnOgTqm9gwIQ6Py7YoduspDQ==", + "requires": { + "@types/node": "^14.14.10", + "jquery": "^3.5.1", + "turf": "^3.0.14" + }, + "dependencies": { + "@types/node": { + "version": "14.14.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.10.tgz", + "integrity": "sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ==" + } + } + }, "lazy-cache": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", diff --git a/package.json b/package.json index b15b17b..9df44bc 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "escape-html": "^1.0.3", "i18next-client": "^1.11.4", "jquery": "latest", + "latlon2country": "^1.0.3", "leaflet": "^1.7.1", "leaflet-providers": "^1.10.2", "libphonenumber": "0.0.10", diff --git a/test.ts b/test.ts index 87cb971..af87e93 100644 --- a/test.ts +++ b/test.ts @@ -1,20 +1,17 @@ //* +import CountryCoder from "latlon2country/lib/countryCoder"; -import Direction from "./UI/Input/DirectionInput"; -import {UIEventSource} from "./Logic/UIEventSource"; -import {VariableUiElement} from "./UI/Base/VariableUIElement"; - -const d = new UIEventSource("90"); -new Direction(d).AttachTo("maindiv") -new VariableUiElement(d.map(d => "" + d + "°")).AttachTo("extradiv") - -UIEventSource.Chronic(25, () => { - const degr = (Number(d.data) + 1) % 360; - d.setData(""+ degr); - return true; -}) +f +unction pr(countries) { + console.log(">>>>>", countries.join(";")) +} +coder.CountryCodeFor(3.2, 51.2, pr) +coder.CountryCodeFor(4.2, 51.2, pr); +coder.CountryCodeFor(4.92119, 51.43995, pr) +coder.CountryCodeFor(4.93189, 51.43552, pr) +coder.CountryCodeFor(34.2581, 44.7536, pr) /*/