Use latlon2country instead of codegrid
This commit is contained in:
parent
89b2dc8a10
commit
c2b1f6643b
6 changed files with 44 additions and 30 deletions
|
@ -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"});
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
2
State.ts
2
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 = {
|
||||
|
|
17
package-lock.json
generated
17
package-lock.json
generated
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
23
test.ts
23
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)
|
||||
/*/
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue