Skip to content

Commit bd51d07

Browse files
committed
wip: add apply style to layer button in style manager (#1072)
1 parent 6ae067b commit bd51d07

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

map/client/components/styles/KStyleEditor.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const emit = defineEmits([
117117
])
118118
119119
// Data
120-
const style = ref(_.assign({}, _.pick(DefaultStyle, ['point', 'line', 'polygon']), { name: '' }, props.style))
120+
const style = ref(_.assign({}, _.cloneDeep(_.pick(DefaultStyle, ['point', 'line', 'polygon']), { name: '' }, props.style)))
121121
const { CurrentActivity } = useCurrentActivity()
122122
123123
// Computed

map/client/components/styles/KStyleManager.vue

+26-7
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,30 @@
2626
avatar: false
2727
},
2828
actions: [
29+
{
30+
id: 'apply-to-layer',
31+
component: 'menu/KMenu',
32+
icon: 'las la-layer-group',
33+
tooltip: 'KStyleManager.APPLY_TO_LAYER',
34+
actionRenderer: 'item',
35+
content: layerMenuContent
36+
},
2937
{
3038
id: 'apply-to-selection',
31-
icon: 'las la-object-ungroup',
39+
icon: 'las la-object-group',
3240
tooltip: 'KStyleManager.APPLY_TO_SELECTION',
33-
scope: 'header',
3441
handler: applyToSelection
3542
},
3643
{
3744
id: 'edit-style',
3845
icon: 'las la-edit',
3946
tooltip: 'KStyleManager.EDIT',
40-
scope: 'header',
4147
handler: editStyle
4248
},
4349
{
4450
id: 'delete-style',
4551
icon: 'las la-trash',
4652
tooltip: 'KStyleManager.DELETE',
47-
scope: 'footer',
4853
handler: { name: 'removeItem', params: ['confirm'] }
4954
},
5055
],
@@ -63,11 +68,12 @@
6368
<script setup>
6469
import { computed, ref } from 'vue'
6570
import _ from 'lodash'
71+
import sift from 'sift'
6672
import { KGrid } from '../../../../core/client/components'
6773
import { Store, api } from '@kalisio/kdk/core.client'
6874
import KStyleEditor from './KStyleEditor.vue'
6975
import { useCurrentActivity } from '../../composables/activity.js'
70-
import { isLayerStyleEditable } from '../../utils/utils.layers.js'
76+
import { isLayerStyleEditable, editLayerStyle } from '../../utils/utils.layers.js'
7177
import { editFeaturesStyle } from '../../utils/utils.features.js'
7278
7379
// Props
@@ -79,11 +85,11 @@ defineProps({
7985
})
8086
8187
// Data
88+
const { getSelectedFeaturesByLayer, CurrentActivity } = useCurrentActivity()
8289
const filter = Store.get('filter')
8390
const styleEditor = ref(null)
8491
const style = ref(null)
8592
const viewMode = ref('list')
86-
const { getSelectedFeaturesByLayer } = useCurrentActivity()
8793
8894
// Computed
8995
const baseQuery = computed(() => {
@@ -121,8 +127,21 @@ const toolbar = computed(() => {
121127
}
122128
]
123129
})
130+
const layerMenuContent = computed(() => {
131+
const visibleLayers = CurrentActivity.value.getLayers().filter(sift({ isVisible: true, scope: 'user', _id: { $exists: true } }))
132+
return _.map(visibleLayers, layer => {
133+
return {
134+
id: layer._id,
135+
label: layer.name,
136+
handler: (styleToApply) => applyToLayer(layer, styleToApply.item)
137+
}
138+
})
139+
})
124140
125141
// Functions
142+
function applyToLayer (layer, styleToApply) {
143+
editLayerStyle(layer, styleToApply)
144+
}
126145
function applyToSelection (styleToApply) {
127146
const type = { Point: 'point', LineString: 'line', Polygon: 'polygon' }
128147
_.forEach(getSelectedFeaturesByLayer(), layer => {
@@ -134,7 +153,7 @@ function applyToSelection (styleToApply) {
134153
}
135154
function editStyle (styleToEdit) {
136155
viewMode.value = 'edit'
137-
style.value = _.get(styleToEdit, 'item', null)
156+
style.value = _.get(styleToEdit, 'item', {})
138157
}
139158
function onApply (style) {
140159
const service = api.getService('styles')

map/client/i18n/map_en.json

+1
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@
749749
},
750750
"KStyleManager": {
751751
"TITLE": "Style manager",
752+
"APPLY_TO_LAYER": "Apply style to layer",
752753
"APPLY_TO_SELECTION": "Apply style to selection",
753754
"EDIT": "Edit style",
754755
"DELETE": "Delete style",

map/client/i18n/map_fr.json

+1
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@
753753
},
754754
"KStyleManager": {
755755
"TITLE": "Gestionnaire de styles",
756+
"APPLY_TO_LAYER": "Appliquer le style à une couche",
756757
"APPLY_TO_SELECTION": "Appliquer le style à la sélection",
757758
"EDIT": "Modifier le style",
758759
"DELETE": "Supprimer le style",

map/client/utils/utils.layers.js

+8
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ export function isMeasureLayer (layer) {
341341
return layer.variables && layer.service
342342
}
343343

344+
export async function editLayerStyle (layer, style) {
345+
style = _.pick(style, ['point', 'line', 'polygon'])
346+
if (layer._id) {
347+
return await api.getService('catalog').patch(layer._id, { 'cesium.style': style, 'leaflet.style': style })
348+
}
349+
return layer
350+
}
351+
344352
export function generateLayerDefinition(layerSpec, geoJson){
345353
// Check wether the geoJson content is a valid geoJson
346354
if (geoJson.type !== 'FeatureCollection' && geoJson.type !== 'Feature') {

0 commit comments

Comments
 (0)