forked from MapComplete/MapComplete
Remerge upstream
This commit is contained in:
commit
5ad3fa83be
13 changed files with 442 additions and 462 deletions
37
Logic/Actors/ExportPDF.ts
Normal file
37
Logic/Actors/ExportPDF.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Creates screenshoter to take png screenshot
|
||||
* Creates jspdf and downloads it
|
||||
* - landscape pdf
|
||||
*
|
||||
* To add new layout:
|
||||
* - add new possible layout name in constructor
|
||||
* - add new layout in "PDFLayout"
|
||||
* -> in there are more instructions
|
||||
*/
|
||||
|
||||
import jsPDF from "jspdf";
|
||||
import { SimpleMapScreenshoter } from "leaflet-simple-map-screenshoter";
|
||||
import State from "../../State";
|
||||
import Minimap from "../../UI/Base/Minimap";
|
||||
import { PDFLayout } from "./PDFLayout";
|
||||
|
||||
export default class ExportPDF {
|
||||
constructor(
|
||||
name: string,
|
||||
layout: "natuurpunt"
|
||||
){
|
||||
const screenshotter = new SimpleMapScreenshoter();
|
||||
//let temporaryMap = new Minimap();
|
||||
//temporaryMap.SetStyle('visibility: hidden');
|
||||
//temporaryMap.AttachTo("tempScreenshotDiv");
|
||||
//minimap op index.html -> hidden daar alles op doen en dan weg
|
||||
//minimap - leaflet map ophalen - boundaries ophalen - State.state.featurePipeline
|
||||
screenshotter.addTo(State.state.leafletMap.data);
|
||||
let doc = new jsPDF('l');
|
||||
screenshotter.takeScreen('image').then(image => {
|
||||
let file = new PDFLayout();
|
||||
file.AddLayout(layout, doc, image);
|
||||
doc.save(name);
|
||||
})
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ export default class GeoLocationHandler extends VariableUiElement {
|
|||
*/
|
||||
private readonly _isActive: UIEventSource<boolean>;
|
||||
|
||||
|
||||
/**
|
||||
* Wether or not the geolocation is locked, aka the user requested the current location and wants the crosshair to follow the user
|
||||
* @private
|
||||
|
@ -45,11 +44,13 @@ export default class GeoLocationHandler extends VariableUiElement {
|
|||
* @private
|
||||
*/
|
||||
private readonly _leafletMap: UIEventSource<L.Map>;
|
||||
|
||||
/**
|
||||
* The date when the user requested the geolocation. If we have a location, it'll autozoom to it the first 30 secs
|
||||
* @private
|
||||
*/
|
||||
private _lastUserRequest: Date;
|
||||
|
||||
/**
|
||||
* A small flag on localstorage. If the user previously granted the geolocation, it will be set.
|
||||
* On firefox, the permissions api is broken (probably fingerprint resistiance) and "granted + don't ask again" doesn't stick between sessions.
|
||||
|
@ -81,13 +82,13 @@ export default class GeoLocationHandler extends VariableUiElement {
|
|||
let icon: string;
|
||||
|
||||
if (isLocked.data) {
|
||||
icon = Svg.crosshair_locked;
|
||||
icon = Svg.location;
|
||||
} else if (hasLocationData) {
|
||||
icon = Svg.crosshair_blue;
|
||||
icon = Svg.location_empty;
|
||||
} else if (isActive.data) {
|
||||
icon = Svg.crosshair_blue_center;
|
||||
icon = Svg.location_empty;
|
||||
} else {
|
||||
icon = Svg.crosshair;
|
||||
icon = Svg.location_circle;
|
||||
}
|
||||
|
||||
return new CenterFlexedElement(
|
||||
|
|
20
Logic/Actors/PDFLayout.ts
Normal file
20
Logic/Actors/PDFLayout.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Adds a theme to the pdf
|
||||
*/
|
||||
|
||||
import jsPDF from "jspdf";
|
||||
|
||||
export class PDFLayout {
|
||||
public AddLayout(layout: string, doc: jsPDF, image: Blob){
|
||||
if(layout === "natuurpunt") this.AddNatuurpuntLayout(doc, image);
|
||||
}
|
||||
public AddNatuurpuntLayout(doc: jsPDF, image: Blob){
|
||||
// Add Natuurpunt layout
|
||||
const screenRatio = screen.width/screen.height;
|
||||
let img = document.createElement('img');
|
||||
img.src = './assets/themes/natuurpunt/natuurpunt.png';
|
||||
doc.addImage(img, 'PNG', 15, 5, 20, 20);
|
||||
doc.addImage(image, 'PNG', 15, 30, 150*screenRatio, 150);
|
||||
return doc;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue