# HG changeset patch # User Fadi Abbud # Date 1569575702 -7200 # Node ID bff6c5c1db4f6c0b31de74d9289f770090c8e2e9 # Parent 80697ecc04e7d1f23ba8d0436c4f6229965154d3 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. diff -r 80697ecc04e7 -r bff6c5c1db4f client/src/components/Bottlenecks.vue --- 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) { diff -r 80697ecc04e7 -r bff6c5c1db4f client/src/components/Pdftool.vue --- 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() diff -r 80697ecc04e7 -r bff6c5c1db4f client/src/components/fairway/AvailableFairwayDepthDialogue.vue --- 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() diff -r 80697ecc04e7 -r bff6c5c1db4f client/src/components/fairway/BottleneckDialogue.vue --- 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, diff -r 80697ecc04e7 -r bff6c5c1db4f client/src/store/bottlenecks.js --- 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; },