-
Notifications
You must be signed in to change notification settings - Fork 4
/
FeaturePopup.svelte
98 lines (79 loc) · 3.04 KB
/
FeaturePopup.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<style>
.propRow > td {
padding: 2px;
}
.propRow > td:hover {
background-color: rgba(240, 240, 240, 0.75);
cursor: pointer;
}
.propRow > td.active {
background-color: lightyellow;
}
</style>
<div style="{featurePinned ? 'height: 200px; overflow: auto;' : ''}">
<table>
{#each summaryProps as [prop, value, propStack]}
<tr class="propRow">
<td style="width: 50px;" class:active="prop === featureProp" on:click="fire('selectProp', { prop, propStack })">
<b>{@html Array((propStack.length - 1) * 2).fill(' ').join('')}{propStack[propStack.length-1]}</b>
</td>
<td style="word-break: break-all;" class:active="value === featurePropValue" on:click="fire('selectValue', { prop, propStack, value })">
{typeof value !== 'object' ? value : ''}
</td>
</tr>
{/each}
{#if extendedProps.length && summaryProps.length}
<tr><td colspan="2"><hr></td></tr>
{/if}
{#each extendedProps as [prop, value, propStack]}
<tr class="propRow">
<td style="width: 50px;" class:active="prop === featureProp" on:click="fire('selectProp', { prop, propStack })">
<b>{@html Array((propStack.length - 1) * 2).fill(' ').join('')}{propStack[propStack.length-1]}</b>
</td>
<td style="word-break: break-all;" class:active="value === featurePropValue" on:click="fire('selectValue', { prop, propStack, value })">
{typeof value !== 'object' ? value : ''}
</td>
</tr>
{/each}
{#if !featurePinned && feature}
<tr><td colspan="2"><i>Click to see all {Object.keys(feature.properties).length} properties</i></td></tr>
{/if}
</div>
<script>
import { parsePropStack, parseNestedObject, lookupProperty } from './utils';
export default {
data() {
return {
featurePinned: false
}
},
computed: {
summaryProps: ({ feature, featureProp }) => {
if (feature == null) {
return [];
}
const featurePropStack = parsePropStack(featureProp);
const addFeatureProp = (['id', 'name', 'wof:name'].indexOf(featureProp) === -1);
return [
['id', feature.properties.id, ['id']],
['name', feature.properties.name, ['name']],
['WOF name', feature.properties['wof:name'], ['wof:name']],
['feature id', feature.id, ['feature id']],
addFeatureProp ? [featureProp, lookupProperty(feature.properties, featurePropStack) || 'null', featurePropStack] : []
]
.filter(x => x[0] && x[1]); // only include props that had values
},
extendedProps: ({ feature, featureProp, featurePinned }) => {
if (!featurePinned || feature == null) {
return [];
}
return parseNestedObject(feature.properties)
.map(r => [r.prop, r.obj, r.propStack])
.filter(([p]) => ['id', 'name', 'wof:name'/*, featureProp*/].indexOf(p) === -1)
.filter(x => x[0] && x[1]) // only include props that had values
// alpha sort, @ properties at bottom
.sort(([a], [b]) => a[0] === '@' ? 1 : b[0] === '@' ? -1 : a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0);
}
}
};
</script>