diff --git a/.forgejo/workflows/daily_data_maintenance.yml b/.forgejo/workflows/daily_data_maintenance.yml index adbcbd94ac..6e2b3922a0 100644 --- a/.forgejo/workflows/daily_data_maintenance.yml +++ b/.forgejo/workflows/daily_data_maintenance.yml @@ -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" diff --git a/assets/layers/osm_community_index/osm_community_index.json b/assets/layers/osm_community_index/osm_community_index.json index 0f50782567..df2bf5a5ba 100644 --- a/assets/layers/osm_community_index/osm_community_index.json +++ b/assets/layers/osm_community_index/osm_community_index.json @@ -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~*" }, diff --git a/scripts/downloadCommunityIndex.ts b/scripts/downloadCommunityIndex.ts index fe4d4dcc02..6643b23de5 100644 --- a/scripts/downloadCommunityIndex.ts +++ b/scripts/downloadCommunityIndex.ts @@ -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 = {} 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") } diff --git a/src/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts b/src/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts index 7cb3428563..848d8734b0 100644 --- a/src/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts +++ b/src/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts @@ -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() + private static whitelistCache = new Map>>() 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> = 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>(whitelistUrl, 1000 * 60 * 60) + .then(json => { const data = new Map>() for (const x in json) { if (x === "zoom") {