Mercurial > gemma
changeset 1931:8fb1b1a8ea85
client: pdf-gen: improve legend behaviour
* Change code to only show the legend if the bottleneck isolines
layers is visible. Move legend creation into a function of its own.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Mon, 21 Jan 2019 12:10:12 +0100 |
parents | 1aa864cccddc |
children | e734d48ef964 |
files | client/src/components/Pdftool.vue |
diffstat | 1 files changed, 16 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue Mon Jan 21 11:57:03 2019 +0100 +++ b/client/src/components/Pdftool.vue Mon Jan 21 12:10:12 2019 +0100 @@ -81,7 +81,7 @@ * * Bernhard E. Reiter <bernhard@intevation.de> * * Fadi Abbud <fadi.abbud@intevation.de> */ -import { mapState } from "vuex"; +import { mapGetters, mapState } from "vuex"; import jsPDF from "jspdf"; import { getPointResolution } from "ol/proj.js"; import locale2 from "locale2"; @@ -108,6 +108,7 @@ ...mapState("application", ["showPdfTool", "secondaryLogo"]), ...mapState("bottlenecks", ["selectedSurvey"]), ...mapState("map", ["openLayersMap", "isolinesLegendImgDataURL"]), + ...mapGetters("map", ["getLayerByName"]), ...mapState("user", ["user"]) }, methods: { @@ -216,16 +217,9 @@ self.addPageInfo(pdf); self.addAboutBox(pdf, width, height); - // addLegend - // transforming into an HTMLImageElement only to find out - // the width x height of the legend image - // FUTURE: find a better way to get the width and height - let legendImage = new Image(); - legendImage.src = self.isolinesLegendImgDataURL; - let aspectRatio = legendImage.width / legendImage.height; - - self.addRoundedBox(pdf, width - 54, 0, 54, 50 / aspectRatio + 4); - pdf.addImage(legendImage, width - 52, 2, 50, 50 / aspectRatio); + if (self.getLayerByName("Bottleneck isolines").isVisible) { + self.addLegend(pdf, width, height); + } pdf.save("map.pdf"); // reset to original size @@ -430,6 +424,17 @@ let str = "Dislaimer: Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua."; this.addText(doc, 5, docHeight - 6, 8, "black", 115, str); + }, + addLegend(doc, docWidth) { + // transforming into an HTMLImageElement only to find out + // the width x height of the legend image + // FUTURE: find a better way to get the width and height + let legendImage = new Image(); + legendImage.src = this.isolinesLegendImgDataURL; + let aspectRatio = legendImage.width / legendImage.height; + + this.addRoundedBox(doc, docWidth - 54, 0, 54, 50 / aspectRatio + 4); + doc.addImage(legendImage, docWidth - 52, 2, 50, 50 / aspectRatio); } } };