More work on the flyer

This commit is contained in:
Pieter Vander Vennet 2022-09-13 00:42:29 +02:00
parent c4404d68f9
commit d186b207de
5 changed files with 412 additions and 14 deletions

View file

@ -5,6 +5,8 @@ import Loc from "../Models/Loc";
import ShowDataLayer from "../UI/ShowDataLayer/ShowDataLayer";
import {BBox} from "../Logic/BBox";
import Minimap from "../UI/Base/Minimap";
import AvailableBaseLayers from "../Logic/Actors/AvailableBaseLayers";
import AvailableBaseLayersImplementation from "../Logic/Actors/AvailableBaseLayersImplementation";
export class PngMapCreator {
private readonly _state: FeaturePipelineState;
@ -29,10 +31,11 @@ export class PngMapCreator {
private async createAndLoadMinimap(): Promise<MinimapImplementation> {
const state = this._state;
const options = this._options
const baselayer = AvailableBaseLayers.layerOverview.find(bl => bl.id === state.layoutToUse.defaultBackgroundId) ?? AvailableBaseLayers.osmCarto
return new Promise(resolve => {
const minimap = Minimap.createMiniMap({
location: new UIEventSource<Loc>(state.locationControl.data), // We remove the link between the old and the new UI-event source as moving the map while the export is running fucks up the screenshot
background: state.backgroundLayer,
background: new UIEventSource(baselayer),
allowMoving: false,
onFullyLoaded: (_) =>
window.setTimeout(() => {
@ -63,14 +66,15 @@ export class PngMapCreator {
return new Promise<string | Blob>(resolve => {
// Next: we prepare the features. Only fully contained features are shown
minimap.leafletMap.addCallbackAndRunD(async (leaflet) => {
const bounds = BBox.fromLeafletBounds(leaflet.getBounds().pad(0.2))
const bounds = BBox.fromLeafletBounds(leaflet.getBounds().pad(0.1).pad(-state.layoutToUse.widenFactor))
// Ping the featurepipeline to download what is needed
state.currentBounds.setData(bounds)
if(state.featurePipeline.runningQuery.data){
// A query is running!
// Let's wait for it to complete
console.log("Waiting for the query to complete")
await state.featurePipeline.runningQuery.AsPromise()
await state.featurePipeline.runningQuery.AsPromise(isRunning => !isRunning)
console.log("Query has completeted!")
}
window.setTimeout(() => {

View file

@ -528,26 +528,28 @@ export class SvgToPdf {
svgImage.setAttribute("height", "" + height)
let layout = AllKnownLayouts.allKnownLayouts.get(params["theme"])
if (layout === undefined) {
console.error("Could not show map with parameters", params)
throw "Theme not found:" + params["theme"] + ". Use theme: to define which theme to use. "
}
layout.widenFactor = 0
const zoom = Number(params["zoom"] ?? params["z"] ?? 14);
for (const l of layout.layers) {
l.minzoom = zoom
}
const state = new FeaturePipelineState(layout)
state.backgroundLayer.addCallbackAndRunD(l => console.log("baselayer is",l.id))
state.backgroundLayer.addCallbackAndRunD(l => console.log("baselayer is", l.id))
state.locationControl.setData({
zoom,
lat: Number(params["lat"] ?? 51.05016),
lon: Number(params["lon"] ?? 3.717842)
})
if (params["layers"] === "none") {
const fl = state.filteredLayers.data
for (const filteredLayer of fl) {
const fl = state.filteredLayers.data
for (const filteredLayer of fl) {
if (params["layers"] === "none") {
filteredLayer.isDisplayed.setData(false)
}else if(filteredLayer.layerDef.id.startsWith("note_import")){
filteredLayer.isDisplayed.setData(false)
}
}
@ -555,10 +557,10 @@ export class SvgToPdf {
for (const paramsKey in params) {
if (paramsKey.startsWith("layer-")) {
const layerName = paramsKey.substring("layer-".length)
const isDisplayed = params[paramsKey].toLowerCase().trim() === "true";
const isDisplayed = params[paramsKey].toLowerCase().trim() === "true";
console.log("Setting display status of ", layerName, "to", isDisplayed)
state.filteredLayers.data.find(l => l.layerDef.id === layerName).isDisplayed.setData(
isDisplayed
isDisplayed
)
}
}