Mercurial > gemma
comparison client/src/components/Pdftool.vue @ 5310:660147046ddd zpg-exception
Client: Implement handling zpg-exception info in pdf
* Extend processing the "text" element of the pdf-template to check for the string "{zpg-exception}", and print the text after it only if the attribute "zpg-exception" set to true.
* Refactor one WFS-request and fit the affected functions to get these attribute, which is used to determine the displaying of zpg-exception info in pdf.
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Tue, 01 Jun 2021 09:33:03 +0200 |
parents | 48bef30cdb72 |
children | 11e013b8b1a9 |
comparison
equal
deleted
inserted
replaced
5309:3c876c65cc43 | 5310:660147046ddd |
---|---|
268 this.templateData = template; | 268 this.templateData = template; |
269 this.form.format = this.templateData.properties.format; | 269 this.form.format = this.templateData.properties.format; |
270 this.form.paperSize = this.templateData.properties.paperSize; | 270 this.form.paperSize = this.templateData.properties.paperSize; |
271 this.form.resolution = this.templateData.properties.resolution; | 271 this.form.resolution = this.templateData.properties.resolution; |
272 }, | 272 }, |
273 numberSoundingsVisible() { | 273 getSoundingInfo() { |
274 return new Promise((resolve, reject) => { | 274 return new Promise((resolve, reject) => { |
275 const map = this.openLayersMap(); | 275 const map = this.openLayersMap(); |
276 const currentExtent = map.getView().calculateExtent(map.getSize()); | 276 const currentExtent = map.getView().calculateExtent(map.getSize()); |
277 const params = { | 277 const params = { |
278 srsName: "EPSG:3857", | 278 srsName: "EPSG:3857", |
279 featureNS: "gemma", | 279 featureNS: "gemma", |
280 featurePrefix: "gemma", | 280 featurePrefix: "gemma", |
281 featureTypes: ["sounding_results_areas_geoserver"], | 281 featureTypes: ["sounding_results_areas_geoserver"], |
282 outputFormat: "application/json", | 282 outputFormat: "application/json", |
283 resultType: "hits", | |
284 bbox: currentExtent, | 283 bbox: currentExtent, |
285 geometryName: "areas" | 284 geometryName: "areas" |
286 }; | 285 }; |
287 if (this.selectedSurvey) { | 286 if (this.selectedSurvey) { |
288 params["filter"] = equalToFilter( | 287 params["filter"] = equalToFilter( |
308 reject(error); | 307 reject(error); |
309 }); | 308 }); |
310 }); | 309 }); |
311 }, | 310 }, |
312 download() { | 311 download() { |
313 this.numberSoundingsVisible() | 312 this.getSoundingInfo() |
314 .then(response => { | 313 .then(response => { |
315 const parser = new DOMParser(); | 314 let soundingInfo = {}; |
316 const responseXML = parser.parseFromString(response.data, "text/xml"); | 315 if (this.selectedSurvey) { |
317 const totalNumber = responseXML | 316 soundingInfo = { |
318 .getElementsByTagName("wfs:FeatureCollection")[0] | 317 number: response.data.numberMatched || 0, |
319 .getAttribute("numberOfFeatures"); | 318 feature: |
320 this.generatePDF(totalNumber > 0); | 319 response.data.features.filter( |
320 f => f.properties.data_info === this.selectedSurvey.data_info | |
321 )[0] || {} | |
322 }; | |
323 } else { | |
324 soundingInfo = { number: 0, feature: {} }; | |
325 } | |
326 this.$store.commit("bottlenecks/setSoundingInfo", soundingInfo); | |
327 this.generatePDF(soundingInfo); | |
321 }) | 328 }) |
322 .catch(error => { | 329 .catch(error => { |
323 console.log(error); | 330 console.log(error); |
324 let message = "Backend not reachable"; | 331 let message = "Backend not reachable"; |
325 if (error.response) { | 332 if (error.response) { |
330 title: this.$gettext("Backend Error"), | 337 title: this.$gettext("Backend Error"), |
331 message: message | 338 message: message |
332 }); | 339 }); |
333 }); | 340 }); |
334 }, | 341 }, |
335 generatePDF(soundingsVisible) { | 342 generatePDF(soundingInfo) { |
336 /** | 343 /** |
337 * In order to generate the image with the appropriate resolution | 344 * In order to generate the image with the appropriate resolution |
338 * we have to temporaily scale the visible part of the map. | 345 * we have to temporaily scale the visible part of the map. |
339 * The newly rendered canvas is converted to Base64 DataURL. | 346 * The newly rendered canvas is converted to Base64 DataURL. |
340 * After that is done, the resolution is resetted to its previous state. | 347 * After that is done, the resolution is resetted to its previous state. |
365 0, | 372 0, |
366 0, | 373 0, |
367 this.pdf.width, | 374 this.pdf.width, |
368 this.pdf.height | 375 this.pdf.height |
369 ); | 376 ); |
370 | |
371 if (this.templateData) { | 377 if (this.templateData) { |
372 this.pdf.doc.setFont("linbiolinum", "normal"); | 378 this.pdf.doc.setFont("linbiolinum", "normal"); |
373 let defaultFontSize = 11, | 379 let defaultFontSize = 11, |
374 defaultRounding = 2, | 380 defaultRounding = 2, |
375 defaultTextColor = "black", | 381 defaultTextColor = "black", |
384 e.position, | 390 e.position, |
385 e.offset || defaultOffset, | 391 e.offset || defaultOffset, |
386 e.width, | 392 e.width, |
387 e.fontSize || defaultFontSize, | 393 e.fontSize || defaultFontSize, |
388 e.color || defaultTextColor, | 394 e.color || defaultTextColor, |
389 e.text | 395 e.text, |
396 soundingInfo | |
390 ); | 397 ); |
391 break; | 398 break; |
392 } | 399 } |
393 case "box": { | 400 case "box": { |
394 this.addBox( | 401 this.addBox( |
434 e.position, | 441 e.position, |
435 e.offset || defaultOffset, | 442 e.offset || defaultOffset, |
436 e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, | 443 e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, |
437 e.color || defaultTextColor, | 444 e.color || defaultTextColor, |
438 e.brcolor || defaultBorderColor, | 445 e.brcolor || defaultBorderColor, |
439 soundingsVisible | 446 soundingInfo.number > 0 |
440 ); | 447 ); |
441 break; | 448 break; |
442 } | 449 } |
443 case "legend": { | 450 case "legend": { |
444 this.addLegend( | 451 this.addLegend( |
445 e.position, | 452 e.position, |
446 e.offset || defaultOffset, | 453 e.offset || defaultOffset, |
447 e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, | 454 e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, |
448 e.brcolor || defaultBorderColor, | 455 e.brcolor || defaultBorderColor, |
449 soundingsVisible | 456 soundingInfo.number > 0 |
450 ); | 457 ); |
451 break; | 458 break; |
452 } | 459 } |
453 case "scalebar": { | 460 case "scalebar": { |
454 this.addScaleBar( | 461 this.addScaleBar( |
494 return intersects(currentExtent, btnExtent); | 501 return intersects(currentExtent, btnExtent); |
495 }; | 502 }; |
496 let filename = "map"; | 503 let filename = "map"; |
497 if ( | 504 if ( |
498 this.bottleneckForPrint && | 505 this.bottleneckForPrint && |
499 (soundingsVisible || isBottlenckVisible()) | 506 (soundingInfo.number > 0 || isBottlenckVisible()) |
500 ) { | 507 ) { |
501 filename = `BN-${sanitize(this.bottleneckForPrint).replace( | 508 filename = `BN-${sanitize(this.bottleneckForPrint).replace( |
502 / /g, | 509 / /g, |
503 "-" | 510 "-" |
504 )}`; | 511 )}`; |
736 this.pdf.doc.setFontSize(size * 3); | 743 this.pdf.doc.setFontSize(size * 3); |
737 this.pdf.doc.setTextColor(0, 0, 0); | 744 this.pdf.doc.setTextColor(0, 0, 0); |
738 this.pdf.doc.setFontStyle("normal"); | 745 this.pdf.doc.setFontStyle("normal"); |
739 this.pdf.doc.text(size < 3 ? x1 - 0.5 : x1 - 1.3, y3 + 1, "N"); | 746 this.pdf.doc.text(size < 3 ? x1 - 0.5 : x1 - 1.3, y3 + 1, "N"); |
740 }, | 747 }, |
741 addLegend(position, offset, rounding, brcolor, soundingsVisible) { | 748 addLegend(position, offset, rounding, brcolor, hasSounding) { |
742 if ( | 749 if ( |
743 soundingsVisible && | 750 hasSounding && |
744 this.bottleneckForPrint && | 751 this.bottleneckForPrint && |
745 this.selectedSurvey && | 752 this.selectedSurvey && |
746 this.openLayersMap() | 753 this.openLayersMap() |
747 .getLayer("BOTTLENECKISOLINE") | 754 .getLayer("BOTTLENECKISOLINE") |
748 .getVisible() | 755 .getVisible() |
778 width - 2 * padding, | 785 width - 2 * padding, |
779 height - 2 * padding | 786 height - 2 * padding |
780 ); | 787 ); |
781 } | 788 } |
782 }, | 789 }, |
783 addBottleneckInfo( | 790 addBottleneckInfo(position, offset, rounding, color, brcolor, hasSounding) { |
784 position, | |
785 offset, | |
786 rounding, | |
787 color, | |
788 brcolor, | |
789 soundingsVisible | |
790 ) { | |
791 if ( | 791 if ( |
792 soundingsVisible && | 792 hasSounding && |
793 this.bottleneckForPrint && | 793 this.bottleneckForPrint && |
794 this.selectedSurvey && | 794 this.selectedSurvey && |
795 this.openLayersMap() | 795 this.openLayersMap() |
796 .getLayer("BOTTLENECKISOLINE") | 796 .getLayer("BOTTLENECKISOLINE") |
797 .getVisible() | 797 .getVisible() |