Mercurial > gemma
annotate client/src/components/Pdftool.vue @ 2350:ed6b0a43d42f
staging: open detailsview for UBN too
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Wed, 20 Feb 2019 10:58:32 +0100 |
parents | 7bbf9ccda701 |
children | 6efd7ecd3a7d |
rev | line source |
---|---|
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1 <template> |
1480 | 2 <div |
3 :class="[ | |
4 'box ui-element rounded bg-white text-nowrap', | |
5 { expanded: showPdfTool } | |
6 ]" | |
7 > | |
2260
531e776cb81d
client: reduced width of pdf-, profile- and identify-box
Markus Kottlaender <markus@intevation.de>
parents:
2259
diff
changeset
|
8 <div style="width: 18rem"> |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
9 <h6 class="mb-0 py-2 px-3 border-bottom d-flex align-items-center"> |
1876
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
10 <font-awesome-icon icon="file-pdf" class="mr-2"></font-awesome-icon> |
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
11 <translate>Generate PDF</translate> |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
12 <font-awesome-icon |
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
13 icon="times" |
2154
a08e0f532304
staging: improve UI
Thomas Junk <thomas.junk@intevation.de>
parents:
2138
diff
changeset
|
14 class="ml-auto text-muted pointer" |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
15 @click="$store.commit('application/showPdfTool', false)" |
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
16 ></font-awesome-icon> |
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
17 </h6> |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
18 <div class="p-3 text-left"> |
2114 | 19 <select |
20 @change="applyTemplateToForm" | |
21 v-model="form.template" | |
22 class="form-control d-block mb-2 w-100 font-weight-bold" | |
23 > | |
2124 | 24 <option |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
25 v-for="template in templates" |
2214
5a4b0c85e7a8
values in template select are now the actual objects
Markus Kottlaender <markus@intevation.de>
parents:
2212
diff
changeset
|
26 :value="template" |
2124 | 27 :key="template.name" |
2114 | 28 > |
2124 | 29 <translate>{{ template.name }}</translate> |
30 </option> | |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
31 </select> |
2114 | 32 <select |
33 v-model="form.format" | |
34 class="form-control form-control-sm d-block mb-2 w-100" | |
35 > | |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
36 <option value="landscape"><translate>landscape</translate></option> |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
37 <option value="portrait"><translate>portrait</translate></option> |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
38 </select> |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
39 <div class="d-flex"> |
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
40 <div class="flex-fill mr-2"> |
2114 | 41 <select |
42 v-model="form.resolution" | |
43 class="form-control form-control-sm mb-2 d-block w-100" | |
44 > | |
2225
bc1780dd7cd1
PDF generation: changed option names in resolution select
Markus Kottlaender <markus@intevation.de>
parents:
2224
diff
changeset
|
45 <option value="80"><translate>80 dpi</translate></option> |
bc1780dd7cd1
PDF generation: changed option names in resolution select
Markus Kottlaender <markus@intevation.de>
parents:
2224
diff
changeset
|
46 <option value="120"><translate>120 dpi</translate></option> |
bc1780dd7cd1
PDF generation: changed option names in resolution select
Markus Kottlaender <markus@intevation.de>
parents:
2224
diff
changeset
|
47 <option value="200"><translate>200 dpi</translate></option> |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
48 </select> |
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
49 </div> |
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
50 <div class="flex-fill ml-2"> |
2114 | 51 <select |
52 v-model="form.paperSize" | |
53 class="form-control form-control-sm mb-2 d-block w-100" | |
54 > | |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
55 <option value="a4"><translate>A4</translate></option> |
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
56 <option value="a3"><translate>A3</translate></option> |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
57 </select> |
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
58 </div> |
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
59 </div> |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
60 <button |
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
61 @click="download" |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
62 :key="'downloadBtn'" |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
63 type="button" |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
64 v-if="readyToGenerate" |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
65 class="btn btn-sm btn-info d-block w-100 mt-2" |
1480 | 66 > |
67 <translate>Generate PDF</translate> | |
68 </button> | |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
69 <button |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
70 @click="cancel" |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
71 :key="'cancelBtn'" |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
72 type="button" |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
73 v-else |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
74 class="btn btn-sm btn-danger d-block w-100 mt-2" |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
75 > |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
76 <font-awesome-icon class="mr-1" icon="spinner" spin /> |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
77 <translate>Cancel</translate> |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
78 </button> |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
79 </div> |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
80 </div> |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
81 </div> |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
82 </template> |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
83 |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
84 <script> |
1362
ca33ad696594
remove the first empyty lines
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1361
diff
changeset
|
85 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
86 * without warranty, see README.md and license for details. |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
87 * |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
88 * SPDX-License-Identifier: AGPL-3.0-or-later |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
89 * License-Filename: LICENSES/AGPL-3.0.txt |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
90 * |
1878
f030182f82f1
client: fix style warning for pdfexport
Bernhard Reiter <bernhard@intevation.de>
parents:
1876
diff
changeset
|
91 * Copyright (C) 2018, 2019 by via donau |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
92 * – Österreichische Wasserstraßen-Gesellschaft mbH |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
93 * Software engineering by Intevation GmbH |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1299
diff
changeset
|
94 * |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
95 * Author(s): |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
96 * * Markus Kottländer <markus.kottlaender@intevation.de> |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
97 * * Bernhard E. Reiter <bernhard@intevation.de> |
1878
f030182f82f1
client: fix style warning for pdfexport
Bernhard Reiter <bernhard@intevation.de>
parents:
1876
diff
changeset
|
98 * * Fadi Abbud <fadi.abbud@intevation.de> |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
99 */ |
1931
8fb1b1a8ea85
client: pdf-gen: improve legend behaviour
Bernhard Reiter <bernhard@intevation.de>
parents:
1928
diff
changeset
|
100 import { mapGetters, mapState } from "vuex"; |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
101 import jsPDF from "jspdf"; |
2240
c3cc21dee75d
client: pdf-gen add multi-language font
Bernhard Reiter <bernhard@intevation.de>
parents:
2227
diff
changeset
|
102 import "@/lib/font-linbiolinum.js"; |
1887
3ed036adc80f
client: pdf-gen: fix scale calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1886
diff
changeset
|
103 import { getPointResolution } from "ol/proj.js"; |
1903
7247ac316cb7
client: pdf-gen: improve layout and ui
Bernhard Reiter <bernhard@intevation.de>
parents:
1897
diff
changeset
|
104 import locale2 from "locale2"; |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
105 import { HTTP } from "../lib/http"; |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
106 import { displayError } from "@/lib/errors.js"; |
2321
c00e3f7f5b17
client: use constant names instead of strings
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2296
diff
changeset
|
107 import { LAYERS } from "@/store/map.js"; |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
108 |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
109 var paperSizes = { |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
110 // in millimeter, landscape [width, height] |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
111 a3: [420, 297], |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
112 a4: [297, 210] |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
113 }; |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
114 |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
115 export default { |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
116 name: "pdftool", |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
117 data() { |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
118 return { |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
119 form: { |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
120 template: null, |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
121 format: "landscape", |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
122 paperSize: "a4", |
1881
f512cfb63e53
pdf-generation: add select box to pdf tool to choose the resolutions
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1879
diff
changeset
|
123 downloadType: "download", |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
124 resolution: "80" |
1947
4235fa8f59d7
clien: pdf-gen: load logo externally; add prepare step
Bernhard Reiter <bernhard@intevation.de>
parents:
1936
diff
changeset
|
125 }, |
2265
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
126 templates: [ |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
127 { |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
128 name: "Default", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
129 properties: { |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
130 format: "landscape", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
131 paperSize: "a4", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
132 resolution: "80" |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
133 }, |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
134 elements: [ |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
135 { |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
136 type: "scalebar", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
137 position: "bottomright", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
138 offset: { x: 2, y: 2 } |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
139 }, |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
140 { |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
141 type: "textbox", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
142 position: "bottomleft", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
143 offset: { x: 2, y: 2 }, |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
144 width: 60, |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
145 fontSize: 8, |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2275
diff
changeset
|
146 text: this.$gettext("Generated by") + " " + "{user}, {date}" |
2265
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
147 }, |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
148 { |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
149 type: "northarrow", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
150 position: "topright", |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
151 offset: { x: 6, y: 4 }, |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
152 size: 2 |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
153 } |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
154 ] |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
155 } |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
156 ], |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
157 templateData: null, |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
158 pdf: { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
159 doc: null, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
160 width: null, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
161 height: null |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
162 }, |
1947
4235fa8f59d7
clien: pdf-gen: load logo externally; add prepare step
Bernhard Reiter <bernhard@intevation.de>
parents:
1936
diff
changeset
|
163 logoImageForPDF: null, // a HTMLImageElement instance |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
164 readyToGenerate: true, // if the user is allowed to press the button |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
165 rendercompleteListener: null, |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
166 mapSize: null, |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
167 mapExtent: null |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
168 }; |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
169 }, |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
170 computed: { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
171 ...mapState("application", ["showPdfTool", "logoForPDF"]), |
2137
a31c9fa47ab8
client: pdf-gen: add bottleneck details
Bernhard Reiter <bernhard@intevation.de>
parents:
2124
diff
changeset
|
172 ...mapState("bottlenecks", ["selectedBottleneck", "selectedSurvey"]), |
1928
76ca071cb006
client: pdf-gen: add legend graphic
Bernhard Reiter <bernhard@intevation.de>
parents:
1914
diff
changeset
|
173 ...mapState("map", ["openLayersMap", "isolinesLegendImgDataURL"]), |
1931
8fb1b1a8ea85
client: pdf-gen: improve legend behaviour
Bernhard Reiter <bernhard@intevation.de>
parents:
1928
diff
changeset
|
174 ...mapGetters("map", ["getLayerByName"]), |
1903
7247ac316cb7
client: pdf-gen: improve layout and ui
Bernhard Reiter <bernhard@intevation.de>
parents:
1897
diff
changeset
|
175 ...mapState("user", ["user"]) |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
176 }, |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
177 methods: { |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
178 // When a template is chosen from the dropdown, its propoerties are |
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
179 // applied to the rest of the form. |
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
180 applyTemplateToForm() { |
2214
5a4b0c85e7a8
values in template select are now the actual objects
Markus Kottlaender <markus@intevation.de>
parents:
2212
diff
changeset
|
181 if (this.form.template) { |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
182 HTTP.get("/templates/print/" + this.form.template.name, { |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
183 headers: { |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
184 "X-Gemma-Auth": localStorage.getItem("token"), |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
185 "Content-type": "text/xml; charset=UTF-8" |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
186 } |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
187 }) |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
188 .then(response => { |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
189 this.templateData = response.data.template_data; |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
190 this.form.format = this.templateData.properties.format; |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
191 this.form.paperSize = this.templateData.properties.paperSize; |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
192 this.form.resolution = this.templateData.properties.resolution; |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
193 }) |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
194 .catch(e => { |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
195 const { status, data } = e.response; |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
196 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2275
diff
changeset
|
197 title: this.$gettext("Backend Error"), |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
198 message: `${status}: ${data.message || data}` |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
199 }); |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
200 }); |
2112
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
201 } |
8c0a0f237c2d
improved behavior of pdf generation form
Markus Kottlaender <markus@intevation.de>
parents:
2111
diff
changeset
|
202 }, |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
203 download() { |
1947
4235fa8f59d7
clien: pdf-gen: load logo externally; add prepare step
Bernhard Reiter <bernhard@intevation.de>
parents:
1936
diff
changeset
|
204 // disable button while working on it |
4235fa8f59d7
clien: pdf-gen: load logo externally; add prepare step
Bernhard Reiter <bernhard@intevation.de>
parents:
1936
diff
changeset
|
205 this.readyToGenerate = false; |
4235fa8f59d7
clien: pdf-gen: load logo externally; add prepare step
Bernhard Reiter <bernhard@intevation.de>
parents:
1936
diff
changeset
|
206 |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
207 console.log( |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
208 "will generate pdf with", |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
209 this.form.paperSize, |
1884
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
210 this.form.format, |
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
211 this.form.resolution |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
212 ); |
1883
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
213 |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
214 if (this.form.format !== "portrait") { |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
215 // landscape, default |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
216 this.pdf.width = paperSizes[this.form.paperSize][0]; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
217 this.pdf.height = paperSizes[this.form.paperSize][1]; |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
218 } else { |
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
219 // switch width and height |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
220 this.pdf.width = paperSizes[this.form.paperSize][1]; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
221 this.pdf.height = paperSizes[this.form.paperSize][0]; |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
222 } |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
223 |
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
224 // FUTURE: consider margins |
1635
ca48145dba9c
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
1613
diff
changeset
|
225 |
1884
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
226 // dots per mm = dots per inch / (25.4 mm/inch) |
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
227 var pixelsPerMapMillimeter = this.form.resolution / 25.4; |
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
228 var mapSizeForPrint = [ |
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
229 // in pixel |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
230 Math.round(this.pdf.width * pixelsPerMapMillimeter), |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
231 Math.round(this.pdf.height * pixelsPerMapMillimeter) |
1884
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
232 ]; |
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
233 |
1883
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
234 // generate PDF and open it |
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
235 // our units are milimeters; width 0 x height 0 is left upper corner |
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
236 |
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
237 // Step 1 prepare and save current map extend |
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
238 // Then add callback "rendercomplete" for Step 3 |
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
239 // which will generate the pdf and resets the map view |
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
240 // Step 2 which starts rendering a map with the necessary image size |
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
241 |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
242 var map = this.openLayersMap; |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
243 this.mapSize = map.getSize(); // size in pixels of the map in the DOM |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
244 // Calculate the extent for the current view state and the passed size. |
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
245 // The size is the pixel dimensions of the box into which the calculated |
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
246 // extent should fit. |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
247 this.mapExtent = map.getView().calculateExtent(this.mapSize); |
1883
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
248 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
249 this.pdf.doc = new jsPDF(this.form.format, "mm", this.form.paperSize); |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
250 // set a callback for after the next complete rendering of the map |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
251 this.rendercompleteListener = map.once("rendercomplete", event => { |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
252 let canvas = event.context.canvas; |
1887
3ed036adc80f
client: pdf-gen: fix scale calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1886
diff
changeset
|
253 |
3ed036adc80f
client: pdf-gen: fix scale calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1886
diff
changeset
|
254 // because we are using Web Mercator, a pixel represents |
2240
c3cc21dee75d
client: pdf-gen add multi-language font
Bernhard Reiter <bernhard@intevation.de>
parents:
2227
diff
changeset
|
255 // a differently sized spot depending on the place of the map. |
1887
3ed036adc80f
client: pdf-gen: fix scale calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1886
diff
changeset
|
256 // So we use a value calculated from the center of the current view. |
1884
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
257 let view = map.getView(); |
1887
3ed036adc80f
client: pdf-gen: fix scale calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1886
diff
changeset
|
258 let proj = view.getProjection(); |
3ed036adc80f
client: pdf-gen: fix scale calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1886
diff
changeset
|
259 let metersPerPixel = // average meters (reality) per pixel (map) |
3ed036adc80f
client: pdf-gen: fix scale calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1886
diff
changeset
|
260 getPointResolution(proj, view.getResolution(), view.getCenter()) * |
3ed036adc80f
client: pdf-gen: fix scale calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1886
diff
changeset
|
261 proj.getMetersPerUnit(); |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
262 // DEBUG console.log("metersPerPixel = ", metersPerPixel); |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
263 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
264 let scaleNominator = Math.round( |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
265 // the x in 1:x map scale |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
266 1000 * pixelsPerMapMillimeter * metersPerPixel |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
267 ); |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
268 console.log("scaleNominator = ", scaleNominator); |
1884
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
269 |
1886
20fe31b4dd5d
client: pdf-gen: use jpeg, add scale number.
Bernhard Reiter <bernhard@intevation.de>
parents:
1884
diff
changeset
|
270 var data = canvas.toDataURL("image/jpeg"); |
2227
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
271 this.pdf.doc.addImage( |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
272 data, |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
273 "JPEG", |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
274 0, |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
275 0, |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
276 this.pdf.width, |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
277 this.pdf.height |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
278 ); |
1903
7247ac316cb7
client: pdf-gen: improve layout and ui
Bernhard Reiter <bernhard@intevation.de>
parents:
1897
diff
changeset
|
279 |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
280 if (this.templateData) { |
2240
c3cc21dee75d
client: pdf-gen add multi-language font
Bernhard Reiter <bernhard@intevation.de>
parents:
2227
diff
changeset
|
281 this.pdf.doc.setFont("linbiolinum", "normal"); |
c3cc21dee75d
client: pdf-gen add multi-language font
Bernhard Reiter <bernhard@intevation.de>
parents:
2227
diff
changeset
|
282 let defaultFontSize = 11, |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
283 defaultRounding = 2, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
284 defaultTextColor = "black", |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
285 defaultBgColor = "white", |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
286 defaultPadding = 3, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
287 defaultOffset = { x: 0, y: 0 }; |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
288 this.templateData.elements.forEach(e => { |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
289 switch (e.type) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
290 case "text": { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
291 this.addText( |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
292 e.position, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
293 e.offset || defaultOffset, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
294 e.width, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
295 e.fontSize || defaultFontSize, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
296 e.color || defaultTextColor, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
297 e.text |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
298 ); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
299 break; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
300 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
301 case "box": { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
302 this.addBox( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
303 e.position, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
304 e.offset || defaultOffset, |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
305 e.width, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
306 e.height, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
307 e.rounding || defaultRounding, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
308 e.color || defaultBgColor |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
309 ); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
310 break; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
311 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
312 case "textbox": { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
313 this.addTextBox( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
314 e.position, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
315 e.offset || defaultOffset, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
316 e.width, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
317 e.height, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
318 e.rounding || defaultRounding, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
319 e.padding || defaultPadding, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
320 e.fontSize || defaultFontSize, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
321 e.color || defaultTextColor, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
322 e.background || defaultBgColor, |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
323 e.text |
2205
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
324 ); |
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
325 break; |
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
326 } |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
327 case "image": { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
328 this.addImage( |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
329 e.url, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
330 e.format, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
331 e.position, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
332 e.offset || defaultOffset, |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
333 e.width, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
334 e.height |
2207
da902f0dac88
pdf-gen: add fixed coordinates and values
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2205
diff
changeset
|
335 ); |
2205
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
336 break; |
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
337 } |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
338 case "bottleneck": { |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
339 this.addBottleneckInfo( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
340 e.position, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
341 e.offset || defaultOffset, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
342 e.rounding || defaultRounding, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
343 e.color || defaultTextColor |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
344 ); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
345 break; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
346 } |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
347 case "legend": { |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
348 this.addLegend( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
349 e.position, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
350 e.offset || defaultOffset, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
351 e.rounding || defaultRounding |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
352 ); |
2205
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
353 break; |
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
354 } |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
355 case "scalebar": { |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
356 this.addScaleBar( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
357 scaleNominator, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
358 e.position, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
359 e.offset || defaultOffset, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
360 e.rounding || defaultRounding |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
361 ); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
362 break; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
363 } |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
364 case "northarrow": { |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
365 this.addNorthArrow( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
366 e.position, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
367 e.offset || defaultOffset, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
368 e.size |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
369 ); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
370 break; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
371 } |
2205
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
372 } |
59c21dee6315
pdf-gen: improve pdftool to use value from template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2124
diff
changeset
|
373 }); |
1928
76ca071cb006
client: pdf-gen: add legend graphic
Bernhard Reiter <bernhard@intevation.de>
parents:
1914
diff
changeset
|
374 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
375 this.pdf.doc.save("map.pdf"); |
1931
8fb1b1a8ea85
client: pdf-gen: improve legend behaviour
Bernhard Reiter <bernhard@intevation.de>
parents:
1928
diff
changeset
|
376 } |
2265
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
377 |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
378 // reset to original size |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
379 map.setSize(this.mapSize); |
2325
7bbf9ccda701
client: fix resetting of zoom level after pdf-gen
Bernhard Reiter <bernhard@intevation.de>
parents:
2321
diff
changeset
|
380 map.getView().fit(this.mapExtent, { |
7bbf9ccda701
client: fix resetting of zoom level after pdf-gen
Bernhard Reiter <bernhard@intevation.de>
parents:
2321
diff
changeset
|
381 size: this.mapSize, |
7bbf9ccda701
client: fix resetting of zoom level after pdf-gen
Bernhard Reiter <bernhard@intevation.de>
parents:
2321
diff
changeset
|
382 // necessary to get to the previous zoom level in all cases |
7bbf9ccda701
client: fix resetting of zoom level after pdf-gen
Bernhard Reiter <bernhard@intevation.de>
parents:
2321
diff
changeset
|
383 // details see https://github.com/openlayers/openlayers/issues/9235 |
7bbf9ccda701
client: fix resetting of zoom level after pdf-gen
Bernhard Reiter <bernhard@intevation.de>
parents:
2321
diff
changeset
|
384 constrainResolution: false |
7bbf9ccda701
client: fix resetting of zoom level after pdf-gen
Bernhard Reiter <bernhard@intevation.de>
parents:
2321
diff
changeset
|
385 }); |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
386 |
1947
4235fa8f59d7
clien: pdf-gen: load logo externally; add prepare step
Bernhard Reiter <bernhard@intevation.de>
parents:
1936
diff
changeset
|
387 // as we are done: re-enable button |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
388 this.readyToGenerate = true; |
1874
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
389 }); |
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
390 |
bad32adafef2
client: add real pdf generation with jspdf
Bernhard Reiter <bernhard@intevation.de>
parents:
1635
diff
changeset
|
391 // trigger rendering |
2227
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
392 map.setSize(mapSizeForPrint); |
2275
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
393 map.getView().fit(this.mapExtent, { size: mapSizeForPrint }); |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
394 }, |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
395 cancel() { |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
396 this.openLayersMap.un( |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
397 this.rendercompleteListener.type, |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
398 this.rendercompleteListener.listener |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
399 ); |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
400 this.openLayersMap.setSize(this.mapSize); |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
401 this.openLayersMap.getView().fit(this.mapExtent, { size: this.mapSize }); |
a6cfa06c5983
client: pdf-gen: added cancel button
Markus Kottlaender <markus@intevation.de>
parents:
2265
diff
changeset
|
402 this.readyToGenerate = true; |
1876
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
403 }, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
404 addRoundedBox(x, y, w, h, color, rounding) { |
1883
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
405 // draws a rounded background box at (x,y) width x height |
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
406 // using jsPDF units |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
407 this.pdf.doc.setDrawColor(color); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
408 this.pdf.doc.setFillColor(color); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
409 this.pdf.doc.roundedRect(x, y, w, h, rounding, rounding, "FD"); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
410 }, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
411 // add some text at specific coordinates and determine how many wrolds in single line |
2288
3f9847c89491
client: pdf-gen: removed unused parameter
Markus Kottlaender <markus@intevation.de>
parents:
2284
diff
changeset
|
412 addText(position, offset, width, fontSize, color, text) { |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
413 text = this.replacePlaceholders(text); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
414 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
415 // split the incoming string to an array, each element is a string of |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
416 // words in a single line |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
417 this.pdf.doc.setTextColor(color); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
418 this.pdf.doc.setFontSize(fontSize); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
419 var textLines = this.pdf.doc.splitTextToSize(text, width); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
420 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
421 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
422 let x = offset.x; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
423 let y = offset.y; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
424 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
425 // if position is on the right, x needs to be calculate with pdf width and |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
426 // the size of the element |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
427 if (["topright", "bottomright"].indexOf(position) !== -1) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
428 x = this.pdf.width - offset.x - width; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
429 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
430 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
431 y = this.pdf.height - offset.y - this.getTextHeight(textLines.length); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
432 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
433 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
434 this.pdf.doc.text(textLines, x, y, { baseline: "hanging" }); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
435 }, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
436 addBox(position, offset, width, height, rounding, color) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
437 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
438 let x = offset.x; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
439 let y = offset.y; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
440 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
441 // if position is on the right, x needs to be calculate with pdf width and |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
442 // the size of the element |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
443 if (["topright", "bottomright"].indexOf(position) !== -1) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
444 x = this.pdf.width - offset.x - width; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
445 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
446 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
447 y = this.pdf.height - offset.y - height; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
448 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
449 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
450 this.addRoundedBox(x, y, width, height, color, rounding); |
1883
76a6d334e681
Client: pdf-gen: refactor addScaleBar
Bernhard Reiter <bernhard@intevation.de>
parents:
1882
diff
changeset
|
451 }, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
452 // add some text at specific coordinates with a background box |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
453 addTextBox( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
454 position, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
455 offset, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
456 width, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
457 height, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
458 rounding, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
459 padding, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
460 fontSize, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
461 color, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
462 background, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
463 text |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
464 ) { |
2296
da6611071a58
client: pdf-gen: fixed width calculation of textbox
Markus Kottlaender <markus@intevation.de>
parents:
2292
diff
changeset
|
465 this.pdf.doc.setFontSize(fontSize); |
da6611071a58
client: pdf-gen: fixed width calculation of textbox
Markus Kottlaender <markus@intevation.de>
parents:
2292
diff
changeset
|
466 text = this.replacePlaceholders(text); |
da6611071a58
client: pdf-gen: fixed width calculation of textbox
Markus Kottlaender <markus@intevation.de>
parents:
2292
diff
changeset
|
467 |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
468 if (!width) { |
2296
da6611071a58
client: pdf-gen: fixed width calculation of textbox
Markus Kottlaender <markus@intevation.de>
parents:
2292
diff
changeset
|
469 width = this.pdf.doc.getTextWidth(text) + 2 * padding; |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
470 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
471 let textWidth = width - 2 * padding; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
472 if (!height) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
473 let textLines = this.pdf.doc.splitTextToSize(text, textWidth); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
474 height = this.getTextHeight(textLines.length) + 2 * padding; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
475 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
476 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
477 this.addBox(position, offset, width, height, rounding, background); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
478 this.addText( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
479 position, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
480 { x: offset.x + padding, y: offset.y + padding }, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
481 textWidth, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
482 fontSize, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
483 color, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
484 text |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
485 ); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
486 }, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
487 addImage(url, format, position, offset, width, height) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
488 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
489 let x = offset.x; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
490 let y = offset.y; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
491 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
492 // if position is on the right, x needs to be calculate with pdf width and |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
493 // the size of the element |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
494 if (["topright", "bottomright"].indexOf(position) !== -1) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
495 x = this.pdf.width - offset.x - width; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
496 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
497 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
498 y = this.pdf.height - offset.y - height; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
499 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
500 |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
501 let image = new Image(); |
2227
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
502 if (url) { |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
503 image.src = url; |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
504 } else { |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
505 if (this.logoForPDF) { |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
506 image.src = this.logoForPDF; |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
507 } else { |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
508 image.src = "/img/gemma-logo-for-pdf.png"; |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
509 } |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
510 } |
9b545e470b94
PDF generation: logo image, adjusted templates
Markus Kottlaender <markus@intevation.de>
parents:
2226
diff
changeset
|
511 |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
512 this.pdf.doc.addImage(image, x, y, width, height); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
513 }, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
514 addScaleBar(scaleNominator, position, offset, rounding) { |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
515 // scaleNominator is the x in 1:x of the map scale |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
516 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
517 // hardcode maximal width for now |
1933
1aa2921d8832
client: pdf-gen: make scalebar box size dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1931
diff
changeset
|
518 let maxWidth = 80; // in mm |
1aa2921d8832
client: pdf-gen: make scalebar box size dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1931
diff
changeset
|
519 |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
520 // reduce width until we'll find a nice number for printing |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
521 // strategy: |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
522 // 1. check which unit prefix we shall use to get [10:10000[ |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
523 // 2. using a mapping for the leading digit to get [1:10[ |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
524 // 3. select a smaller number which is nicely dividable |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
525 // 4. scale up again to get length in paper mm and to be shown |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
526 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
527 // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10#Polyfill |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
528 let log10 = |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
529 Math.log10 || // more precise, but unsupported by IE |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
530 function(x) { |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
531 return Math.log(x) * Math.LOG10E; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
532 }; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
533 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
534 let maxLength = maxWidth * scaleNominator; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
535 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
536 let unit = "mm"; |
1914
3d2b55d2d8a6
client: pdf-gen: fix scale bar calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1903
diff
changeset
|
537 let unitConversionFactor = 1; |
3d2b55d2d8a6
client: pdf-gen: fix scale bar calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1903
diff
changeset
|
538 if (maxLength >= 1e7) { |
3d2b55d2d8a6
client: pdf-gen: fix scale bar calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1903
diff
changeset
|
539 // >= 10 km |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
540 unit = "km"; |
1914
3d2b55d2d8a6
client: pdf-gen: fix scale bar calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1903
diff
changeset
|
541 unitConversionFactor = 1e6; |
3d2b55d2d8a6
client: pdf-gen: fix scale bar calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1903
diff
changeset
|
542 } else if (maxLength >= 1e4) { |
3d2b55d2d8a6
client: pdf-gen: fix scale bar calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1903
diff
changeset
|
543 // >= 10 m |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
544 unit = "m"; |
1914
3d2b55d2d8a6
client: pdf-gen: fix scale bar calculation
Bernhard Reiter <bernhard@intevation.de>
parents:
1903
diff
changeset
|
545 unitConversionFactor = 1e3; |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
546 } |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
547 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
548 maxLength /= unitConversionFactor; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
549 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
550 // DEBUG console.log(maxLength, unit); |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
551 let unroundedLength = maxLength; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
552 let numberOfDigits = Math.floor(log10(unroundedLength)); |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
553 let factor = Math.pow(10, numberOfDigits); |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
554 let mapped = unroundedLength / factor; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
555 // DEBUG console.log(mapped); |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
556 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
557 var length = Math.floor(maxLength); // just to have an upper limit |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
558 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
559 // manually only use numbers that are very nice to devide by 4 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
560 // note that this is taken into account for rounding later |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
561 if (mapped > 8) { |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
562 length = 8 * factor; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
563 } else if (mapped > 4) { |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
564 length = 4 * factor; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
565 } else if (mapped > 2) { |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
566 length = 2 * factor; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
567 } else { |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
568 length = factor; |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
569 } |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
570 |
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
571 let size = (length * unitConversionFactor) / scaleNominator / 4; |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
572 let fullSize = size * 4; |
1933
1aa2921d8832
client: pdf-gen: make scalebar box size dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1931
diff
changeset
|
573 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
574 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
575 let x = offset.x; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
576 let y = offset.y; |
1933
1aa2921d8832
client: pdf-gen: make scalebar box size dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1931
diff
changeset
|
577 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
578 // if position is on the right, x needs to be calculate with pdf width and |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
579 // the size of the element |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
580 if (["topright", "bottomright"].indexOf(position) !== -1) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
581 x = this.pdf.width - offset.x - fullSize - 8; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
582 } |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
583 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
584 y = this.pdf.height - offset.y - 10; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
585 } |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
586 |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
587 // to give the outer white box 4mm padding |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
588 let scaleBarX = x + 4; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
589 let scaleBarY = y + 5; // 5 because above the scalebar will be the numbers |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
590 |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
591 // draw outer white box |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
592 this.addRoundedBox(x, y, fullSize + 8, 10, "white", rounding); |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
593 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
594 // draw first part of scalebar |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
595 this.pdf.doc.setDrawColor(0, 0, 0); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
596 this.pdf.doc.setFillColor(0, 0, 0); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
597 this.pdf.doc.rect(scaleBarX, scaleBarY, size, 1, "FD"); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
598 |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
599 // draw second part of scalebar |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
600 this.pdf.doc.setDrawColor(0, 0, 0); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
601 this.pdf.doc.setFillColor(255, 255, 255); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
602 this.pdf.doc.rect(scaleBarX + size, scaleBarY, size, 1, "FD"); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
603 |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
604 // draw third part of scalebar |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
605 this.pdf.doc.setDrawColor(0, 0, 0); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
606 this.pdf.doc.setFillColor(0, 0, 0); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
607 this.pdf.doc.rect(scaleBarX + size * 2, scaleBarY, size * 2, 1, "FD"); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
608 |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
609 // draw numeric labels above scalebar |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
610 this.pdf.doc.setTextColor("black"); |
2240
c3cc21dee75d
client: pdf-gen add multi-language font
Bernhard Reiter <bernhard@intevation.de>
parents:
2227
diff
changeset
|
611 this.pdf.doc.setFontSize(6); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
612 this.pdf.doc.text(scaleBarX, scaleBarY - 1, "0"); |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
613 // /4 and could give 2.5. We still round, because of floating point arith |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
614 this.pdf.doc.text( |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
615 scaleBarX + size - 1, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
616 scaleBarY - 1, |
1897
c78efb1ddb02
client: pdf-gen: improve scalebar to show nice values
Bernhard Reiter <bernhard@intevation.de>
parents:
1887
diff
changeset
|
617 (Math.round((length * 10) / 4) / 10).toString() |
1884
59ef76d83de7
client: pdf-gen: make scalebar dynamic
Bernhard Reiter <bernhard@intevation.de>
parents:
1883
diff
changeset
|
618 ); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
619 this.pdf.doc.text( |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
620 scaleBarX + size * 2 - 2, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
621 scaleBarY - 1, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
622 Math.round(length / 2).toString() |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
623 ); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
624 this.pdf.doc.text( |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
625 scaleBarX + size * 4 - 4, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
626 scaleBarY - 1, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
627 Math.round(length).toString() + " " + unit |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
628 ); |
1876
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
629 }, |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
630 addNorthArrow(position, offset, size) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
631 // TODO: fix positioning |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
632 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
633 let x1 = offset.x; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
634 let y1 = offset.y; |
1876
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
635 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
636 // if position is on the right, x needs to be calculate with pdf width and |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
637 // the size of the element |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
638 if (["topright", "bottomright"].indexOf(position) !== -1) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
639 x1 = this.pdf.width - offset.x - size; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
640 } |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
641 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
642 y1 = this.pdf.height - offset.y - size; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
643 } |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
644 |
1876
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
645 var y2 = y1 + size * 3; |
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
646 var x3 = x1 - size * 2; |
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
647 var y3 = y1 + size * 5; |
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
648 var x4 = x1 + size * 2; |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
649 // white triangle |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
650 this.pdf.doc.setFillColor(255, 255, 255); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
651 this.pdf.doc.setDrawColor(255, 255, 255); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
652 this.pdf.doc.triangle( |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
653 x3 - 0.8, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
654 y3 + 1.2, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
655 x1, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
656 y1 - 1.2, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
657 x1, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
658 y2 + 0.6, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
659 "F" |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
660 ); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
661 this.pdf.doc.triangle( |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
662 x1, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
663 y1 - 1.2, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
664 x1, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
665 y2 + 0.6, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
666 x4 + 0.8, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
667 y3 + 1.2, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
668 "F" |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
669 ); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
670 |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
671 // north arrow |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
672 this.pdf.doc.setDrawColor(0, 0, 0); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
673 this.pdf.doc.setFillColor(255, 255, 255); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
674 this.pdf.doc.triangle(x3, y3, x1, y1, x1, y2, "FD"); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
675 this.pdf.doc.setFillColor(0, 0, 0); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
676 this.pdf.doc.triangle(x1, y1, x1, y2, x4, y3, "FD"); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
677 this.pdf.doc.setFontSize(size * 3.1); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
678 this.pdf.doc.setTextColor(255, 255, 255); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
679 this.pdf.doc.setFontStyle("bold"); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
680 this.pdf.doc.text(size < 3 ? x1 - 0.5 : x1 - 1.3, y3 + 1, "N"); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
681 this.pdf.doc.setFontSize(size * 3); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
682 this.pdf.doc.setTextColor(0, 0, 0); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
683 this.pdf.doc.setFontStyle("normal"); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
684 this.pdf.doc.text(size < 3 ? x1 - 0.5 : x1 - 1.3, y3 + 1, "N"); |
1876
e53924abb4a2
client: export some elements to pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1874
diff
changeset
|
685 }, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
686 addLegend(position, offset, rounding) { |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
687 if ( |
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
688 this.selectedBottleneck && |
2259
7e378b38d302
client: pdf-gen: made selectedSurvey mandatory for displaying the bottleneck info box and iso line legend.
Markus Kottlaender <markus@intevation.de>
parents:
2258
diff
changeset
|
689 this.selectedSurvey && |
2321
c00e3f7f5b17
client: use constant names instead of strings
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2296
diff
changeset
|
690 this.getLayerByName(LAYERS.BOTTLENECKISOLINE).isVisible |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
691 ) { |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
692 // transforming into an HTMLImageElement only to find out |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
693 // the width x height of the legend image |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
694 // FUTURE: find a better way to get the width and height |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
695 let legendImage = new Image(); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
696 legendImage.src = this.isolinesLegendImgDataURL; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
697 let aspectRatio = legendImage.width / legendImage.height; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
698 let width = 54; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
699 let height = width / aspectRatio; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
700 let padding = 2; |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
701 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
702 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
703 let x = offset.x; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
704 let y = offset.y; |
1947
4235fa8f59d7
clien: pdf-gen: load logo externally; add prepare step
Bernhard Reiter <bernhard@intevation.de>
parents:
1936
diff
changeset
|
705 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
706 // if position is on the right, x needs to be calculate with pdf width and |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
707 // the size of the element |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
708 if (["topright", "bottomright"].indexOf(position) !== -1) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
709 x = this.pdf.width - offset.x - width; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
710 } |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
711 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
712 y = this.pdf.height - offset.y - height; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
713 } |
1947
4235fa8f59d7
clien: pdf-gen: load logo externally; add prepare step
Bernhard Reiter <bernhard@intevation.de>
parents:
1936
diff
changeset
|
714 |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
715 this.addRoundedBox(x, y, width, height, "white", rounding); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
716 this.pdf.doc.addImage( |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
717 legendImage, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
718 x + padding, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
719 y + padding, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
720 width - 2 * padding, |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
721 height - 2 * padding |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
722 ); |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
723 } |
1931
8fb1b1a8ea85
client: pdf-gen: improve legend behaviour
Bernhard Reiter <bernhard@intevation.de>
parents:
1928
diff
changeset
|
724 }, |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
725 addBottleneckInfo(position, offset, rounding, color) { |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
726 if ( |
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
727 this.selectedBottleneck && |
2259
7e378b38d302
client: pdf-gen: made selectedSurvey mandatory for displaying the bottleneck info box and iso line legend.
Markus Kottlaender <markus@intevation.de>
parents:
2258
diff
changeset
|
728 this.selectedSurvey && |
2321
c00e3f7f5b17
client: use constant names instead of strings
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2296
diff
changeset
|
729 this.getLayerByName(LAYERS.BOTTLENECKISOLINE).isVisible |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
730 ) { |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
731 let survey = this.selectedSurvey; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
732 |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
733 // determine text dimensions |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
734 // this is a little bit cumbersome but we need to separate width |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
735 // calculations and writing |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
736 this.pdf.doc.setFontSize(10); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
737 this.pdf.doc.setTextColor(color); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
738 let textOptions = { baseline: "hanging" }; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
739 let str1_1 = this.$gettext("Bottleneck") + ": "; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
740 let str1_2 = this.selectedBottleneck; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
741 let str2_1 = this.$gettext("Survey date") + ": "; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
742 let str2_2 = survey.date_info; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
743 let str3_1 = this.$gettext("Ref gauge") + ": "; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
744 let str3_2 = survey.gauge_objname; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
745 let str4_1 = this.$gettext("Depth relativ to") + ": "; |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
746 let str4_2 = |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
747 survey.depth_reference + |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
748 " = " + |
2291
60af456d01f0
client:pdf-gen:(minor) fix bottleneckinfo function
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2288
diff
changeset
|
749 (survey.hasOwnProperty("waterlevel_value") |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
750 ? survey.waterlevel_value + " cm" |
2291
60af456d01f0
client:pdf-gen:(minor) fix bottleneckinfo function
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2288
diff
changeset
|
751 : "?"); |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
752 |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
753 this.pdf.doc.setFontStyle("italic"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
754 let w1_1 = this.pdf.doc.getTextWidth(str1_1); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
755 this.pdf.doc.setFontStyle("bold"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
756 let w1_2 = this.pdf.doc.getTextWidth(str1_2); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
757 this.pdf.doc.setFontStyle("italic"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
758 let w2_1 = this.pdf.doc.getTextWidth(str2_1); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
759 this.pdf.doc.setFontStyle("normal"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
760 let w2_2 = this.pdf.doc.getTextWidth(str2_2); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
761 this.pdf.doc.setFontStyle("italic"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
762 let w3_1 = this.pdf.doc.getTextWidth(str3_1); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
763 this.pdf.doc.setFontStyle("normal"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
764 let w3_2 = this.pdf.doc.getTextWidth(str3_2); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
765 this.pdf.doc.setFontStyle("italic"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
766 let w4_1 = this.pdf.doc.getTextWidth(str4_1); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
767 this.pdf.doc.setFontStyle("normal"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
768 let w4_2 = this.pdf.doc.getTextWidth(str4_2); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
769 |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
770 let height = 21; |
2240
c3cc21dee75d
client: pdf-gen add multi-language font
Bernhard Reiter <bernhard@intevation.de>
parents:
2227
diff
changeset
|
771 let padding = 3; |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
772 let width = |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
773 Math.max(w1_1 + w1_2, w2_1 + w2_2, w3_1 + w3_2, w4_1 + w4_2) + |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
774 2 * padding; |
2220
d926292d81b6
PDF generation: changed form labels/option texts
Markus Kottlaender <markus@intevation.de>
parents:
2219
diff
changeset
|
775 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
776 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
777 let x = offset.x; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
778 let y = offset.y; |
1931
8fb1b1a8ea85
client: pdf-gen: improve legend behaviour
Bernhard Reiter <bernhard@intevation.de>
parents:
1928
diff
changeset
|
779 |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
780 // if position is on the right, x needs to be calculate with pdf width and |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
781 // the size of the element |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
782 if (["topright", "bottomright"].indexOf(position) !== -1) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
783 x = this.pdf.width - offset.x - width; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
784 } |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
785 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
786 y = this.pdf.height - offset.y - height; |
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
787 } |
2137
a31c9fa47ab8
client: pdf-gen: add bottleneck details
Bernhard Reiter <bernhard@intevation.de>
parents:
2124
diff
changeset
|
788 |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
789 // white background box |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
790 this.addRoundedBox(x, y, width, height, "white", rounding); |
2138
4a903d382901
client: pdf-gen: make bottleneck infos more fancy
Bernhard Reiter <bernhard@intevation.de>
parents:
2137
diff
changeset
|
791 |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
792 // bottleneck |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
793 this.pdf.doc.setFontStyle("italic"); |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
794 this.pdf.doc.text(x + padding, y + padding, str1_1, textOptions); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
795 this.pdf.doc.setFontStyle("bold"); |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
796 this.pdf.doc.text(x + padding + w1_1, y + padding, str1_2, textOptions); |
2137
a31c9fa47ab8
client: pdf-gen: add bottleneck details
Bernhard Reiter <bernhard@intevation.de>
parents:
2124
diff
changeset
|
797 |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
798 // survey date |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
799 this.pdf.doc.setFontStyle("italic"); |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
800 this.pdf.doc.text(x + padding, y + padding + 4, str2_1, textOptions); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
801 this.pdf.doc.setFontStyle("normal"); |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
802 this.pdf.doc.text( |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
803 x + padding + w2_1, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
804 y + padding + 4, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
805 str2_2, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
806 textOptions |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
807 ); |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
808 |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
809 // ref gauge |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
810 this.pdf.doc.setFontStyle("italic"); |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
811 this.pdf.doc.text(x + padding, y + padding + 8, str3_1, textOptions); |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2240
diff
changeset
|
812 this.pdf.doc.setFontStyle("normal"); |
2258
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
813 this.pdf.doc.text( |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
814 x + padding + w3_1, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
815 y + padding + 8, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
816 str3_2, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
817 textOptions |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
818 ); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
819 |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
820 // depth relative to |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
821 this.pdf.doc.setFontStyle("italic"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
822 this.pdf.doc.text(x + padding, y + padding + 12, str4_1, textOptions); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
823 this.pdf.doc.setFontStyle("normal"); |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
824 this.pdf.doc.text( |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
825 x + padding + w4_1, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
826 y + padding + 12, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
827 str4_2, |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
828 textOptions |
24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
Markus Kottlaender <markus@intevation.de>
parents:
2257
diff
changeset
|
829 ); |
2218
631ca0412db9
adjusted positioning of pdf elements
Markus Kottlaender <markus@intevation.de>
parents:
2215
diff
changeset
|
830 } |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
831 }, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
832 replacePlaceholders(text) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
833 if (text.includes("{date}")) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
834 text = text.replace("{date}", new Date().toLocaleString(locale2)); |
2167
40f26fbc505f
client: pdf-gen: add reference_water_level to details
Bernhard Reiter <bernhard@intevation.de>
parents:
2154
diff
changeset
|
835 } |
2223
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
836 if (text.includes("{user}")) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
837 text = text.replace("{user}", this.user); |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
838 } |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
839 return text; |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
840 }, |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
841 getTextHeight(numberOfLines) { |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
842 return ( |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
843 numberOfLines * |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
844 ((this.pdf.doc.getFontSize() * 25.4) / parseInt(this.form.resolution)) * |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
845 this.pdf.doc.getLineHeightFactor() |
85142493096c
PDF generation: improved positioning, prepared demo templates
Markus Kottlaender <markus@intevation.de>
parents:
2222
diff
changeset
|
846 ); |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
847 } |
2212
733cfc3db48a
started pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2207
diff
changeset
|
848 }, |
733cfc3db48a
started pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2207
diff
changeset
|
849 mounted() { |
2265
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
850 this.form.template = this.templates[0]; |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
851 this.templateData = this.form.template; |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
852 HTTP.get("/templates/print", { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
853 headers: { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
854 "X-Gemma-Auth": localStorage.getItem("token"), |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
855 "Content-type": "text/xml; charset=UTF-8" |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
856 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
857 }) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
858 .then(response => { |
2265
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
859 if (response.data.length) { |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
860 this.templates = response.data; |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
861 this.form.template = this.templates[0]; |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
862 this.applyTemplateToForm(); |
940ae7c20326
client: pdf-gen: use default template when backend does not provide any
Markus Kottlaender <markus@intevation.de>
parents:
2260
diff
changeset
|
863 } |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
864 }) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
865 .catch(e => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
866 const { status, data } = e.response; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
867 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2275
diff
changeset
|
868 title: this.$gettext("Backend Error"), |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
869 message: `${status}: ${data.message || data}` |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
870 }); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
871 }); |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
872 } |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
873 }; |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
874 </script> |