Fix generation of docs by injecting dependency
This commit is contained in:
parent
a4445eed3e
commit
59d53e5ec5
3 changed files with 34 additions and 16 deletions
|
@ -5,7 +5,6 @@ import {And, Or, Tag} from "./Tags";
|
|||
import {Utils} from "../Utils";
|
||||
import {UIElement} from "../UI/UIElement";
|
||||
import Combine from "../UI/Base/Combine";
|
||||
import CountryCoder from "latlon2country"
|
||||
|
||||
class SimpleMetaTagger {
|
||||
public readonly keys: string[];
|
||||
|
@ -42,6 +41,7 @@ class SimpleMetaTagger {
|
|||
export default class MetaTagging {
|
||||
|
||||
|
||||
static coder: any;
|
||||
private static latlon = new SimpleMetaTagger(["_lat", "_lon"], "The latitude and longitude of the point (or centerpoint in the case of a way/area)",
|
||||
(feature => {
|
||||
const centerPoint = GeoOperations.centerpoint(feature);
|
||||
|
@ -64,12 +64,12 @@ export default class MetaTagging {
|
|||
["_country"], "The country code of the property (with latlon2country)",
|
||||
feature => {
|
||||
|
||||
const coder = new CountryCoder("https://pietervdvn.github.io/latlon2country/");
|
||||
|
||||
let centerPoint: any = GeoOperations.centerpoint(feature);
|
||||
const lat = centerPoint.geometry.coordinates[1];
|
||||
const lon = centerPoint.geometry.coordinates[0];
|
||||
coder.GetCountryCodeFor(lon, lat, (countries) => {
|
||||
|
||||
MetaTagging.GetCountryCodeFor(lon, lat, (countries) => {
|
||||
try {
|
||||
feature.properties["_country"] = countries[0].trim().toLowerCase();
|
||||
const tagsSource = State.state.allElements.getEventSourceFor(feature);
|
||||
|
@ -143,7 +143,6 @@ export default class MetaTagging {
|
|||
})
|
||||
})
|
||||
)
|
||||
|
||||
private static directionSimplified = new SimpleMetaTagger(
|
||||
["_direction:simplified", "_direction:leftright"], "_direction:simplified turns 'camera:direction' and 'direction' into either 0, 45, 90, 135, 180, 225, 270 or 315, whichever is closest. _direction:leftright is either 'left' or 'right', which is left-looking on the map or 'right-looking' on the map",
|
||||
(feature => {
|
||||
|
@ -167,7 +166,6 @@ export default class MetaTagging {
|
|||
|
||||
})
|
||||
)
|
||||
|
||||
private static carriageWayWidth = new SimpleMetaTagger(
|
||||
["_width:needed", "_width:needed:no_pedestrians", "_width:difference"],
|
||||
"Legacy for a specific project calculating the needed width for safe traffic on a road. Only activated if 'width:carriageway' is present",
|
||||
|
@ -276,7 +274,6 @@ export default class MetaTagging {
|
|||
|
||||
}
|
||||
);
|
||||
|
||||
private static currentTime = new SimpleMetaTagger(
|
||||
["_now:date", "_now:datetime", "_loaded:date", "_loaded:_datetime"],
|
||||
"Adds the time that the data got loaded - pretty much the time of downloading from overpass. The format is YYYY-MM-DD hh:mm, aka 'sortable' aka ISO-8601-but-not-entirely",
|
||||
|
@ -294,6 +291,7 @@ export default class MetaTagging {
|
|||
function datetime(d: Date) {
|
||||
return d.toISOString().slice(0, -5).replace("T", " ");
|
||||
}
|
||||
|
||||
feature.properties["_now:date"] = date(now);
|
||||
feature.properties["_now:datetime"] = datetime(now);
|
||||
feature.properties["_loaded:date"] = date(freshness);
|
||||
|
@ -301,7 +299,6 @@ export default class MetaTagging {
|
|||
|
||||
}
|
||||
)
|
||||
|
||||
private static metatags = [
|
||||
MetaTagging.latlon,
|
||||
MetaTagging.surfaceArea,
|
||||
|
@ -330,8 +327,20 @@ export default class MetaTagging {
|
|||
|
||||
}
|
||||
|
||||
static GetCountryCodeFor(lon: number, lat: number, callback: (country: string) => void) {
|
||||
MetaTagging.coder.GetCountryCodeFor(lon, lat, callback)
|
||||
}
|
||||
|
||||
static HelpText(): UIElement {
|
||||
const subElements: UIElement[] = [];
|
||||
const subElements: UIElement[] = [
|
||||
new Combine([
|
||||
"<h1>Metatags</h1>",
|
||||
"Metatags are extra tags available, in order to display more data or to give better questions.",
|
||||
"The are calculated when the data arrives in the webbrowser. This document gives an overview of the available metatags"
|
||||
])
|
||||
|
||||
|
||||
];
|
||||
|
||||
for (const metatag of MetaTagging.metatags) {
|
||||
subElements.push(
|
||||
|
|
9
index.ts
9
index.ts
|
@ -11,6 +11,15 @@ import State from "./State";
|
|||
import Combine from "./UI/Base/Combine";
|
||||
import Translations from "./UI/i18n/Translations";
|
||||
|
||||
|
||||
import CountryCoder from "latlon2country"
|
||||
|
||||
import MetaTagging from "./Logic/MetaTagging";
|
||||
|
||||
// Workaround for a stupid crash: inject the function
|
||||
MetaTagging.coder = new CountryCoder("https://pietervdvn.github.io/latlon2country/");
|
||||
|
||||
|
||||
let defaultLayout = ""
|
||||
// --------------------- Special actions based on the parameters -----------------
|
||||
// @ts-ignore
|
||||
|
|
|
@ -14,7 +14,7 @@ function WriteFile(filename, html: UIElement) : void {
|
|||
}
|
||||
|
||||
WriteFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage)
|
||||
// WriteFile("./Docs/CalculatedTags.md", MetaTagging.HelpText())
|
||||
WriteFile("./Docs/CalculatedTags.md", MetaTagging.HelpText())
|
||||
|
||||
|
||||
console.log("Generated docs")
|
||||
|
|
Loading…
Reference in a new issue