20
20
<KStyleEditorSection
21
21
v-if =" canEditPoint"
22
22
label =" KStyleEditor.POINT_SECTION"
23
- :style =" style "
23
+ :style =" model "
24
24
type =" point"
25
25
:dense =" dense"
26
26
>
27
- <KStyleProperty v-model =" style .point.color" :name =" $t('KStyleEditor.COLOR')" type =" color" :dense =" dense" />
28
- <KStyleProperty v-model =" style .point.size" :name =" $t('KStyleEditor.SIZE')" type =" size" :min =" 8" :max =" 64" :dense =" dense" />
29
- <KStyleProperty v-model =" style .point.opacity" :name =" $t('KStyleEditor.OPACITY')" type =" opacity" :dense =" dense" />
30
- <KStyleProperty v-model =" style .point.shape" :name =" $t('KStyleEditor.SHAPE')" type =" shape" :dense =" dense" />
27
+ <KStyleProperty v-model =" model .point.color" :name =" $t('KStyleEditor.COLOR')" type =" color" :default = " getDefaultValue('point.color') " :dense =" dense" />
28
+ <KStyleProperty v-model =" model .point.size" :name =" $t('KStyleEditor.SIZE')" type =" size" :min =" 8" :max =" 64" :default = " getDefaultValue('point.size') " :dense =" dense" />
29
+ <KStyleProperty v-model =" model .point.opacity" :name =" $t('KStyleEditor.OPACITY')" type =" opacity" :default = " getDefaultValue('point.opacity') " :dense =" dense" />
30
+ <KStyleProperty v-model =" model .point.shape" :name =" $t('KStyleEditor.SHAPE')" type =" shape" :default = " getDefaultValue('point.shape') " :dense =" dense" />
31
31
<KStylePropertiesGroup
32
32
v-if =" !is3D"
33
33
label =" KStyleEditor.ICON_GROUP"
34
- v-model =" style .point.icon"
34
+ v-model =" model .point.icon"
35
35
:properties =" pointIconProperties"
36
36
:dense =" dense"
37
37
/>
38
38
<KStylePropertiesGroup
39
39
label =" KStyleEditor.STROKE_GROUP"
40
- v-model =" style .point.stroke"
40
+ v-model =" model .point.stroke"
41
41
:properties =" pointStrokeProperties"
42
42
:dense =" dense"
43
43
/>
46
46
<KStyleEditorSection
47
47
v-if =" canEditLine"
48
48
label =" KStyleEditor.LINE_SECTION"
49
- :style =" style "
49
+ :style =" model "
50
50
type =" line"
51
51
:dense =" dense"
52
52
>
53
- <KStyleProperty v-model =" style .line.color" :name =" $t('KStyleEditor.COLOR')" type =" color" :dense =" dense" />
54
- <KStyleProperty v-model =" style .line.width" :name =" $t('KStyleEditor.SIZE')" type =" size" :min =" 1" :max =" 12" :dense =" dense" />
55
- <KStyleProperty v-model =" style .line.opacity" :name =" $t('KStyleEditor.OPACITY')" type =" opacity" :dense =" dense" />
53
+ <KStyleProperty v-model =" model .line.color" :name =" $t('KStyleEditor.COLOR')" type =" color" :default = " getDefaultValue('line.color') " :dense =" dense" />
54
+ <KStyleProperty v-model =" model .line.width" :name =" $t('KStyleEditor.SIZE')" type =" size" :min =" 1" :max =" 12" :default = " getDefaultValue('line.width') " :dense =" dense" />
55
+ <KStyleProperty v-model =" model .line.opacity" :name =" $t('KStyleEditor.OPACITY')" type =" opacity" :default = " getDefaultValue('line.opacity') " :dense =" dense" />
56
56
</KStyleEditorSection >
57
57
<!-- Polygon editor -->
58
58
<KStyleEditorSection
59
59
v-if =" canEditPolygon"
60
60
label =" KStyleEditor.POLYGON_SECTION"
61
- :style =" style "
61
+ :style =" model "
62
62
type =" polygon"
63
63
:dense =" dense"
64
64
>
65
- <KStyleProperty v-model =" style .polygon.color" :name =" $t('KStyleEditor.FILL_COLOR')" type =" color" :dense =" dense" />
66
- <KStyleProperty v-model =" style .polygon.opacity" :name =" $t('KStyleEditor.FILL_OPACITY')" type =" opacity" :dense =" dense" />
65
+ <KStyleProperty v-model =" model .polygon.color" :name =" $t('KStyleEditor.FILL_COLOR')" type =" color" :default = " getDefaultValue('polygon.color') " :dense =" dense" />
66
+ <KStyleProperty v-model =" model .polygon.opacity" :name =" $t('KStyleEditor.FILL_OPACITY')" type =" opacity" :default = " getDefaultValue('polygon.opacity') " :dense =" dense" />
67
67
<KStylePropertiesGroup
68
68
label =" KStyleEditor.STROKE_GROUP"
69
- v-model =" style .polygon.stroke"
69
+ v-model =" model .polygon.stroke"
70
70
:properties =" polygonStrokeProperties"
71
71
:dense =" dense"
72
72
/>
85
85
86
86
<script setup>
87
87
import _ from ' lodash'
88
+ import config from ' config'
88
89
import logger from ' loglevel'
89
90
import { ref , computed , watch } from ' vue'
90
91
import { api , i18n , utils as kdkCoreUtils } from ' @kalisio/kdk/core.client'
92
+ import { useCurrentActivity } from ' ../../composables'
91
93
import KPanel from ' ../../../../core/client/components/KPanel.vue'
92
94
import KStyleEditorSection from ' ./KStyleEditorSection.vue'
93
95
import KStylePropertiesGroup from ' ./KStylePropertiesGroup.vue'
@@ -100,14 +102,6 @@ const props = defineProps({
100
102
type: Object ,
101
103
default : () => null
102
104
},
103
- default: {
104
- type: Object ,
105
- default : () => null
106
- },
107
- is3D: {
108
- type: Boolean ,
109
- default: false
110
- },
111
105
title: {
112
106
type: String ,
113
107
default: ' '
@@ -120,7 +114,7 @@ const props = defineProps({
120
114
type: Array ,
121
115
default: null
122
116
},
123
- allowedStyles : {
117
+ allowedTypes : {
124
118
type: Array ,
125
119
default: [' point' , ' line' , ' polygon' ]
126
120
},
@@ -134,8 +128,9 @@ const props = defineProps({
134
128
const emit = defineEmits ([' applied' , ' canceled' ])
135
129
136
130
// Data
131
+ const { CurrentActivityContext } = useCurrentActivity ()
137
132
const formRef = ref (null )
138
- const style = ref (null )
133
+ const model = ref (null )
139
134
const mode = props .style ? ' edition' : ' creation'
140
135
const formSchema = {
141
136
$schema: ' http://json-schema.org/draft-07/schema#' ,
@@ -160,27 +155,33 @@ const formValues = computed(() => {
160
155
if (_ .isEmpty (props .style )) return null
161
156
return { name: _ .get (props .style , ' name' ) }
162
157
})
158
+ const engine = computed (() => {
159
+ return _ .get (CurrentActivityContext .config , ' engine' , _ .get (config, ' engines.leaflet' ))
160
+ })
161
+ const is3D = computed (() => {
162
+ return engine .value === ' cesium'
163
+ })
163
164
const defaultStyle = computed (() => {
164
- return _ .defaultsDeep ( props . default , DefaultStyle )
165
+ return _ .merge (DefaultStyle, engine . value . style )
165
166
})
166
167
const pointStrokeProperties = computed (() => {
167
168
return [
168
- { name: ' color' , label: ' KStyleEditor.STROKE_COLOR' , type: ' color' , default: defaultStyle . value . point .stroke .color },
169
- { name: ' width' , label: ' KStyleEditor.STROKE_WIDTH' , type: ' size' , min: 1 , max: 12 , default: defaultStyle . value . point .stroke .width },
170
- { name: ' opacity' , label: ' KStyleEditor.STROKE_OPACITY' , type: ' opacity' , default: defaultStyle . value . point .stroke .opacity }
169
+ { name: ' color' , label: ' KStyleEditor.STROKE_COLOR' , type: ' color' , default: getDefaultValue ( ' point.stroke.color' ) },
170
+ { name: ' width' , label: ' KStyleEditor.STROKE_WIDTH' , type: ' size' , min: 1 , max: 12 , default: getDefaultValue ( ' point.stroke.width' ) },
171
+ { name: ' opacity' , label: ' KStyleEditor.STROKE_OPACITY' , type: ' opacity' , default: getDefaultValue ( ' point.stroke.opacity' ) }
171
172
]
172
173
})
173
174
const pointIconProperties = computed (() => {
174
175
return [
175
- { name: ' classes' , label: ' KStyleEditor.ICON' , type: ' icon' , default: defaultStyle . value . point .icon .classes },
176
- { name: ' size' , label: ' KStyleEditor.ICON_SIZE' , type: ' size' , min: 8 , max: 48 , default: defaultStyle . value . point .icon .size }
176
+ { name: ' classes' , label: ' KStyleEditor.ICON' , type: ' icon' , default: getDefaultValue ( ' point.icon.classes' ) },
177
+ { name: ' size' , label: ' KStyleEditor.ICON_SIZE' , type: ' size' , min: 8 , max: 48 , default: getDefaultValue ( ' point.icon.size' ) }
177
178
]
178
179
})
179
180
const polygonStrokeProperties = computed (() => {
180
181
return [
181
- { name: ' color' , label: ' KStyleEditor.STROKE_COLOR' , type: ' color' , default: defaultStyle . value . polygon .stroke .color },
182
- { name: ' width' , label: ' KStyleEditor.STROKE_WIDTH' , type: ' size' , min: 1 , max: 12 , default: defaultStyle . value . polygon .stroke .width },
183
- { name: ' opacity' , label: ' KStyleEditor.STROKE_OPACITY' , type: ' opacity' , default: defaultStyle . value . polygon .stroke .opacity }
182
+ { name: ' color' , label: ' KStyleEditor.STROKE_COLOR' , type: ' color' , default: getDefaultValue ( ' polygon.stroke.color' ) },
183
+ { name: ' width' , label: ' KStyleEditor.STROKE_WIDTH' , type: ' size' , min: 1 , max: 12 , default: getDefaultValue ( ' polygon.stroke.width' ) },
184
+ { name: ' opacity' , label: ' KStyleEditor.STROKE_OPACITY' , type: ' opacity' , default: getDefaultValue ( ' polygon.stroke.opacity' ) }
184
185
]
185
186
})
186
187
const buttons = computed (() => {
@@ -201,16 +202,20 @@ const buttons = computed(() => {
201
202
}
202
203
]
203
204
})
204
- const canEditPoint = computed (() => props .allowedStyles .includes (' point' ))
205
- const canEditLine = computed (() => props .allowedStyles .includes (' line' ))
206
- const canEditPolygon = computed (() => props .allowedStyles .includes (' polygon' ))
205
+ const canEditPoint = computed (() => props .allowedTypes .includes (' point' ))
206
+ const canEditLine = computed (() => props .allowedTypes .includes (' line' ))
207
+ const canEditPolygon = computed (() => props .allowedTypes .includes (' polygon' ))
207
208
208
209
// Watch
209
210
watch (() => props .style , (value ) => {
210
- style .value = value
211
+ if (! value) model .value = engine .value .style
212
+ else model .value = value
211
213
}, { immediate: true })
212
214
213
215
// Functions
216
+ function getDefaultValue (path ) {
217
+ return _ .get (engine .value .style , path, _ .get (DefaultStyle, path))
218
+ }
214
219
const onNameChanged = _ .debounce (async (field , value ) => {
215
220
if (_ .size (value) > 2 ) await checkName (value)
216
221
}, 200 )
@@ -230,13 +235,11 @@ async function apply () {
230
235
const isUnique = await checkName (values .name )
231
236
if (! isUnique) return false
232
237
// create to patch the style
233
- let data
238
+ const data = _ . merge ( model . value , values)
234
239
if (mode === ' creation' ) {
235
- data = _ .merge (style .value , values)
236
240
logger .debug (' [KDK] Create style with values:' , data)
237
241
await service .create (data)
238
242
} else {
239
- data = _ .merge (style .value , values)
240
243
logger .debug (` [KDK] Patch style ${ style ._id } with values:` , data)
241
244
await service .patch (style .value ._id , data)
242
245
}
0 commit comments