Mercurial > gemma
changeset 4488:bff6c5c1db4f
client: pdf-gen: improve adding bottleneck info to pdf
* Check if the bottleneck is in the current view to add its info to the exported pdf and the pdf filename, this avoid wrong filename and wrong info in pdf in case view has been changed to another location.
* Set the bottleneck to print after moving to it in map.
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Fri, 27 Sep 2019 11:15:02 +0200 |
parents | 80697ecc04e7 |
children | 39b9a264b319 |
files | client/src/components/Bottlenecks.vue client/src/components/Pdftool.vue client/src/components/fairway/AvailableFairwayDepthDialogue.vue client/src/components/fairway/BottleneckDialogue.vue client/src/store/bottlenecks.js |
diffstat | 5 files changed, 52 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/Bottlenecks.vue Thu Sep 26 17:22:44 2019 +0200 +++ b/client/src/components/Bottlenecks.vue Fri Sep 27 11:15:02 2019 +0200 @@ -162,6 +162,10 @@ preventZoomOut: true }); }); + this.$store.commit( + "bottlenecks/setBottleneckForPrint", + bottleneck.properties.name + ); }, loadSurveys(bottleneck) { if (bottleneck === this.openBottleneck) {
--- a/client/src/components/Pdftool.vue Thu Sep 26 17:22:44 2019 +0200 +++ b/client/src/components/Pdftool.vue Fri Sep 27 11:15:02 2019 +0200 @@ -119,6 +119,7 @@ import { displayError } from "@/lib/errors"; import { pdfgen, templateLoader } from "@/lib/mixins"; import sanitize from "sanitize-filename"; +import { containsCoordinate } from "ol/extent"; const paperSizes = { // in millimeter, landscape [width, height] @@ -196,7 +197,11 @@ }, computed: { ...mapState("application", ["showPdfTool", "logoForPDF"]), - ...mapState("bottlenecks", ["selectedBottleneck", "selectedSurvey"]), + ...mapState("bottlenecks", [ + "selectedBottleneck", + "selectedSurvey", + "bottleneckForPrint" + ]), ...mapState("map", ["isolinesLegendImgDataURL"]), ...mapGetters("map", ["openLayersMap"]), generatePdfLable() { @@ -204,16 +209,37 @@ }, filename() { let filename = "map"; - if (this.selectedBottleneck) { - filename = `BN-${sanitize(this.selectedBottleneck)}`; - if (this.selectedSurvey) { - filename += "-sr" + this.selectedSurvey.date_info.replace(/-/g, ""); + if (this.bottleneckForPrint) { + if (this.isBottleneckInView()) { + filename = `BN-${sanitize(this.bottleneckForPrint)}`; + if (this.selectedSurvey) { + filename += "-sr" + this.selectedSurvey.date_info.replace(/-/g, ""); + } } } return `${filename}-${this.dateForPDF()}.pdf`; } }, methods: { + // Check if the view contains the selected bottleneck + // to avoid including bottleneck info in pdf in case view has changed to another location + isBottleneckInView() { + let map = this.openLayersMap(); + // Get extent of the viewport + let viewExtent = map.getView().calculateExtent(map.getSize()); + let btnExtent = map // Extent of the selected bottleneck + .getLayer("BOTTLENECKS") + .getSource() + .getFeatures() + .find(f => f.get("objnam") === this.bottleneckForPrint) + .getGeometry().extent_; + // Get center of bottleneck from extent + let centerCoordinat = [ + (btnExtent[0] + btnExtent[2]) / 2, + (btnExtent[1] + btnExtent[3]) / 2 + ]; + return containsCoordinate(viewExtent, centerCoordinat); + }, close() { this.$store.commit("application/showPdfTool", false); }, @@ -648,8 +674,9 @@ }, addLegend(position, offset, rounding, brcolor) { if ( - this.selectedBottleneck && + this.bottleneckForPrint && this.selectedSurvey && + this.isBottleneckInView() && this.openLayersMap() .getLayer("BOTTLENECKISOLINE") .getVisible() @@ -689,8 +716,9 @@ }, addBottleneckInfo(position, offset, rounding, color, brcolor) { if ( - this.selectedBottleneck && + this.bottleneckForPrint && this.selectedSurvey && + this.isBottleneckInView() && this.openLayersMap() .getLayer("BOTTLENECKISOLINE") .getVisible()
--- a/client/src/components/fairway/AvailableFairwayDepthDialogue.vue Thu Sep 26 17:22:44 2019 +0200 +++ b/client/src/components/fairway/AvailableFairwayDepthDialogue.vue Fri Sep 27 11:15:02 2019 +0200 @@ -661,6 +661,10 @@ "bottlenecks/setSelectedBottleneck", this.selectedFairwayAvailabilityFeature.properties.name ); + this.$store.commit( + "bottlenecks/setBottleneckForPrint", + this.selectedBottleneck + ); } if (this.type === this.$options.STRETCH) { this.openLayersMap()
--- a/client/src/components/fairway/BottleneckDialogue.vue Thu Sep 26 17:22:44 2019 +0200 +++ b/client/src/components/fairway/BottleneckDialogue.vue Fri Sep 27 11:15:02 2019 +0200 @@ -698,6 +698,10 @@ bn => bn.properties.name === this.selectedBottleneck ); if (!bottleneck) return; + this.$store.commit( + "bottlenecks/setBottleneckForPrint", + this.selectedBottleneck + ); this.$store.dispatch("map/moveToFeauture", { feature: bottleneck, zoom: 17,
--- a/client/src/store/bottlenecks.js Thu Sep 26 17:22:44 2019 +0200 +++ b/client/src/store/bottlenecks.js Fri Sep 27 11:15:02 2019 +0200 @@ -24,7 +24,8 @@ selectedBottleneck: null, surveys: [], selectedSurvey: null, - surveysLoading: false + surveysLoading: false, + bottleneckForPrint: null }; }; @@ -63,6 +64,9 @@ } }, mutations: { + setBottleneckForPrint: (state, bottleneck) => { + state.bottleneckForPrint = bottleneck; + }, setBottlenecks: (state, bottlenecks) => { state.bottlenecks = bottlenecks; },