forked from MapComplete/MapComplete
		
	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 {Utils} from "../Utils";
 | 
				
			||||||
import {UIElement} from "../UI/UIElement";
 | 
					import {UIElement} from "../UI/UIElement";
 | 
				
			||||||
import Combine from "../UI/Base/Combine";
 | 
					import Combine from "../UI/Base/Combine";
 | 
				
			||||||
import CountryCoder from "latlon2country"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SimpleMetaTagger {
 | 
					class SimpleMetaTagger {
 | 
				
			||||||
    public readonly keys: string[];
 | 
					    public readonly keys: string[];
 | 
				
			||||||
| 
						 | 
					@ -42,6 +41,7 @@ class SimpleMetaTagger {
 | 
				
			||||||
export default class MetaTagging {
 | 
					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)",
 | 
					    private static latlon = new SimpleMetaTagger(["_lat", "_lon"], "The latitude and longitude of the point (or centerpoint in the case of a way/area)",
 | 
				
			||||||
        (feature => {
 | 
					        (feature => {
 | 
				
			||||||
            const centerPoint = GeoOperations.centerpoint(feature);
 | 
					            const centerPoint = GeoOperations.centerpoint(feature);
 | 
				
			||||||
| 
						 | 
					@ -64,12 +64,12 @@ export default class MetaTagging {
 | 
				
			||||||
        ["_country"], "The country code of the property (with latlon2country)",
 | 
					        ["_country"], "The country code of the property (with latlon2country)",
 | 
				
			||||||
        feature => {
 | 
					        feature => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const coder = new CountryCoder("https://pietervdvn.github.io/latlon2country/");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            let centerPoint: any = GeoOperations.centerpoint(feature);
 | 
					            let centerPoint: any = GeoOperations.centerpoint(feature);
 | 
				
			||||||
            const lat = centerPoint.geometry.coordinates[1];
 | 
					            const lat = centerPoint.geometry.coordinates[1];
 | 
				
			||||||
            const lon = centerPoint.geometry.coordinates[0];
 | 
					            const lon = centerPoint.geometry.coordinates[0];
 | 
				
			||||||
            coder.GetCountryCodeFor(lon, lat, (countries) => {
 | 
					
 | 
				
			||||||
 | 
					            MetaTagging.GetCountryCodeFor(lon, lat, (countries) => {
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    feature.properties["_country"] = countries[0].trim().toLowerCase();
 | 
					                    feature.properties["_country"] = countries[0].trim().toLowerCase();
 | 
				
			||||||
                    const tagsSource = State.state.allElements.getEventSourceFor(feature);
 | 
					                    const tagsSource = State.state.allElements.getEventSourceFor(feature);
 | 
				
			||||||
| 
						 | 
					@ -143,7 +143,6 @@ export default class MetaTagging {
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static directionSimplified = new SimpleMetaTagger(
 | 
					    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",
 | 
					        ["_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 => {
 | 
					        (feature => {
 | 
				
			||||||
| 
						 | 
					@ -167,7 +166,6 @@ export default class MetaTagging {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static carriageWayWidth = new SimpleMetaTagger(
 | 
					    private static carriageWayWidth = new SimpleMetaTagger(
 | 
				
			||||||
        ["_width:needed", "_width:needed:no_pedestrians", "_width:difference"],
 | 
					        ["_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",
 | 
					        "Legacy for a specific project calculating the needed width for safe traffic on a road. Only activated if 'width:carriageway' is present",
 | 
				
			||||||
| 
						 | 
					@ -276,14 +274,13 @@ export default class MetaTagging {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static currentTime = new SimpleMetaTagger(
 | 
					    private static currentTime = new SimpleMetaTagger(
 | 
				
			||||||
        ["_now:date", "_now:datetime", "_loaded:date", "_loaded:_datetime"],
 | 
					        ["_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",
 | 
					        "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",
 | 
				
			||||||
        (feature, _, freshness) => {
 | 
					        (feature, _, freshness) => {
 | 
				
			||||||
            const now = new Date();
 | 
					            const now = new Date();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(typeof freshness === "string" ){
 | 
					            if (typeof freshness === "string") {
 | 
				
			||||||
                freshness = new Date(freshness)
 | 
					                freshness = new Date(freshness)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -294,6 +291,7 @@ export default class MetaTagging {
 | 
				
			||||||
            function datetime(d: Date) {
 | 
					            function datetime(d: Date) {
 | 
				
			||||||
                return d.toISOString().slice(0, -5).replace("T", " ");
 | 
					                return d.toISOString().slice(0, -5).replace("T", " ");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            feature.properties["_now:date"] = date(now);
 | 
					            feature.properties["_now:date"] = date(now);
 | 
				
			||||||
            feature.properties["_now:datetime"] = datetime(now);
 | 
					            feature.properties["_now:datetime"] = datetime(now);
 | 
				
			||||||
            feature.properties["_loaded:date"] = date(freshness);
 | 
					            feature.properties["_loaded:date"] = date(freshness);
 | 
				
			||||||
| 
						 | 
					@ -301,7 +299,6 @@ export default class MetaTagging {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static metatags = [
 | 
					    private static metatags = [
 | 
				
			||||||
        MetaTagging.latlon,
 | 
					        MetaTagging.latlon,
 | 
				
			||||||
        MetaTagging.surfaceArea,
 | 
					        MetaTagging.surfaceArea,
 | 
				
			||||||
| 
						 | 
					@ -317,7 +314,7 @@ export default class MetaTagging {
 | 
				
			||||||
     * An actor which adds metatags on every feature in the given object
 | 
					     * An actor which adds metatags on every feature in the given object
 | 
				
			||||||
     * The features are a list of geojson-features, with a "properties"-field and geometry
 | 
					     * The features are a list of geojson-features, with a "properties"-field and geometry
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    static addMetatags(features: {feature: any, freshness: Date}[]) {
 | 
					    static addMetatags(features: { feature: any, freshness: Date }[]) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const metatag of MetaTagging.metatags) {
 | 
					        for (const metatag of MetaTagging.metatags) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
| 
						 | 
					@ -330,8 +327,20 @@ export default class MetaTagging {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static HelpText() : UIElement{
 | 
					    static GetCountryCodeFor(lon: number, lat: number, callback: (country: string) => void) {
 | 
				
			||||||
        const subElements: UIElement[] = [];
 | 
					        MetaTagging.coder.GetCountryCodeFor(lon, lat, callback)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    static HelpText(): 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) {
 | 
					        for (const metatag of MetaTagging.metatags) {
 | 
				
			||||||
            subElements.push(
 | 
					            subElements.push(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										9
									
								
								index.ts
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								index.ts
									
										
									
									
									
								
							| 
						 | 
					@ -11,6 +11,15 @@ import State from "./State";
 | 
				
			||||||
import Combine from "./UI/Base/Combine";
 | 
					import Combine from "./UI/Base/Combine";
 | 
				
			||||||
import Translations from "./UI/i18n/Translations";
 | 
					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 = ""
 | 
					let defaultLayout = ""
 | 
				
			||||||
// --------------------- Special actions based on the parameters -----------------
 | 
					// --------------------- Special actions based on the parameters -----------------
 | 
				
			||||||
// @ts-ignore
 | 
					// @ts-ignore
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ function WriteFile(filename, html: UIElement) : void {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WriteFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage)
 | 
					WriteFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage)
 | 
				
			||||||
// WriteFile("./Docs/CalculatedTags.md", MetaTagging.HelpText())
 | 
					WriteFile("./Docs/CalculatedTags.md", MetaTagging.HelpText())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
console.log("Generated docs")
 | 
					console.log("Generated docs")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue