forked from MapComplete/MapComplete
		
	Scripts: fix overview-support for osm-community, switch server
This commit is contained in:
		
							parent
							
								
									90aa2f1fc1
								
							
						
					
					
						commit
						30604304eb
					
				
					 4 changed files with 23 additions and 9 deletions
				
			
		| 
						 | 
					@ -22,11 +22,14 @@ jobs:
 | 
				
			||||||
        run: npm ci
 | 
					        run: npm ci
 | 
				
			||||||
        shell: bash
 | 
					        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
 | 
					        shell: bash
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
          mkdir community-index
 | 
					 | 
				
			||||||
          npm run download:community-index -- -- community-index/
 | 
					 | 
				
			||||||
          zip community-index.zip community-index/*
 | 
					          zip community-index.zip community-index/*
 | 
				
			||||||
          scp community-index.zip hetzner:data/
 | 
					          scp community-index.zip hetzner:data/
 | 
				
			||||||
 | 
					          ssh hetzner "cd data && rm -rf community-index/ && unzip community-index.zip && rm community-index.zip"
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@
 | 
				
			||||||
    "es": "Una capa que muestra las comunidades de OpenStreetMap"
 | 
					    "es": "Una capa que muestra las comunidades de OpenStreetMap"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "source": {
 | 
					  "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,
 | 
					    "geoJsonZoomLevel": 6,
 | 
				
			||||||
    "osmTags": "resources~*"
 | 
					    "osmTags": "resources~*"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ import Script from "./Script"
 | 
				
			||||||
import { CommunityResource } from "../src/Logic/Web/CommunityIndex"
 | 
					import { CommunityResource } from "../src/Logic/Web/CommunityIndex"
 | 
				
			||||||
import { Utils } from "../src/Utils"
 | 
					import { Utils } from "../src/Utils"
 | 
				
			||||||
import { FeatureCollection, MultiPolygon, Polygon } from "geojson"
 | 
					import { FeatureCollection, MultiPolygon, Polygon } from "geojson"
 | 
				
			||||||
import { writeFileSync } from "fs"
 | 
					import { existsSync, mkdirSync, writeFileSync } from "fs"
 | 
				
			||||||
import { GeoOperations } from "../src/Logic/GeoOperations"
 | 
					import { GeoOperations } from "../src/Logic/GeoOperations"
 | 
				
			||||||
import { Tiles } from "../src/Models/TileRange"
 | 
					import { Tiles } from "../src/Models/TileRange"
 | 
				
			||||||
import ScriptUtils from "./ScriptUtils"
 | 
					import ScriptUtils from "./ScriptUtils"
 | 
				
			||||||
| 
						 | 
					@ -53,6 +53,9 @@ class DownloadCommunityIndex extends Script {
 | 
				
			||||||
            id: string
 | 
					            id: string
 | 
				
			||||||
        }>>(DownloadCommunityIndex.upstreamUrl + "completeFeatureCollection.json"
 | 
					        }>>(DownloadCommunityIndex.upstreamUrl + "completeFeatureCollection.json"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        if (!existsSync(targetDirectory)) {
 | 
				
			||||||
 | 
					            mkdirSync(targetDirectory)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        const features = data.features
 | 
					        const features = data.features
 | 
				
			||||||
        const global = features.find(
 | 
					        const global = features.find(
 | 
				
			||||||
            f => f.id === "Q2"
 | 
					            f => f.id === "Q2"
 | 
				
			||||||
| 
						 | 
					@ -76,6 +79,7 @@ class DownloadCommunityIndex extends Script {
 | 
				
			||||||
        const spread = GeoOperations.spreadIntoBboxes(local, DownloadCommunityIndex.targetZoomlevel)
 | 
					        const spread = GeoOperations.spreadIntoBboxes(local, DownloadCommunityIndex.targetZoomlevel)
 | 
				
			||||||
        let written = 0
 | 
					        let written = 0
 | 
				
			||||||
        let skipped = 0
 | 
					        let skipped = 0
 | 
				
			||||||
 | 
					        const writtenTilesOverview: Record<number, number[]> = {}
 | 
				
			||||||
        writeFileSync(targetDirectory + "local.geojson", JSON.stringify({ type: "FeatureCollection", features: local }))
 | 
					        writeFileSync(targetDirectory + "local.geojson", JSON.stringify({ type: "FeatureCollection", features: local }))
 | 
				
			||||||
        for (const tileIndex of spread.keys()) {
 | 
					        for (const tileIndex of spread.keys()) {
 | 
				
			||||||
            const features = spread.get(tileIndex)
 | 
					            const features = spread.get(tileIndex)
 | 
				
			||||||
| 
						 | 
					@ -95,9 +99,16 @@ class DownloadCommunityIndex extends Script {
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            writeFileSync(path, JSON.stringify({ type: "FeatureCollection", features: clipped }), "utf8")
 | 
					            writeFileSync(path, JSON.stringify({ type: "FeatureCollection", features: clipped }), "utf8")
 | 
				
			||||||
            written++
 | 
					            written++
 | 
				
			||||||
 | 
					            let yList = writtenTilesOverview[x]
 | 
				
			||||||
 | 
					            if (!yList) {
 | 
				
			||||||
 | 
					                yList = []
 | 
				
			||||||
 | 
					                writtenTilesOverview[x] = yList
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            yList.push(y)
 | 
				
			||||||
            console.log(`Written tile ${path}`)
 | 
					            console.log(`Written tile ${path}`)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        console.log(`Created ${written} tiles, skipped ${skipped}`)
 | 
					        console.log(`Created ${written} tiles, skipped ${skipped}`)
 | 
				
			||||||
 | 
					        writeFileSync(targetDirectory + "/tiles_6_overview.json", JSON.stringify(writtenTilesOverview), "utf8")
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ import { BBox } from "../../BBox"
 | 
				
			||||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
 | 
					import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class DynamicGeoJsonTileSource extends UpdatableDynamicTileSource {
 | 
					export default class DynamicGeoJsonTileSource extends UpdatableDynamicTileSource {
 | 
				
			||||||
    private static whitelistCache = new Map<string, any>()
 | 
					    private static whitelistCache = new Map<string, Map<number, Set<number>>>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(
 | 
					    constructor(
 | 
				
			||||||
        layer: LayerConfig,
 | 
					        layer: LayerConfig,
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ export default class DynamicGeoJsonTileSource extends UpdatableDynamicTileSource
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        console.log("Creating a dynamic geojson source for", layer.source.geojsonSource)
 | 
					        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) {
 | 
					        if (source.geojsonSource.indexOf("{x}_{y}.geojson") > 0) {
 | 
				
			||||||
            const whitelistUrl = source.geojsonSource
 | 
					            const whitelistUrl = source.geojsonSource
 | 
				
			||||||
                .replace("{z}", "" + source.geojsonZoomLevel)
 | 
					                .replace("{z}", "" + source.geojsonZoomLevel)
 | 
				
			||||||
| 
						 | 
					@ -37,8 +37,8 @@ export default class DynamicGeoJsonTileSource extends UpdatableDynamicTileSource
 | 
				
			||||||
            if (DynamicGeoJsonTileSource.whitelistCache.has(whitelistUrl)) {
 | 
					            if (DynamicGeoJsonTileSource.whitelistCache.has(whitelistUrl)) {
 | 
				
			||||||
                whitelist = DynamicGeoJsonTileSource.whitelistCache.get(whitelistUrl)
 | 
					                whitelist = DynamicGeoJsonTileSource.whitelistCache.get(whitelistUrl)
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                Utils.downloadJsonCached(whitelistUrl, 1000 * 60 * 60)
 | 
					                Utils.downloadJsonCached<Record<string | number, number[]>>(whitelistUrl, 1000 * 60 * 60)
 | 
				
			||||||
                    .then((json) => {
 | 
					                    .then(json => {
 | 
				
			||||||
                        const data = new Map<number, Set<number>>()
 | 
					                        const data = new Map<number, Set<number>>()
 | 
				
			||||||
                        for (const x in json) {
 | 
					                        for (const x in json) {
 | 
				
			||||||
                            if (x === "zoom") {
 | 
					                            if (x === "zoom") {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue