diff --git a/scripts/ScriptUtils.ts b/scripts/ScriptUtils.ts index 9ed725d96..62923d2bf 100644 --- a/scripts/ScriptUtils.ts +++ b/scripts/ScriptUtils.ts @@ -5,8 +5,6 @@ import * as https from "https"; import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson"; import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson"; -Utils.runningFromConsole = true - export default class ScriptUtils { @@ -53,7 +51,7 @@ export default class ScriptUtils { try { headers = headers ?? {} headers.accept = "application/json" - console.log("ScriptUtils.DownloadJson(", url.substring(0, 40), url.length > 40 ? "..." : "", ")") + console.log(" > ScriptUtils.DownloadJson(", url, ")") const urlObj = new URL(url) https.get({ host: urlObj.host, diff --git a/scripts/fixTheme.ts b/scripts/fixTheme.ts index fa98e8b48..e5f65750a 100644 --- a/scripts/fixTheme.ts +++ b/scripts/fixTheme.ts @@ -9,9 +9,6 @@ import AllImageProviders from "../Logic/ImageProviders/AllImageProviders"; import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson"; import LayerConfig from "../Models/ThemeConfig/LayerConfig"; -Utils.runningFromConsole = true; - - ScriptUtils.fixUtils() if (process.argv.length == 2) { diff --git a/scripts/generateCache.ts b/scripts/generateCache.ts index 44ce289d4..0134c941f 100644 --- a/scripts/generateCache.ts +++ b/scripts/generateCache.ts @@ -26,7 +26,6 @@ import FilteringFeatureSource from "../Logic/FeatureSource/Sources/FilteringFeat import Loc from "../Models/Loc"; ScriptUtils.fixUtils() - function createOverpassObject(theme: LayoutConfig, relationTracker: RelationsTracker, backend: string) { let filters: TagsFilter[] = []; let extraScripts: string[] = []; @@ -167,6 +166,7 @@ function loadAllTiles(targetdir: string, r: TileRange, theme: LayoutConfig, extr // Create and save the geojson file - which is the main chunk of the data const geojson = OsmToGeoJson.default(rawOsm); + console.log(" which as",geojson.features.length, "features") allFeatures.push(...geojson.features) } @@ -203,6 +203,7 @@ function sliceToTiles(allFeatures: FeatureSource, theme: LayoutConfig, relations const layerId = layer.id if (layer.source.isOsmCacheLayer !== true) { + console.log("Skipping layer ", layerId, ": not a caching layer") skippedLayers.add(layer.id) return; } @@ -241,6 +242,7 @@ function sliceToTiles(allFeatures: FeatureSource, theme: LayoutConfig, relations maxFeatureCount: undefined, registerTile: tile => { const tileIndex = tile.tileIndex; + console.log("Got tile:", tileIndex, tile.layer.layerDef.id) if (tile.features.data.length === 0) { return } @@ -365,7 +367,7 @@ async function main(args: string[]) { const targetdir = args[2] + "/" + themeName if (!existsSync(args[2])) { console.log("Directory not found") - throw "The directory " + args[2] + "does not exist" + throw `The directory ${args[2]} does not exist` } const lat0 = Number(args[3]) diff --git a/scripts/generateDocs.ts b/scripts/generateDocs.ts index 3ef152e7a..c1b1ca500 100644 --- a/scripts/generateDocs.ts +++ b/scripts/generateDocs.ts @@ -1,4 +1,3 @@ -import {Utils} from "../Utils"; import SpecialVisualizations from "../UI/SpecialVisualizations"; import SimpleMetaTagger from "../Logic/SimpleMetaTagger"; import Combine from "../UI/Base/Combine"; @@ -16,9 +15,6 @@ import TableOfContents from "../UI/Base/TableOfContents"; import Title from "../UI/Base/Title"; import QueryParameterDocumentation from "../UI/QueryParameterDocumentation"; -Utils.runningFromConsole = true; - - function WriteFile(filename, html: BaseUIElement, autogenSource: string[]): void { if (html instanceof Combine) { diff --git a/scripts/generateLayouts.ts b/scripts/generateLayouts.ts index 50c631d2b..e77af31eb 100644 --- a/scripts/generateLayouts.ts +++ b/scripts/generateLayouts.ts @@ -1,4 +1,3 @@ -import {Utils} from "../Utils"; import {existsSync, mkdirSync, readFileSync, writeFile, writeFileSync} from "fs"; import Locale from "../UI/i18n/Locale"; import Translations from "../UI/i18n/Translations"; @@ -7,9 +6,6 @@ import Constants from "../Models/Constants"; import * as all_known_layouts from "../assets/generated/known_layers_and_themes.json" import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson"; import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; -// We HAVE to mark this while importing -Utils.runningFromConsole = true; - const sharp = require('sharp'); diff --git a/scripts/generateLicenseInfo.ts b/scripts/generateLicenseInfo.ts index e6c47b922..3d0e4a6b6 100644 --- a/scripts/generateLicenseInfo.ts +++ b/scripts/generateLicenseInfo.ts @@ -1,10 +1,7 @@ -import {Utils} from "../Utils"; import {existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync} from "fs"; import SmallLicense from "../Models/smallLicense"; import ScriptUtils from "./ScriptUtils"; -Utils.runningFromConsole = true; - /** * Sweeps the entire 'assets/' (except assets/generated) directory for image files and any 'license_info.json'-file. * Checks that the license info is included for each of them and generates a compiles license_info.json for those diff --git a/scripts/generateTaginfoProjectFiles.ts b/scripts/generateTaginfoProjectFiles.ts index 58166a11c..2b2f2ef6b 100644 --- a/scripts/generateTaginfoProjectFiles.ts +++ b/scripts/generateTaginfoProjectFiles.ts @@ -1,4 +1,3 @@ -import {Utils} from "../Utils"; import {AllKnownLayouts} from "../Customizations/AllKnownLayouts"; import Locale from "../UI/i18n/Locale"; import {Translation} from "../UI/i18n/Translation"; @@ -6,9 +5,6 @@ import {readFileSync, writeFileSync} from "fs"; import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; import LayerConfig from "../Models/ThemeConfig/LayerConfig"; -Utils.runningFromConsole = true; - - /** * Generates all the files in "Docs/TagInfo". These are picked up by the taginfo project, showing a link to the mapcomplete theme if the key is used */ diff --git a/scripts/generateWikiPage.ts b/scripts/generateWikiPage.ts index 688dfd2fe..904410823 100644 --- a/scripts/generateWikiPage.ts +++ b/scripts/generateWikiPage.ts @@ -1,12 +1,8 @@ -import {Utils} from "../Utils"; import {writeFile} from "fs"; import Translations from "../UI/i18n/Translations"; import {AllKnownLayouts} from "../Customizations/AllKnownLayouts"; import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; -Utils.runningFromConsole = true; - - function generateWikiEntry(layout: LayoutConfig) { if (layout.hideFromOverview) { return ""; diff --git a/scripts/postal_code_tools/createRoutablePoint.ts b/scripts/postal_code_tools/createRoutablePoint.ts new file mode 100644 index 000000000..727030d31 --- /dev/null +++ b/scripts/postal_code_tools/createRoutablePoint.ts @@ -0,0 +1,92 @@ +import {appendFileSync, existsSync, readFileSync, writeFileSync} from "fs"; +import {GeoOperations} from "../../Logic/GeoOperations"; +import ScriptUtils from "../ScriptUtils"; +import {Utils} from "../../Utils"; + + +async function main(args: string[]) { + + const pointCandidates = JSON.parse(readFileSync(args[0], "utf8")) + const postcodes = JSON.parse(readFileSync(args[1], "utf8")) + const output = args[2] ?? "centralCoordinates.csv" + + const perPostCode = new Map() + + const alreadyLoaded = new Set() + if(existsSync(output)){ + const lines = readFileSync(output, "UTF8").split("\n") + lines.shift() + lines.forEach(line => { + const postalCode = Number( line.split(",")[0]) + alreadyLoaded.add(postalCode) + }) + }else{ + writeFileSync(output,"postal_code,lon,lat\n","UTF-8") + } + + for (const boundary of postcodes.features) { + const postcode = boundary.properties.nouveau_PO + if(alreadyLoaded.has(Number(postcode))){ + console.log("Skipping ", postcode, "as already loaded") + continue + } + if (perPostCode.has(postcode)) { + perPostCode.get(postcode).push(boundary) + } else { + perPostCode.set(postcode, [boundary]) + } + + } + + for (const postcode of Array.from(perPostCode.keys())) { + const boundaries = perPostCode.get(postcode) + const candidates = [] + for (const boundary of boundaries) { + for (const candidate of pointCandidates.features) { + if (!GeoOperations.inside(candidate, boundary)) { + // console.log(JSON.stringify(candidate)) + continue + } + candidates.push(candidate.geometry.coordinates) + + } + } + if (candidates.length === 0) { + console.log("Postcode ", postcode, "has", candidates.length, "candidates, using centerpoint instead") + candidates.push(...boundaries.map(boundary => GeoOperations.centerpointCoordinates(boundary))) + } + + + const url = "https://staging.anyways.eu/routing-api/v1/routes?access_token=postal_code_script&turn_by_turn=false&format=geojson&language=en" + const depPoints :[number,number][] = Utils.NoNull( await Promise.all(candidates.map(async candidate => { + try{ + + const result = await ScriptUtils.DownloadJSON(url + "&loc=" + candidate.join("%2C") + "&loc=3.22000%2C51.21577&profile=car.short") + const depPoint = result.features.filter(f => f.geometry.type === "LineString")[0].geometry.coordinates[0] + return <[number,number]>[depPoint[0], depPoint[1]] // Drop elevation + }catch(e){ + console.error("No result or could not calculate a route") + } + }))) + + const centers = boundaries.map(b => GeoOperations.centerpointCoordinates(b)) + const center = GeoOperations.centerpointCoordinates({ + type:"Feature", + geometry:{ + type:"LineString", + coordinates: centers + } + }) + + depPoints.sort((c0, c1) => GeoOperations.distanceBetween(c0, center) - GeoOperations.distanceBetween(c1, center)) + console.log("Sorted departure point candidates for ",postcode," are ", JSON.stringify(depPoints)) + appendFileSync(output,[postcode, ...depPoints[0]].join(", ")+"\n","UTF-8") + } + + +} + + +let args = [...process.argv] +args.splice(0, 2) +main(args).then(_ => console.log("Done!")) \ No newline at end of file diff --git a/scripts/postal_code_tools/genPostal.sh b/scripts/postal_code_tools/genPostal.sh old mode 100644 new mode 100755 index 1b586627f..1784daba4 --- a/scripts/postal_code_tools/genPostal.sh +++ b/scripts/postal_code_tools/genPostal.sh @@ -1,4 +1,5 @@ #! /bin/bash -npm run generate:layeroverview +# npm run generate:layeroverview +cd ../.. ts-node scripts/generateCache.ts postal_codes 8 /home/pietervdvn/Downloads/postal_codes 49.69606181911566 2.373046875 51.754240074033525 6.459960937499999 --generate-point-overview '*' --force-zoom-level 1 \ No newline at end of file diff --git a/scripts/printVersion.ts b/scripts/printVersion.ts index e40773c3e..204b43283 100644 --- a/scripts/printVersion.ts +++ b/scripts/printVersion.ts @@ -1,6 +1,3 @@ -import {Utils} from "../Utils"; import Constants from "../Models/Constants"; -Utils.runningFromConsole = true; - console.log("git tag -a", Constants.vNumber, `-m "Deployed on ${new Date()}"`) \ No newline at end of file diff --git a/test/GeoOperations.spec.ts b/test/GeoOperations.spec.ts index c63564fcc..ccdb87229 100644 --- a/test/GeoOperations.spec.ts +++ b/test/GeoOperations.spec.ts @@ -1,12 +1,9 @@ -import {Utils} from "../Utils"; import * as Assert from "assert"; import {equal} from "assert"; import T from "./TestHelper"; import {GeoOperations} from "../Logic/GeoOperations"; import {BBox} from "../Logic/BBox"; -Utils.runningFromConsole = true; - export default class GeoOperationsSpec extends T { private static polygon = { diff --git a/test/ImageAttribution.spec.ts b/test/ImageAttribution.spec.ts index 08007b277..eb31fb28b 100644 --- a/test/ImageAttribution.spec.ts +++ b/test/ImageAttribution.spec.ts @@ -1,12 +1,9 @@ -import {Utils} from "../Utils"; import {equal} from "assert"; import T from "./TestHelper"; import {Translation} from "../UI/i18n/Translation"; import * as bike_repair_station from "../assets/layers/bike_repair_station/bike_repair_station.json" import LayerConfig from "../Models/ThemeConfig/LayerConfig"; -Utils.runningFromConsole = true; - export default class ImageAttributionSpec extends T { constructor() { super( diff --git a/test/Tag.spec.ts b/test/Tag.spec.ts index 0180a1512..86ba6abda 100644 --- a/test/Tag.spec.ts +++ b/test/Tag.spec.ts @@ -10,9 +10,6 @@ import {And} from "../Logic/Tags/And"; import {TagUtils} from "../Logic/Tags/TagUtils"; import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig"; - -Utils.runningFromConsole = true; - export default class TagSpec extends T { constructor() { diff --git a/test/Theme.spec.ts b/test/Theme.spec.ts index cb6cc2756..6a3f4b2a6 100644 --- a/test/Theme.spec.ts +++ b/test/Theme.spec.ts @@ -4,8 +4,6 @@ import * as assert from "assert"; import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson"; import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; -Utils.runningFromConsole = true; - export default class ThemeSpec extends T { constructor() { super("theme",