# HG changeset patch # User Bernhard Reiter # Date 1548067044 -3600 # Node ID 76ca071cb0064cc3fd1546085d7314b074fc2134 # Parent 5a37ee3216512d68f250f531c9115ba856034a6c client: pdf-gen: add legend graphic * Add a plain legend graphic to the right upper corner. Take a detour via a HTMLImageElement to get the aspect ration of the legend graphic and calculate the necessary size accordingly. diff -r 5a37ee321651 -r 76ca071cb006 client/src/components/Pdftool.vue --- a/client/src/components/Pdftool.vue Mon Jan 21 10:56:14 2019 +0100 +++ b/client/src/components/Pdftool.vue Mon Jan 21 11:37:24 2019 +0100 @@ -107,7 +107,7 @@ computed: { ...mapState("application", ["showPdfTool", "secondaryLogo"]), ...mapState("bottlenecks", ["selectedSurvey"]), - ...mapState("map", ["openLayersMap"]), + ...mapState("map", ["openLayersMap", "isolinesLegendImgDataURL"]), ...mapState("user", ["user"]) }, methods: { @@ -216,6 +216,17 @@ 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); + pdf.save("map.pdf"); // reset to original size map.setSize(mapSize);