Attempt to fix build

This commit is contained in:
Pieter Vander Vennet 2024-03-21 15:50:27 +01:00
parent d29df8ae51
commit 9ebf820c61
4 changed files with 40 additions and 13 deletions

View file

@ -277,8 +277,14 @@ class GenerateLayouts extends Script {
if (f.properties.type === "vector") { if (f.properties.type === "vector") {
// We also need to whitelist eventual sources // We also need to whitelist eventual sources
const styleSpec = await Utils.downloadJsonCached(f.properties.url, 1000 * 120) let url = f.properties.url
for (const key of Object.keys(styleSpec.sources)) { if(url.startsWith("pmtiles://")){
url = url.substring("pmtiles://".length)
}
const styleSpec = await Utils.downloadJsonCached(url, 1000 * 120, {
Origin: "https://mapcomplete.org"
})
for (const key of Object.keys(styleSpec?.sources ?? {})) {
const url = styleSpec.sources[key].url const url = styleSpec.sources[key].url
if (!url) { if (!url) {
continue continue
@ -290,7 +296,9 @@ class GenerateLayouts extends Script {
console.log("Source url ", key, url) console.log("Source url ", key, url)
urls.push(url) urls.push(url)
if (urlClipped.endsWith(".json")) { if (urlClipped.endsWith(".json")) {
const tileInfo = await Utils.downloadJsonCached(url, 1000 * 120) const tileInfo = await Utils.downloadJsonCached(url, 1000 * 120, {
Origin: "https://mapcomplete.org"
})
urls.push(tileInfo["tiles"] ?? []) urls.push(tileInfo["tiles"] ?? [])
} }
} }
@ -354,9 +362,17 @@ class GenerateLayouts extends Script {
const eliLayers: RasterLayerPolygon[] = AvailableRasterLayers.layersAvailableAt( const eliLayers: RasterLayerPolygon[] = AvailableRasterLayers.layersAvailableAt(
new ImmutableStore({ lon: 0, lat: 0 }) new ImmutableStore({ lon: 0, lat: 0 })
).data ).data
const vectorLayers = eliLayers.filter((l) => l.properties.type === "vector") {
const vectorSources = vectorLayers.map((l) => l.properties.url) const vectorLayers = eliLayers.filter((l) => l.properties.type === "vector")
apiUrls.push(...vectorSources) const vectorSources = vectorLayers.map((l) => l.properties.url)
vectorSources.push(...vectorLayers.map((l) => l.properties.style))
apiUrls.push(...vectorSources.map(url => {
if(url?.startsWith("pmtiles://")){
return url.substring("pmtiles://".length)
}
return url
}))
}
for (let connectSource of apiUrls.concat(geojsonSources)) { for (let connectSource of apiUrls.concat(geojsonSources)) {
if (!connectSource) { if (!connectSource) {
continue continue

View file

@ -55,6 +55,9 @@ export class AvailableRasterLayers {
url: url:
"https://api.maptiler.com/maps/15cc8f61-0353-4be6-b8da-13daea5f7432/style.json?key=" + "https://api.maptiler.com/maps/15cc8f61-0353-4be6-b8da-13daea5f7432/style.json?key=" +
Constants.maptilerApiKey, Constants.maptilerApiKey,
style:
"https://api.maptiler.com/maps/15cc8f61-0353-4be6-b8da-13daea5f7432/style.json?key=" +
Constants.maptilerApiKey,
category: "osmbasedmap", category: "osmbasedmap",
id: "maptiler", id: "maptiler",
type: "vector", type: "vector",

View file

@ -1,6 +1,6 @@
import { Map as MLMap, RasterSourceSpecification, VectorTileSource } from "maplibre-gl" import { Map as MLMap, RasterSourceSpecification, VectorTileSource } from "maplibre-gl"
import { Store, Stores, UIEventSource } from "../../Logic/UIEventSource" import { Store, Stores, UIEventSource } from "../../Logic/UIEventSource"
import { RasterLayerPolygon } from "../../Models/RasterLayers" import { AvailableRasterLayers, RasterLayerPolygon } from "../../Models/RasterLayers"
import { RasterLayerProperties } from "../../Models/RasterLayerProperties" import { RasterLayerProperties } from "../../Models/RasterLayerProperties"
import { Utils } from "../../Utils" import { Utils } from "../../Utils"
import { VectorSourceSpecification } from "@maplibre/maplibre-gl-style-spec" import { VectorSourceSpecification } from "@maplibre/maplibre-gl-style-spec"
@ -127,7 +127,11 @@ class SingleBackgroundHandler {
.layers.find((l) => l.id.startsWith("mapcomplete_"))?.id .layers.find((l) => l.id.startsWith("mapcomplete_"))?.id
if (background.type === "vector") { if (background.type === "vector") {
map.setStyle(background["style"]) if(background.style){
map.setStyle(background.style)
}else{
map.setStyle(AvailableRasterLayers.maptilerDefaultLayer.properties.style)
}
} else { } else {
map.addLayer( map.addLayer(
@ -142,7 +146,11 @@ class SingleBackgroundHandler {
addLayerBeforeId addLayerBeforeId
) )
this.opacity.addCallbackAndRun((o) => { this.opacity.addCallbackAndRun((o) => {
map.setPaintProperty(background.id, "raster-opacity", o) try{
map.setPaintProperty(background.id, "raster-opacity", o)
}catch (e) {
console.debug("Could not set raster-opacity of", background.id)
}
}) })
} }
} }

View file

@ -177,7 +177,7 @@
} }
}, },
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3/{z}/{x}/{y}.mvt?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"style": "https://api.protomaps.com/styles/v2/white.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/white.json?key=2af8b969a9e8b692",
"id": "protomaps.white", "id": "protomaps.white",
"name": "Protomaps White", "name": "Protomaps White",
@ -189,7 +189,7 @@
} }
}, },
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3/{z}/{x}/{y}.mvt?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"style": "https://api.protomaps.com/styles/v2/light.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/light.json?key=2af8b969a9e8b692",
"id": "protomaps.light", "id": "protomaps.light",
"name": "Protomaps Light", "name": "Protomaps Light",
@ -201,7 +201,7 @@
} }
}, },
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3/{z}/{x}/{y}.mvt?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"style": "https://api.protomaps.com/styles/v2/grayscale.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/grayscale.json?key=2af8b969a9e8b692",
"id": "protomaps.grayscale", "id": "protomaps.grayscale",
"name": "Protomaps Grayscale", "name": "Protomaps Grayscale",
@ -225,7 +225,7 @@
} }
}, },
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3/{z}/{x}/{y}.mvt?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"style": "https://api.protomaps.com/styles/v2/black.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/black.json?key=2af8b969a9e8b692",
"id": "protomaps.black", "id": "protomaps.black",
"name": "Protomaps Black", "name": "Protomaps Black",