Mercurial > gemma
diff client/src/components/Pdftool.vue @ 1887:3ed036adc80f dev-pdf-generation
client: pdf-gen: fix scale calculation
* Change scale calculation to use ol.proj.getPointResolution() at
the center of the current view to make up for different point dimensions
if you are not on the equator for the web mercator projection. This is
also how the scaleline control of OpenLayers does it.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Thu, 17 Jan 2019 21:48:11 +0100 |
parents | 20fe31b4dd5d |
children | c78efb1ddb02 |
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue Thu Jan 17 16:42:47 2019 +0100 +++ b/client/src/components/Pdftool.vue Thu Jan 17 21:48:11 2019 +0100 @@ -81,6 +81,7 @@ */ import { mapState } from "vuex"; import jsPDF from "jspdf"; +import { getPointResolution } from "ol/proj.js"; var paperSizes = { // in millimeter, landscape [width, height] @@ -163,9 +164,15 @@ // set a callback for after the next complete rendering of the map map.once("rendercomplete", function(event) { let canvas = event.context.canvas; + + // because we are using Web Mercator, a pixel represents + // a differently sizes spot depending on the place of the map. + // So we use a value calculated from the center of the current view. let view = map.getView(); - let metersPerPixel = // meters (reality) per pixel (map) - view.getResolution() * view.getProjection().getMetersPerUnit(); + let proj = view.getProjection(); + let metersPerPixel = // average meters (reality) per pixel (map) + getPointResolution(proj, view.getResolution(), view.getCenter()) * + proj.getMetersPerUnit(); console.log("metersPerPixel = ", metersPerPixel); var data = canvas.toDataURL("image/jpeg");