Scripts: fix overview-support for osm-community, switch server

This commit is contained in:
Pieter Vander Vennet 2025-01-27 03:14:19 +01:00
parent 90aa2f1fc1
commit 30604304eb
4 changed files with 23 additions and 9 deletions
.forgejo/workflows
assets/layers/osm_community_index
scripts
src/Logic/FeatureSource/TiledFeatureSource

View file

@ -22,11 +22,14 @@ jobs:
run: npm ci
shell: bash
- name: update community index files
- name: create community index files
shell: bash
run: npm run download:community-index -- -- community-index/
- name: upload community index
shell: bash
run: |
mkdir community-index
npm run download:community-index -- -- community-index/
zip community-index.zip community-index/*
scp community-index.zip hetzner:data/
ssh hetzner "cd data && rm -rf community-index/ && unzip community-index.zip && rm community-index.zip"

View file

@ -19,7 +19,7 @@
"es": "Una capa que muestra las comunidades de OpenStreetMap"
},
"source": {
"geoJson": "https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/community_index/tile_{z}_{x}_{y}.geojson",
"geoJson": "https://data.mapcomplete.org/community-index/tile_{z}_{x}_{y}.geojson",
"geoJsonZoomLevel": 6,
"osmTags": "resources~*"
},

View file

@ -2,7 +2,7 @@ import Script from "./Script"
import { CommunityResource } from "../src/Logic/Web/CommunityIndex"
import { Utils } from "../src/Utils"
import { FeatureCollection, MultiPolygon, Polygon } from "geojson"
import { writeFileSync } from "fs"
import { existsSync, mkdirSync, writeFileSync } from "fs"
import { GeoOperations } from "../src/Logic/GeoOperations"
import { Tiles } from "../src/Models/TileRange"
import ScriptUtils from "./ScriptUtils"
@ -53,6 +53,9 @@ class DownloadCommunityIndex extends Script {
id: string
}>>(DownloadCommunityIndex.upstreamUrl + "completeFeatureCollection.json"
)
if (!existsSync(targetDirectory)) {
mkdirSync(targetDirectory)
}
const features = data.features
const global = features.find(
f => f.id === "Q2"
@ -76,6 +79,7 @@ class DownloadCommunityIndex extends Script {
const spread = GeoOperations.spreadIntoBboxes(local, DownloadCommunityIndex.targetZoomlevel)
let written = 0
let skipped = 0
const writtenTilesOverview: Record<number, number[]> = {}
writeFileSync(targetDirectory + "local.geojson", JSON.stringify({ type: "FeatureCollection", features: local }))
for (const tileIndex of spread.keys()) {
const features = spread.get(tileIndex)
@ -95,9 +99,16 @@ class DownloadCommunityIndex extends Script {
})
writeFileSync(path, JSON.stringify({ type: "FeatureCollection", features: clipped }), "utf8")
written++
let yList = writtenTilesOverview[x]
if (!yList) {
yList = []
writtenTilesOverview[x] = yList
}
yList.push(y)
console.log(`Written tile ${path}`)
}
console.log(`Created ${written} tiles, skipped ${skipped}`)
writeFileSync(targetDirectory + "/tiles_6_overview.json", JSON.stringify(writtenTilesOverview), "utf8")
}

View file

@ -6,7 +6,7 @@ import { BBox } from "../../BBox"
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
export default class DynamicGeoJsonTileSource extends UpdatableDynamicTileSource {
private static whitelistCache = new Map<string, any>()
private static whitelistCache = new Map<string, Map<number, Set<number>>>()
constructor(
layer: LayerConfig,
@ -27,7 +27,7 @@ export default class DynamicGeoJsonTileSource extends UpdatableDynamicTileSource
}
console.log("Creating a dynamic geojson source for", layer.source.geojsonSource)
let whitelist = undefined
let whitelist: Map<number, Set<number>> = undefined
if (source.geojsonSource.indexOf("{x}_{y}.geojson") > 0) {
const whitelistUrl = source.geojsonSource
.replace("{z}", "" + source.geojsonZoomLevel)
@ -37,8 +37,8 @@ export default class DynamicGeoJsonTileSource extends UpdatableDynamicTileSource
if (DynamicGeoJsonTileSource.whitelistCache.has(whitelistUrl)) {
whitelist = DynamicGeoJsonTileSource.whitelistCache.get(whitelistUrl)
} else {
Utils.downloadJsonCached(whitelistUrl, 1000 * 60 * 60)
.then((json) => {
Utils.downloadJsonCached<Record<string | number, number[]>>(whitelistUrl, 1000 * 60 * 60)
.then(json => {
const data = new Map<number, Set<number>>()
for (const x in json) {
if (x === "zoom") {