Mercurial > gemma
annotate client/src/components/identify/Identify.vue @ 2455:54c9fe587fe6
Subdivide SQL function to prepare for improved error handling
The context of an error (e.g. the function in which it occured)
can be inferred by the database client. Not doing all in one
statement will render the context more meaningful.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 01 Mar 2019 18:38:02 +0100 |
parents | 9de710bdb535 |
children | bb5286acfee2 |
rev | line source |
---|---|
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1 <template> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
2 <div |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
3 :class="[ |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
4 'box ui-element rounded bg-white text-nowrap', |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
5 { expanded: showIdentify } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
6 ]" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
7 > |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
8 <div style="width: 18rem"> |
2387
f185503ef35a
client: unified box's header styles by creating a reusable component
Markus Kottlaender <markus@intevation.de>
parents:
2372
diff
changeset
|
9 <UIBoxHeader icon="info" title="Identified" :closeCallback="close" /> |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
10 <div class="features flex-grow-1 text-left"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
11 <div v-if="currentMeasurement"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
12 <small class="d-block bg-dark text-light text-center px-2 py-1"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
13 {{ $gettext("Measurement") }} |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
14 </small> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
15 <small class="d-flex justify-content-between px-2"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
16 <b> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
17 {{ currentMeasurement.quantity }} |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
18 </b> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
19 {{ currentMeasurement.value }} {{ currentMeasurement.unitSymbol }} |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
20 </small> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
21 </div> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
22 <div |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
23 v-for="feature of filteredIdentifiedFeatures" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
24 :key="feature.getId()" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
25 > |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
26 <small class="d-block bg-dark text-light text-center px-2 py-1"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
27 {{ $gettext(featureLabel(feature)) }} |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
28 </small> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
29 <small |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
30 v-for="prop in featureProps(feature)" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
31 :key="prop.key" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
32 v-if="prop.val" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
33 class="d-flex justify-content-between px-2" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
34 > |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
35 <b>{{ $gettext(prop.key) }}</b> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
36 {{ prop.val }} |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
37 </small> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
38 </div> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
39 <div |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
40 v-if="!currentMeasurement && !filteredIdentifiedFeatures.length" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
41 class="text-muted small text-center my-auto py-3 px-2" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
42 > |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
43 <translate>No features identified.</translate> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
44 </div> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
45 </div> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
46 <div class="versioninfo border-top p-3 text-left"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
47 <span v-translate="{ license: 'AGPL-3.0-or-later' }"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
48 This app uses <i>gemma</i>, which is Free Software under <br /> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
49 %{ license } without warranty, see docs for details. |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
50 </span> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
51 <br /> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
52 <a href="https://hg.intevation.de/gemma/file/tip"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
53 <translate>source-code</translate> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
54 </a> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
55 {{ versionStr }} <br />© via donau. ⓔ Intevation. <br /> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
56 <span v-translate="{ name: 'OpenSteetMap' }" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
57 >Some data © |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
58 <a href="https://www.openstreetmap.org/copyright">%{ name }</a> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
59 contributors. |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
60 </span> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
61 <br /> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
62 <span v-translate="{ geoLicense: 'CC-BY-4.0' }"> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
63 Uses |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
64 <a href="https://download.geonames.org/export/dump/readme.txt" |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
65 >GeoNames</a |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
66 > |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
67 under %{ geoLicense }. |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
68 </span> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
69 <translate>Generated PDFs use font: </translate> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
70 <a href="http://libertine-fonts.org">LinBiolinum</a> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
71 </div> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
72 </div> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
73 </div> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
74 </template> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
75 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
76 <style lang="scss" scoped> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
77 .features { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
78 max-height: 19rem; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
79 overflow-y: auto; |
2372
20e4efa64320
client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2371
diff
changeset
|
80 small { |
20e4efa64320
client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2371
diff
changeset
|
81 &:nth-child(even) { |
20e4efa64320
client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2371
diff
changeset
|
82 background: #f8f8f8; |
20e4efa64320
client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2371
diff
changeset
|
83 } |
20e4efa64320
client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2371
diff
changeset
|
84 &:hover { |
20e4efa64320
client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2371
diff
changeset
|
85 background: #eeeeee; |
20e4efa64320
client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2371
diff
changeset
|
86 } |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
87 } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
88 } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
89 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
90 .versioninfo { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
91 font-size: 60%; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
92 white-space: normal; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
93 } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
94 </style> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
95 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
96 <script> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
97 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
98 * without warranty, see README.md and license for details. |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
99 * |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
100 * SPDX-License-Identifier: AGPL-3.0-or-later |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
101 * License-Filename: LICENSES/AGPL-3.0.txt |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
102 * |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
103 * Copyright (C) 2018, 2019 by via donau |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
104 * – Österreichische Wasserstraßen-Gesellschaft mbH |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
105 * Software engineering by Intevation GmbH |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
106 * |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
107 * Author(s): |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
108 * Thomas Junk <thomas.junk@intevation.de> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
109 * Bernhard E. Reiter <bernhard.reiter@intevation.de> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
110 * Markus Kottländer <markus.kottlaender@intevation.de> |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
111 */ |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
112 import { mapState, mapGetters } from "vuex"; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
113 import { formatter } from "./formatter"; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
114 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
115 export default { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
116 name: "identify", |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
117 computed: { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
118 ...mapGetters("application", ["versionStr"]), |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
119 ...mapState("application", ["showIdentify"]), |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
120 ...mapGetters("map", ["filteredIdentifiedFeatures"]), |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
121 ...mapState("map", ["currentMeasurement"]) |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
122 }, |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
123 methods: { |
2387
f185503ef35a
client: unified box's header styles by creating a reusable component
Markus Kottlaender <markus@intevation.de>
parents:
2372
diff
changeset
|
124 close() { |
f185503ef35a
client: unified box's header styles by creating a reusable component
Markus Kottlaender <markus@intevation.de>
parents:
2372
diff
changeset
|
125 this.$store.commit("application/showIdentify", false); |
f185503ef35a
client: unified box's header styles by creating a reusable component
Markus Kottlaender <markus@intevation.de>
parents:
2372
diff
changeset
|
126 }, |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
127 featureId(feature) { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
128 // cut away everything from the last . to the end |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
129 return feature.getId().replace(/[.][^.]*$/, ""); |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
130 }, |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
131 featureLabel(feature) { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
132 if (formatter.hasOwnProperty(this.featureId(feature))) { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
133 return formatter[this.featureId(feature)].label; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
134 } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
135 return this.featureId(feature); |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
136 }, |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
137 featureProps(feature) { |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
138 let featureId = this.featureId(feature); |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
139 |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
140 // create array with {key, val} objects |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
141 let propsArray = []; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
142 Object.keys(feature.getProperties()).forEach(key => { |
2423
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
143 // skip geometry (would lead to cyclic object error) |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
144 if (key !== feature.getGeometryName()) { |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
145 let val = feature.getProperties()[key]; |
2405
ef928c63388a
client: handle json values in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2387
diff
changeset
|
146 |
2423
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
147 // if val is a valid json object string, spread its values into the array |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
148 let jsonObj = this.getObjectFromString(val); |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
149 if (jsonObj) { |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
150 Object.keys(jsonObj).forEach(key => { |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
151 propsArray.push({ key, val: jsonObj[key] }); |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
152 }); |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
153 } else { |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
154 // otherwise just put the key value pair into the array |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
155 propsArray.push({ key, val }); |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
156 } |
2405
ef928c63388a
client: handle json values in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2387
diff
changeset
|
157 } |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
158 }); |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
159 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
160 // change labels and remove unneeded properties |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
161 // for all features |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
162 propsArray = propsArray.map(formatter.all); |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
163 // feature specific |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
164 if ( |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
165 formatter.hasOwnProperty(featureId) && |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
166 formatter[featureId].hasOwnProperty("props") |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
167 ) { |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
168 propsArray = propsArray.map(formatter[featureId].props); |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
169 } |
2441
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
170 // remove empty entries |
9de710bdb535
client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents:
2424
diff
changeset
|
171 propsArray = propsArray.filter(p => p); |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
172 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
173 // remove underscores in labels that where not previously changed already |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
174 propsArray = propsArray.map(prop => { |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
175 return { key: prop.key.replace(/_/g, " "), val: prop.val }; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
176 }); |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
177 |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
178 return propsArray; |
2423
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
179 }, |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
180 getObjectFromString(val) { |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
181 // JSON.parse() accepts integers and null as valid json. So to be sure to |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
182 // get an object, we cannot just try JSON.parse() but we need to check if |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
183 // the given value is a string and starts with a {. |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
184 if ( |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
185 Object.prototype.toString.call(val) === "[object String]" && |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
186 val[0] === "{" |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
187 ) { |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
188 try { |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
189 return JSON.parse(val); |
2424
b6deb03ef13f
client: fix linter error (empty block)
Markus Kottlaender <markus@intevation.de>
parents:
2423
diff
changeset
|
190 } catch (e) { |
b6deb03ef13f
client: fix linter error (empty block)
Markus Kottlaender <markus@intevation.de>
parents:
2423
diff
changeset
|
191 return null; |
b6deb03ef13f
client: fix linter error (empty block)
Markus Kottlaender <markus@intevation.de>
parents:
2423
diff
changeset
|
192 } |
2423
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
193 } |
3423cd4b3136
client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents:
2405
diff
changeset
|
194 return null; |
2371
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
195 } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
196 } |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
197 }; |
045bac575294
client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
198 </script> |