annotate client/src/components/identify/Identify.vue @ 2735:3c2ac140ad30

identify_tool: zoom to BBox PoC implemented
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 19 Mar 2019 16:32:07 +0100
parents bb5286acfee2
children 4063adda3095
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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" />
2534
bb5286acfee2 client: reduced spacings between and inside boxes and more compact main menu
Markus Kottlaender <markus@intevation.de>
parents: 2441
diff changeset
10 <div class="features">
2371
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>
2735
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
36 <span v-if="prop.key != 'bbox'">{{ prop.val }}</span>
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
37 <a v-else @click="zoomTo(prop.val)" href="#"
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
38 ><translate>Zoom to</translate></a
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
39 >
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
40 </small>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
41 </div>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
42 <div
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
43 v-if="!currentMeasurement && !filteredIdentifiedFeatures.length"
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
44 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
45 >
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
46 <translate>No features identified.</translate>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
47 </div>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
48 </div>
2534
bb5286acfee2 client: reduced spacings between and inside boxes and more compact main menu
Markus Kottlaender <markus@intevation.de>
parents: 2441
diff changeset
49 <div class="versioninfo border-top box-body">
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
50 <span v-translate="{ license: 'AGPL-3.0-or-later' }">
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
51 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
52 %{ license } without warranty, see docs for details.
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
53 </span>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
54 <br />
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
55 <a href="https://hg.intevation.de/gemma/file/tip">
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
56 <translate>source-code</translate>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
57 </a>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
58 {{ versionStr }} <br />© via donau. &#x24D4; Intevation. <br />
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
59 <span v-translate="{ name: 'OpenSteetMap' }"
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
60 >Some data ©
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
61 <a href="https://www.openstreetmap.org/copyright">%{ name }</a>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
62 contributors.
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
63 </span>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
64 <br />
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
65 <span v-translate="{ geoLicense: 'CC-BY-4.0' }">
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
66 Uses
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
67 <a href="https://download.geonames.org/export/dump/readme.txt"
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
68 >GeoNames</a
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
69 >
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
70 under %{ geoLicense }.
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
71 </span>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
72 <translate>Generated PDFs use font: </translate>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
73 <a href="http://libertine-fonts.org">LinBiolinum</a>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
74 </div>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
75 </div>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
76 </div>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
77 </template>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
78
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
79 <style lang="scss" scoped>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
80 .features {
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
81 max-height: 19rem;
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
82 overflow-y: auto;
2372
20e4efa64320 client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2371
diff changeset
83 small {
20e4efa64320 client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2371
diff changeset
84 &:nth-child(even) {
20e4efa64320 client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2371
diff changeset
85 background: #f8f8f8;
20e4efa64320 client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2371
diff changeset
86 }
20e4efa64320 client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2371
diff changeset
87 &:hover {
20e4efa64320 client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2371
diff changeset
88 background: #eeeeee;
20e4efa64320 client: improved row colors in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2371
diff changeset
89 }
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
90 }
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
91 }
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
92
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
93 .versioninfo {
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
94 font-size: 60%;
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
95 white-space: normal;
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
96 }
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
97 </style>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
98
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
99 <script>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
100 /* 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
101 * without warranty, see README.md and license for details.
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 * SPDX-License-Identifier: AGPL-3.0-or-later
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
104 * License-Filename: LICENSES/AGPL-3.0.txt
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
105 *
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
106 * Copyright (C) 2018, 2019 by via donau
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
107 * – Österreichische Wasserstraßen-Gesellschaft mbH
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
108 * Software engineering by Intevation GmbH
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
109 *
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
110 * Author(s):
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
111 * Thomas Junk <thomas.junk@intevation.de>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
112 * Bernhard E. Reiter <bernhard.reiter@intevation.de>
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
113 * Markus Kottländer <markus.kottlaender@intevation.de>
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 import { mapState, mapGetters } from "vuex";
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
116 import { formatter } from "./formatter";
2735
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
117 import { displayInfo } from "@/lib/errors.js";
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
118
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
119 export default {
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
120 name: "identify",
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
121 computed: {
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
122 ...mapGetters("application", ["versionStr"]),
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
123 ...mapState("application", ["showIdentify"]),
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
124 ...mapGetters("map", ["filteredIdentifiedFeatures"]),
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
125 ...mapState("map", ["currentMeasurement"])
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
126 },
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
127 methods: {
2735
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
128 zoomTo(val) {
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
129 displayInfo({
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
130 message:
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
131 "Coordinates:\n" +
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
132 JSON.stringify(val)
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
133 .split(",")
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
134 .join("\n")
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
135 });
3c2ac140ad30 identify_tool: zoom to BBox PoC implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 2534
diff changeset
136 },
2387
f185503ef35a client: unified box's header styles by creating a reusable component
Markus Kottlaender <markus@intevation.de>
parents: 2372
diff changeset
137 close() {
f185503ef35a client: unified box's header styles by creating a reusable component
Markus Kottlaender <markus@intevation.de>
parents: 2372
diff changeset
138 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
139 },
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
140 featureId(feature) {
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
141 // cut away everything from the last . to the end
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
142 return feature.getId().replace(/[.][^.]*$/, "");
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
143 },
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
144 featureLabel(feature) {
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
145 if (formatter.hasOwnProperty(this.featureId(feature))) {
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
146 return formatter[this.featureId(feature)].label;
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
147 }
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
148 return this.featureId(feature);
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
149 },
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
150 featureProps(feature) {
2441
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
151 let featureId = this.featureId(feature);
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
152
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
153 // create array with {key, val} objects
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
154 let propsArray = [];
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
155 Object.keys(feature.getProperties()).forEach(key => {
2423
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
156 // 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
157 if (key !== feature.getGeometryName()) {
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
158 let val = feature.getProperties()[key];
2405
ef928c63388a client: handle json values in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2387
diff changeset
159
2423
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
160 // 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
161 let jsonObj = this.getObjectFromString(val);
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
162 if (jsonObj) {
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
163 Object.keys(jsonObj).forEach(key => {
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
164 propsArray.push({ key, val: jsonObj[key] });
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
165 });
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
166 } else {
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
167 // 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
168 propsArray.push({ key, val });
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
169 }
2405
ef928c63388a client: handle json values in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2387
diff changeset
170 }
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
171 });
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 // change labels and remove unneeded properties
2441
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
174 // for all features
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
175 propsArray = propsArray.map(formatter.all);
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
176 // feature specific
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
177 if (
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
178 formatter.hasOwnProperty(featureId) &&
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
179 formatter[featureId].hasOwnProperty("props")
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
180 ) {
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
181 propsArray = propsArray.map(formatter[featureId].props);
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
182 }
2441
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
183 // remove empty entries
9de710bdb535 client: improved identify box formatter
Markus Kottlaender <markus@intevation.de>
parents: 2424
diff changeset
184 propsArray = propsArray.filter(p => p);
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
185
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
186 // remove underscores in labels that where not previously changed already
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
187 propsArray = propsArray.map(prop => {
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
188 return { key: prop.key.replace(/_/g, " "), val: prop.val };
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
189 });
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
190
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
191 return propsArray;
2423
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
192 },
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
193 getObjectFromString(val) {
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
194 // 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
195 // 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
196 // 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
197 if (
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
198 Object.prototype.toString.call(val) === "[object String]" &&
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
199 val[0] === "{"
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
200 ) {
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
201 try {
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
202 return JSON.parse(val);
2424
b6deb03ef13f client: fix linter error (empty block)
Markus Kottlaender <markus@intevation.de>
parents: 2423
diff changeset
203 } catch (e) {
b6deb03ef13f client: fix linter error (empty block)
Markus Kottlaender <markus@intevation.de>
parents: 2423
diff changeset
204 return null;
b6deb03ef13f client: fix linter error (empty block)
Markus Kottlaender <markus@intevation.de>
parents: 2423
diff changeset
205 }
2423
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
206 }
3423cd4b3136 client: fix json parsing in identify box
Markus Kottlaender <markus@intevation.de>
parents: 2405
diff changeset
207 return null;
2371
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
208 }
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
209 }
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
210 };
045bac575294 client: fixed broken previous commit
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
211 </script>