More work on making flyers

This commit is contained in:
Pieter Vander Vennet 2022-09-12 20:14:03 +02:00
parent 9d753ec7c0
commit b9d5a1edff
8 changed files with 831 additions and 418 deletions

View file

@ -3,6 +3,7 @@ import Loc from "../../Models/Loc"
import BaseLayer from "../../Models/BaseLayer"
import { UIEventSource } from "../../Logic/UIEventSource"
import { BBox } from "../../Logic/BBox"
import {deprecate} from "util";
export interface MinimapOptions {
background?: UIEventSource<BaseLayer>
@ -24,7 +25,10 @@ export interface MinimapObj {
installBounds(factor: number | BBox, showRange?: boolean): void
TakeScreenshot(): Promise<any>
TakeScreenshot(format): Promise<string>
TakeScreenshot(format: "image"): Promise<string>
TakeScreenshot(format:"blob"): Promise<Blob>
TakeScreenshot(format?: "image" | "blob"): Promise<string | Blob>
}
export default class Minimap {

View file

@ -109,10 +109,26 @@ export default class MinimapImplementation extends BaseUIElement implements Mini
mp.remove()
}
public async TakeScreenshot() {
/**
* Takes a screenshot of the current map
* @param format: image: give a base64 encoded png image;
* @constructor
*/
public async TakeScreenshot(): Promise<string> ;
public async TakeScreenshot(format: "image"): Promise<string> ;
public async TakeScreenshot(format: "blob"): Promise<Blob> ;
public async TakeScreenshot(format: "image" | "blob"): Promise<string | Blob> ;
public async TakeScreenshot(format: "image" | "blob" = "image"): Promise<string | Blob> {
const screenshotter = new SimpleMapScreenshoter()
screenshotter.addTo(this.leafletMap.data)
return await screenshotter.takeScreen("image")
const result = <any> await screenshotter.takeScreen((<any> format) ?? "image")
if(format === "image" && typeof result === "string"){
return result
}
if(format === "blob" && result instanceof Blob){
return result
}
throw "Something went wrong while creating the screenshot: "+result
}
protected InnerConstructElement(): HTMLElement {

View file

@ -32,7 +32,7 @@ export default class LocationInput
public readonly leafletMap: UIEventSource<any>
public readonly bounds
public readonly location
private _centerLocation: UIEventSource<Loc>
private readonly _centerLocation: UIEventSource<Loc>
private readonly mapBackground: UIEventSource<BaseLayer>
/**
* The features to which the input should be snapped
@ -177,10 +177,6 @@ export default class LocationInput
this.map.installBounds(factor, showRange)
}
TakeScreenshot(): Promise<any> {
return this.map.TakeScreenshot()
}
protected InnerConstructElement(): HTMLElement {
try {
const self = this
@ -270,4 +266,8 @@ export default class LocationInput
.ConstructElement()
}
}
TakeScreenshot(): Promise<string> {
return this.map.TakeScreenshot()
}
}