-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBalloonComponent.vue
233 lines (224 loc) · 6.51 KB
/
BalloonComponent.vue
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<template>
<v-card class="mx-auto elevation-0 balloon-component" v-if="position">
<slot name="balloon-header" :attrs="{ ...$props, ...$attrs }">
<v-list-item class="px-1">
<template #prepend="prependScope">
<slot name="prepend" v-bind="prependScope">
<div class="pl-1 pr-2">
<v-icon color="primary" :size="iconSize"> $vcsInfo </v-icon>
</div>
</slot>
</template>
<slot name="balloon-title" :attrs="{ ...$props, ...$attrs }">
<v-list-item-title>
<h3 class="font-weight-bold">
{{ $st(balloonTitle) }}
</h3>
</v-list-item-title>
<v-list-item-subtitle v-if="balloonSubtitle">
{{ $st(balloonSubtitle) }}
</v-list-item-subtitle>
</slot>
<template #append>
<VcsButton
@click.stop="close"
icon="mdi-close-thick"
tooltip="components.close"
class="px-1"
/>
</template>
</v-list-item>
</slot>
<v-divider />
<v-card
class="overflow-y-auto py-2 elevation-0"
:max-height="maxHeight"
color="transparent"
>
<slot :attrs="{ ...$props, ...$attrs }">
<v-list
v-for="(value, key, index) in attributes"
:key="`attribute-${index}`"
color="transparent"
>
<v-list-item class="px-2">
<v-list-item-title>
{{ $st(key) }}
</v-list-item-title>
<v-list-item-subtitle
:tag="getTag(tags, key)"
v-bind="getTagOptions(tags, key)"
>
{{ typeof value === 'string' ? $st(value) : value }}
</v-list-item-subtitle>
</v-list-item>
</v-list>
</slot>
</v-card>
</v-card>
</template>
<script>
import { inject, onMounted, onUnmounted, ref, watch } from 'vue';
import {
VCard,
VDivider,
VIcon,
VList,
VListItem,
VListItemSubtitle,
VListItemTitle,
} from 'vuetify/components';
import {
getTargetSize,
posToNumber,
} from '../manager/window/windowHelper.js';
import { setupBalloonPositionListener } from './balloonHelper.js';
import VcsButton from '../components/buttons/VcsButton.vue';
import { getTag, getTagOptions } from '../components/tables/VcsTable.vue';
import { useIconSize } from '../vuePlugins/vuetify.js';
/**
* @description A balloon viewing feature attributes. Size dynamic dependent on number of attributes.
* Scrollable, if more than 6 attributes are provided.
* @vue-prop {string} featureId - feature's id
* @vue-prop {string} balloonTitle - balloon title
* @vue-prop {string} balloonSubtitle - balloon subtitle
* @vue-prop {Object} attributes - feature's attributes
* @vue-prop {Object} tags - optional object containing keys rendered as tags
* @vue-prop {Array<import("ol/coordinate").Coordinate>} position - clicked position balloon is rendered at
* @vue-data {slot} [#balloon-header] - slot to override balloon header, $props and $attrs are passed to `attrs`
* @vue-data {slot} [#balloon-title] - slot to override balloon title and subtitle, $props and $attrs are passed to `attrs`. Is overwritten by balloon-header slot.
* @vue-data {slot} [#default] - slot to override balloon content, $props and $attrs are passed to `attrs`
* @vue-data {slot} [#prepend] - slot to override balloon header icon
*/
export default {
name: 'BalloonComponent',
components: {
VcsButton,
VCard,
VList,
VListItem,
VIcon,
VListItemTitle,
VListItemSubtitle,
VDivider,
},
props: {
featureId: {
type: String,
required: true,
},
balloonTitle: {
type: String,
required: true,
},
balloonSubtitle: {
type: String,
required: true,
},
attributes: {
type: Object,
required: true,
},
tags: {
type: Object,
default: undefined,
},
position: {
type: Array,
default: null,
},
},
setup(props, { attrs }) {
const app = inject('vcsApp');
const windowId = attrs['window-state'].id;
function getMaxHeight() {
if (app.windowManager.get(windowId)?.position?.maxHeight) {
return (
posToNumber(
app.windowManager.get(windowId).position.maxHeight,
'maxHeight',
getTargetSize(app.maps.target),
) - 49 // 44px header offset with padding 5px
);
}
if (app.windowManager.get(windowId)?.position?.height) {
return (
posToNumber(
app.windowManager.get(windowId).position.height,
'height',
getTargetSize(app.maps.target),
) - 49 // 44px header offset with padding 5px
);
}
return 250;
}
const maxHeight = ref(getMaxHeight());
let balloonPositionListener = null;
const destroyListener = () => {
if (balloonPositionListener) {
balloonPositionListener();
}
};
onMounted(async () => {
balloonPositionListener = await setupBalloonPositionListener(
app,
windowId,
props.position,
);
});
watch(
() => props.featureId,
async () => {
destroyListener();
balloonPositionListener = await setupBalloonPositionListener(
app,
windowId,
props.position,
);
maxHeight.value = getMaxHeight();
},
);
onUnmounted(() => {
destroyListener();
});
const close = () => {
app.windowManager.remove(attrs['window-state'].id);
destroyListener();
};
const iconSize = useIconSize();
return {
iconSize,
close,
getTag,
getTagOptions,
maxHeight,
};
},
};
</script>
<style lang="scss">
.balloon {
z-index: 0 !important;
}
.balloon hr:first-child {
display: none;
}
.balloon:after {
content: '';
position: absolute;
bottom: -12px;
left: 40px;
border-width: 12px 10px 0;
border-style: solid;
display: block;
width: 0;
filter: drop-shadow(1px 2px 1px rgba(0, 0, 0, 0.3));
}
.balloon:after {
border-color: rgb(var(--v-theme-surface-light)) transparent;
}
.balloon .v-list-item .v-list-item__title,
.balloon .v-list-item .v-list-item__subtitle {
line-height: 18px;
}
</style>