1
1
<template >
2
- <q-tree
3
- :nodes =" [root]"
4
- node-key =" _id"
5
- label-key =" label"
6
- children-key =" children"
7
- v-model:expanded =" expandedNodes"
8
- dense
9
- >
10
- <template v-slot :default-header =" prop " >
11
- <!-- Layer rendering -->
12
- <q-icon v-if =" prop.node.icon" :name =" prop.node.icon" />
13
- <KLayerItem v-if =" isLayerNode(prop.node)"
14
- v-bind =" $props"
15
- :togglable =" false"
16
- :layer =" root"
17
- />
18
- <!-- Features rendering -->
19
- <div v-else-if =" prop.node.label" class =" row fit items-center q-pl-md q-pr-sm no-wrap" >
20
- <div :class =" {
21
- 'text-primary': root.isVisible,
22
- 'text-grey-6': root.isDisabled || !root.isVisible
23
- }"
24
- >
25
- <span v-html =" prop.node.label" />
2
+ <div >
3
+ <q-tree
4
+ :nodes =" [root]"
5
+ node-key =" _id"
6
+ label-key =" label"
7
+ children-key =" children"
8
+ v-model:expanded =" expandedNodes"
9
+ dense
10
+ >
11
+ <template v-slot :default-header =" prop " >
12
+ <!-- Layer rendering -->
13
+ <q-icon v-if =" prop.node.icon" :name =" prop.node.icon" />
14
+ <KLayerItem v-if =" isLayerNode(prop.node)"
15
+ v-bind =" $props"
16
+ :togglable =" false"
17
+ :layer =" root"
18
+ />
19
+ <!-- Features rendering -->
20
+ <div v-else-if =" prop.node.label" class =" row fit items-center q-pl-md q-pr-sm no-wrap" >
21
+ <div :class =" {
22
+ 'text-primary': root.isVisible,
23
+ 'text-grey-6': root.isDisabled || !root.isVisible
24
+ }"
25
+ >
26
+ <span v-html =" prop.node.label" />
27
+ </div >
28
+ <q-space v-if =" isFeatureNode(prop.node)" />
29
+ <!-- Features actions -->
30
+ <KPanel v-if =" isFeatureNode(prop.node)"
31
+ :id =" `${prop.node.label}-feature-actions`"
32
+ :content =" featureActions"
33
+ :context =" prop.node"
34
+ />
26
35
</div >
27
- <q-space v-if =" isFeatureNode(prop.node)" />
28
- <!-- Features actions -->
29
- <KPanel v-if =" isFeatureNode(prop.node)"
30
- :id =" `${prop.node.label}-feature-actions`"
31
- :content =" featureActions"
32
- :context =" prop.node"
36
+ </template >
37
+ <!-- Feature properties rendering -->
38
+ <template v-slot :default-body =" prop " >
39
+ <KView v-if =" isFeaturePropertiesNode(prop.node)"
40
+ class =" q-pa-md full-width"
41
+ :values =" prop.node"
42
+ :schema =" schema"
43
+ :separators =" true"
33
44
/>
34
- </div >
35
- </template >
36
- <!-- Feature properties rendering -->
37
- <template v-slot :default-body =" prop " >
38
- <KView v-if =" isFeaturePropertiesNode(prop.node)"
39
- class =" q-pa-md full-width"
40
- :values =" prop.node"
41
- :schema =" schema"
42
- :separators =" true"
43
- />
44
- </template >
45
- </q-tree >
45
+ </template >
46
+ </q-tree >
47
+ <KModal
48
+ id =" style-editor-modal"
49
+ :title =" styleEditorTitle"
50
+ :buttons =" []"
51
+ v-model =" isFeatureStyleEdited"
52
+ >
53
+ <KStyleEditor :edit-name =" false" :allowed-styles =" [editedFeatureType]" :style =" editedFeatureStyle" @cancel =" onCancelFeatureStyle" @apply =" onApplyFeatureStyle" />
54
+ </KModal >
55
+ </div >
46
56
</template >
47
57
48
58
<script setup>
@@ -54,9 +64,11 @@ import bbox from '@turf/bbox'
54
64
import { Store , i18n } from ' ../../../../core/client'
55
65
import { KView } from ' ../../../../core/client/components'
56
66
import KLayerItem from ' ../catalog/KLayerItem.vue'
67
+ import KStyleEditor from ' ../styles/KStyleEditor.vue'
57
68
import { useCurrentActivity } from ' ../../composables/activity.js'
58
69
import { getFeatureId , getFeatureLabel } from ' ../../utils/utils.js'
59
70
import { isLayerDataEditable } from ' ../../utils/utils.layers.js'
71
+ import { getFeatureStyleType } from ' ../../utils/utils.features.js'
60
72
import { generatePropertiesSchema } from ' ../../utils/utils.schema.js'
61
73
62
74
// Props
@@ -73,8 +85,17 @@ const router = useRouter()
73
85
const { CurrentActivity } = useCurrentActivity ()
74
86
const expandedNodes = ref ([props .item .layer ._id ])
75
87
const editedFeatures = ref ([])
88
+ const editedFeature = ref (null )
89
+ const editedFeatureType = ref (null )
90
+ const editedFeatureStyle = ref (null )
76
91
77
92
// Computed
93
+ const isFeatureStyleEdited = computed (() => {
94
+ return ! _ .isNil (editedFeatureStyle .value )
95
+ })
96
+ const styleEditorTitle = computed (() => {
97
+ return (editedFeature .value ? getFeatureLabel (editedFeature .value , props .item .layer ) : ' ' )
98
+ })
78
99
const layerActions = computed (() => {
79
100
return [{
80
101
id: ' layer-actions' ,
@@ -134,6 +155,12 @@ const featureActions = computed(() => {
134
155
icon: ' las la-address-card' ,
135
156
handler: editSelectedFeatureProperties,
136
157
visible: isLayerDataEditable (props .item .layer ) && _ .get (props .item .layer , ' schema.content' )
158
+ }, {
159
+ id: ' edit-style-selected-feature' ,
160
+ label: ' KSelectedLayerFeatures.EDIT_FEATURE_STYLE_LABEL' ,
161
+ icon: ' las la-paint-brush' ,
162
+ handler: editSelectedFeatureStyle,
163
+ visible: isLayerDataEditable (props .item .layer )
137
164
}, {
138
165
id: ' reset-style-selected-feature' ,
139
166
label: ' KSelectedLayerFeatures.RESET_FEATURE_STYLE_LABEL' ,
@@ -259,11 +286,25 @@ function editSelectedFeatureProperties (feature) {
259
286
})
260
287
})
261
288
}
262
- function resetSelectedFeaturesStyle () {
263
- CurrentActivity .value .editFeaturesStyle ({ type: ' FeatureCollection' , features: props .item .features .map (feature => Object .assign (feature, { style: {} })) }, props .item .layer )
289
+ function editSelectedFeatureStyle (feature ) {
290
+ editedFeature .value = feature
291
+ editedFeatureType .value = getFeatureStyleType (feature)
292
+ editedFeatureStyle .value = { [editedFeatureType .value ]: _ .get (feature, ' style' , {}) }
293
+ }
294
+ function onCancelFeatureStyle () {
295
+ editedFeature .value = null
296
+ editedFeatureType .value = null
297
+ editedFeatureStyle .value = null
298
+ }
299
+ async function onApplyFeatureStyle (style ) {
300
+ await CurrentActivity .value .editFeaturesStyle (Object .assign (editedFeature .value , { style: style[editedFeatureType .value ] }), props .item .layer )
301
+ onCancelFeatureStyle ()
302
+ }
303
+ async function resetSelectedFeaturesStyle () {
304
+ await CurrentActivity .value .editFeaturesStyle ({ type: ' FeatureCollection' , features: props .item .features .map (feature => Object .assign (feature, { style: {} })) }, props .item .layer )
264
305
}
265
- function resetSelectedFeatureStyle (feature ) {
266
- CurrentActivity .value .editFeaturesStyle (Object .assign (feature, { style: {} }), props .item .layer )
306
+ async function resetSelectedFeatureStyle (feature ) {
307
+ await CurrentActivity .value .editFeaturesStyle (Object .assign (feature, { style: {} }), props .item .layer )
267
308
}
268
309
function removeSelectedFeatures () {
269
310
Dialog .create ({
0 commit comments