forked from MapComplete/MapComplete
		
	Merge branch 'master' into develop
This commit is contained in:
		
						commit
						b2d1cb4034
					
				
					 4 changed files with 34 additions and 16 deletions
				
			
		| 
						 | 
					@ -21,7 +21,9 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
 | 
				
			||||||
            throw "Invalid layer: geojsonSource expected"
 | 
					            throw "Invalid layer: geojsonSource expected"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        const whitelistUrl = source.geojsonSource.replace("{z}_{x}_{y}.geojson", "overview.json")
 | 
					        const whitelistUrl = source.geojsonSource
 | 
				
			||||||
 | 
					            .replace("{z}", ""+source.geojsonZoomLevel)
 | 
				
			||||||
 | 
					            .replace("{x}_{y}.geojson", "overview.json")
 | 
				
			||||||
            .replace("{layer}",layer.layerDef.id)
 | 
					            .replace("{layer}",layer.layerDef.id)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        let whitelist = undefined
 | 
					        let whitelist = undefined
 | 
				
			||||||
| 
						 | 
					@ -46,7 +48,8 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
 | 
				
			||||||
                if(whitelist !== undefined){
 | 
					                if(whitelist !== undefined){
 | 
				
			||||||
                    const isWhiteListed = whitelist.get(zxy[1])?.has(zxy[2])
 | 
					                    const isWhiteListed = whitelist.get(zxy[1])?.has(zxy[2])
 | 
				
			||||||
                    if(!isWhiteListed){
 | 
					                    if(!isWhiteListed){
 | 
				
			||||||
                        return undefined;
 | 
					                        console.log("Not whitelisted:",zxy, isWhiteListed, whitelist)
 | 
				
			||||||
 | 
					                    //    return undefined;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,7 +34,7 @@
 | 
				
			||||||
  "hideFromOverview": true,
 | 
					  "hideFromOverview": true,
 | 
				
			||||||
  "clustering": {
 | 
					  "clustering": {
 | 
				
			||||||
    "#": "Disable clustering for this theme",
 | 
					    "#": "Disable clustering for this theme",
 | 
				
			||||||
    "maxZoom": 0
 | 
					    "maxZoom": 1
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "layers": [
 | 
					  "layers": [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										1
									
								
								index.ts
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								index.ts
									
										
									
									
									
								
							| 
						 | 
					@ -63,7 +63,6 @@ if (path !== "index.html" && path !== "") {
 | 
				
			||||||
defaultLayout = QueryParameters.GetQueryParameter("layout", defaultLayout, "The layout to load into MapComplete").data;
 | 
					defaultLayout = QueryParameters.GetQueryParameter("layout", defaultLayout, "The layout to load into MapComplete").data;
 | 
				
			||||||
let layoutToUse: LayoutConfig = AllKnownLayouts.allKnownLayouts.get(defaultLayout.toLowerCase());
 | 
					let layoutToUse: LayoutConfig = AllKnownLayouts.allKnownLayouts.get(defaultLayout.toLowerCase());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
const userLayoutParam = QueryParameters.GetQueryParameter("userlayout", "false", "If not 'false', a custom (non-official) theme is loaded. This custom layout can be done in multiple ways: \n\n- The hash of the URL contains a base64-encoded .json-file containing the theme definition\n- The hash of the URL contains a lz-compressed .json-file, as generated by the custom theme generator\n- The parameter itself is an URL, in which case that URL will be downloaded. It should point to a .json of a theme");
 | 
					const userLayoutParam = QueryParameters.GetQueryParameter("userlayout", "false", "If not 'false', a custom (non-official) theme is loaded. This custom layout can be done in multiple ways: \n\n- The hash of the URL contains a base64-encoded .json-file containing the theme definition\n- The hash of the URL contains a lz-compressed .json-file, as generated by the custom theme generator\n- The parameter itself is an URL, in which case that URL will be downloaded. It should point to a .json of a theme");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Workaround/legacy to keep the old paramters working as I renamed some of them
 | 
					// Workaround/legacy to keep the old paramters working as I renamed some of them
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,7 @@ import FeatureSource, {FeatureSourceForLayer} from "../Logic/FeatureSource/Featu
 | 
				
			||||||
import StaticFeatureSource from "../Logic/FeatureSource/Sources/StaticFeatureSource";
 | 
					import StaticFeatureSource from "../Logic/FeatureSource/Sources/StaticFeatureSource";
 | 
				
			||||||
import TiledFeatureSource from "../Logic/FeatureSource/TiledFeatureSource/TiledFeatureSource";
 | 
					import TiledFeatureSource from "../Logic/FeatureSource/TiledFeatureSource/TiledFeatureSource";
 | 
				
			||||||
import Constants from "../Models/Constants";
 | 
					import Constants from "../Models/Constants";
 | 
				
			||||||
 | 
					import {GeoOperations} from "../Logic/GeoOperations";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ScriptUtils.fixUtils()
 | 
					ScriptUtils.fixUtils()
 | 
				
			||||||
| 
						 | 
					@ -170,11 +171,11 @@ function loadAllTiles(targetdir: string, r: TileRange, theme: LayoutConfig, extr
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Load all the tiles into memory from disk
 | 
					 * Load all the tiles into memory from disk
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsTracker: RelationsTracker, targetdir: string) {
 | 
					function sliceToTiles(allFeatures: FeatureSource, theme: LayoutConfig, relationsTracker: RelationsTracker, targetdir: string, pointsOnlyLayers: string[]) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    function handleLayer(source: FeatureSourceForLayer) {
 | 
					    function handleLayer(source: FeatureSourceForLayer) {
 | 
				
			||||||
        const layer = source.layer.layerDef;
 | 
					        const layer = source.layer.layerDef;
 | 
				
			||||||
 | 
					        const targetZoomLevel = layer.source.geojsonZoomLevel ?? 0
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        const layerId = layer.id
 | 
					        const layerId = layer.id
 | 
				
			||||||
        if (layer.source.isOsmCacheLayer !== true) {
 | 
					        if (layer.source.isOsmCacheLayer !== true) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
| 
						 | 
					@ -200,13 +201,10 @@ function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsT
 | 
				
			||||||
        // At this point, we have all the features of the entire area.
 | 
					        // At this point, we have all the features of the entire area.
 | 
				
			||||||
        // However, we want to export them per tile of a fixed size, so we use a dynamicTileSOurce to split it up
 | 
					        // However, we want to export them per tile of a fixed size, so we use a dynamicTileSOurce to split it up
 | 
				
			||||||
        TiledFeatureSource.createHierarchy(source, {
 | 
					        TiledFeatureSource.createHierarchy(source, {
 | 
				
			||||||
            minZoomLevel: 14,
 | 
					            minZoomLevel: targetZoomLevel,
 | 
				
			||||||
            maxZoomLevel: 14,
 | 
					            maxZoomLevel: targetZoomLevel,
 | 
				
			||||||
            maxFeatureCount: undefined,
 | 
					            maxFeatureCount: undefined,
 | 
				
			||||||
            registerTile: tile => {
 | 
					            registerTile: tile => {
 | 
				
			||||||
                if (tile.z < 12) {
 | 
					 | 
				
			||||||
                    return;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                if (tile.features.data.length === 0) {
 | 
					                if (tile.features.data.length === 0) {
 | 
				
			||||||
                    return
 | 
					                    return
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					@ -229,7 +227,7 @@ function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // All the tiles are written at this point
 | 
					        // All the tiles are written at this point
 | 
				
			||||||
        // Only thing left to do is to create the index
 | 
					        // Only thing left to do is to create the index
 | 
				
			||||||
        const path = targetdir + "_" + layerId + "_overview.json"
 | 
					        const path = targetdir + "_" + layerId + "_" + targetZoomLevel + "_overview.json"
 | 
				
			||||||
        const perX = {}
 | 
					        const perX = {}
 | 
				
			||||||
        createdTiles.map(i => Tiles.tile_from_index(i)).forEach(([z, x, y]) => {
 | 
					        createdTiles.map(i => Tiles.tile_from_index(i)).forEach(([z, x, y]) => {
 | 
				
			||||||
            const key = "" + x
 | 
					            const key = "" + x
 | 
				
			||||||
| 
						 | 
					@ -240,7 +238,18 @@ function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsT
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        writeFileSync(path, JSON.stringify(perX))
 | 
					        writeFileSync(path, JSON.stringify(perX))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // And, if needed, to create a points-only layer
 | 
				
			||||||
 | 
					        if(pointsOnlyLayers.indexOf(layer.id) >= 0){
 | 
				
			||||||
 | 
					            const features = source.features.data.map(f => f.feature)
 | 
				
			||||||
 | 
					            const points = features.map(feature => GeoOperations.centerpoint(feature))
 | 
				
			||||||
 | 
					            console.log("Writing points overview for ", layerId)
 | 
				
			||||||
 | 
					            const targetPath = targetdir+"_"+layerId+"_points.geojson"
 | 
				
			||||||
 | 
					            // This is the geojson file containing all features for this tile
 | 
				
			||||||
 | 
					            writeFileSync(targetPath, JSON.stringify({
 | 
				
			||||||
 | 
					                type: "FeatureCollection",
 | 
				
			||||||
 | 
					                features: points
 | 
				
			||||||
 | 
					            }, null, " "))
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    new PerLayerFeatureSourceSplitter(
 | 
					    new PerLayerFeatureSourceSplitter(
 | 
				
			||||||
| 
						 | 
					@ -255,10 +264,11 @@ function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsT
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function main(args: string[]) {
 | 
					async function main(args: string[]) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (args.length == 0) {
 | 
					    if (args.length == 0) {
 | 
				
			||||||
        console.error("Expected arguments are: theme zoomlevel targetdirectory lat0 lon0 lat1 lon1 [--generate-point-overview layer-name]")
 | 
					        console.error("Expected arguments are: theme zoomlevel targetdirectory lat0 lon0 lat1 lon1 [--generate-point-overview layer-name,layer-name,...]")
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const themeName = args[0]
 | 
					    const themeName = args[0]
 | 
				
			||||||
| 
						 | 
					@ -269,6 +279,12 @@ async function main(args: string[]) {
 | 
				
			||||||
    const lat1 = Number(args[5])
 | 
					    const lat1 = Number(args[5])
 | 
				
			||||||
    const lon1 = Number(args[6])
 | 
					    const lon1 = Number(args[6])
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    let generatePointLayersFor = []
 | 
				
			||||||
 | 
					    if(args[7] == "--generate-point-overview"){
 | 
				
			||||||
 | 
					        generatePointLayersFor = args[8].split(",")
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const tileRange = Tiles.TileRangeBetween(zoomlevel, lat0, lon0, lat1, lon1)
 | 
					    const tileRange = Tiles.TileRangeBetween(zoomlevel, lat0, lon0, lat1, lon1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const theme = AllKnownLayouts.allKnownLayouts.get(themeName)
 | 
					    const theme = AllKnownLayouts.allKnownLayouts.get(themeName)
 | 
				
			||||||
| 
						 | 
					@ -293,7 +309,7 @@ async function main(args: string[]) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const extraFeatures = await downloadExtraData(theme);
 | 
					    const extraFeatures = await downloadExtraData(theme);
 | 
				
			||||||
    const allFeaturesSource = loadAllTiles(targetdir, tileRange, theme, extraFeatures)
 | 
					    const allFeaturesSource = loadAllTiles(targetdir, tileRange, theme, extraFeatures)
 | 
				
			||||||
    postProcess(allFeaturesSource, theme, relationTracker, targetdir)
 | 
					    sliceToTiles(allFeaturesSource, theme, relationTracker, targetdir, generatePointLayersFor)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue