Skip to content

Commit 1fb4418

Browse files
committed
feat: create a style manager - apply to in memory layers (#1072)
1 parent 2e5eb2a commit 1fb4418

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

map/client/components/selection/KSelectedLayerFeatures.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</template>
3737
<!-- Feature properties rendering -->
3838
<template v-slot:default-body="prop">
39-
<KView v-if="isFeaturePropertiesNode(prop.node)"
39+
<KView v-if="isFeaturePropertiesNode(prop.node)"
4040
class="q-pa-md full-width"
4141
:values="prop.node"
4242
:schema="schema"
@@ -118,7 +118,7 @@ const layerActions = computed(() => {
118118
}, {
119119
id: 'reset-style-selected-features',
120120
label: 'KSelectedLayerFeatures.RESET_FEATURES_STYLE_LABEL',
121-
icon: 'las la-paint-brush',
121+
icon: 'las la-ban',
122122
handler: resetSelectedFeaturesStyle,
123123
visible: isLayerDataEditable(props.item.layer)
124124
}, {
@@ -164,7 +164,7 @@ const featureActions = computed(() => {
164164
}, {
165165
id: 'reset-style-selected-feature',
166166
label: 'KSelectedLayerFeatures.RESET_FEATURE_STYLE_LABEL',
167-
icon: 'las la-paint-brush',
167+
icon: 'las la-ban',
168168
handler: resetSelectedFeatureStyle,
169169
visible: isLayerDataEditable(props.item.layer)
170170
}, {
@@ -200,11 +200,11 @@ const root = computed(() => {
200200
label: getLabel(feature.properties)
201201
}, feature.properties)] // Properties only for node displaying it
202202
}, feature)) // Target feature is required as context for actions
203-
// For each feature add a node containing
203+
// For each feature add a node containing
204204
// Replace default layer actions with new ones
205205
return Object.assign({
206206
icon: getIcon(props.item.layer),
207-
label: getLabel(props.item.layer),
207+
label: getLabel(props.item.layer)
208208
}, _.omit(props.item.layer, ['icon', 'actions']), { actions: layerActions.value, children })
209209
})
210210

map/client/components/styles/KStyleManager.vue

+7-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import { computed, ref } from 'vue'
7070
import _ from 'lodash'
7171
import sift from 'sift'
7272
import { KGrid } from '../../../../core/client/components'
73-
import { Filter, Sorter, Store, api } from '@kalisio/kdk/core.client'
73+
import { Filter, Sorter, api } from '@kalisio/kdk/core.client'
7474
import KStyleEditor from './KStyleEditor.vue'
7575
import { useCurrentActivity } from '../../composables/activity.js'
7676
import { isLayerStyleEditable, editLayerStyle } from '../../utils/utils.layers.js'
@@ -121,7 +121,7 @@ const toolbar = computed(() => {
121121
]
122122
})
123123
const layerMenuContent = computed(() => {
124-
const visibleLayers = CurrentActivity.value.getLayers().filter(sift({ isVisible: true, scope: 'user', _id: { $exists: true } }))
124+
const visibleLayers = CurrentActivity.value.getLayers().filter(sift({ isVisible: true, scope: 'user' }))
125125
return _.map(visibleLayers, layer => {
126126
return {
127127
id: layer._id,
@@ -132,8 +132,11 @@ const layerMenuContent = computed(() => {
132132
})
133133
134134
// Functions
135-
function applyToLayer (layer, styleToApply) {
136-
editLayerStyle(layer, styleToApply)
135+
async function applyToLayer (layer, styleToApply) {
136+
await editLayerStyle(layer, styleToApply)
137+
if (!layer._id) {
138+
await CurrentActivity.value.resetLayer(layer)
139+
}
137140
}
138141
function applyToSelection (styleToApply) {
139142
const type = { Point: 'point', LineString: 'line', Polygon: 'polygon' }

map/client/i18n/map_en.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"ADD_LAYER": "Add a layer",
5353
"EDIT_LABEL": "Edit properties",
5454
"EDIT_LAYER_STYLE_LABEL": "Edit style",
55+
"RESET_LAYER_STYLE_LABEL": "Reset style",
5556
"FILTER_DATA_LABEL": "Filter data",
5657
"VIEW_DATA_LABEL": "View data",
5758
"CHART_DATA_LABEL": "Chart data",

map/client/i18n/map_fr.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"ADD_LAYER": "Ajouter une couche",
5353
"EDIT_LABEL": "Editer les propriétés",
5454
"EDIT_LAYER_STYLE_LABEL": "Editer le style",
55+
"RESET_LAYER_STYLE_LABEL": "Réinitialiser le style",
5556
"FILTER_DATA_LABEL": "Filtrer les données",
5657
"VIEW_DATA_LABEL": "Voir les données",
5758
"CHART_DATA_LABEL": "Graphique des données",

map/client/mixins/mixin.activity.js

+10
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,16 @@ export const activity = {
131131
isLayerStyleEditable: layers.isLayerStyleEditable,
132132
isLayerDataEditable: layers.isLayerDataEditable,
133133
async resetLayer (layer) {
134+
// Keep track of data as we will reset the layer
135+
let geoJson
136+
if (typeof this.toGeoJson === 'function') geoJson = await this.toGeoJson(layer.name)
134137
// Reset layer with new setup but keep track of current visibility state
135138
// as adding the layer back will restore default visibility state
136139
const isVisible = this.isLayerVisible(layer.name)
137140
await this.removeLayer(layer.name)
138141
await this.addLayer(layer)
139142
if (isVisible) await this.showLayer(layer.name)
143+
if (geoJson && (typeof this.toGeoJson === 'function')) this.updateLayer(layer.name, geoJson)
140144
},
141145
configureLayerActions (layer) {
142146
let actions = _.get(this, 'activityOptions.layers.actions', [])
@@ -222,6 +226,12 @@ export const activity = {
222226
// this one can be triggered from a toolbar to accept or reject changes
223227
await this.stopEditLayer(status)
224228
},
229+
async onResetLayerStyle (layer) {
230+
await layers.editLayerStyle(layer, {})
231+
if (!layer._id) {
232+
await this.resetLayer(layer)
233+
}
234+
},
225235
async onRemoveLayer (layer) {
226236
// Stop any running edition
227237
if ((typeof this.isLayerEdited === 'function') && this.isLayerEdited(layer)) await this.stopEditLayer('reject')

map/client/utils/utils.layers.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ export function isMeasureLayer (layer) {
344344
export async function editLayerStyle (layer, style) {
345345
style = _.pick(style, ['point', 'line', 'polygon'])
346346
if (layer._id) {
347-
return await api.getService('catalog').patch(layer._id, { 'cesium.style': style, 'leaflet.style': style })
347+
await api.getService('catalog').patch(layer._id, { 'cesium.style': style, 'leaflet.style': style })
348+
} else {
349+
_.set(layer, 'cesium.style', style)
350+
_.set(layer, 'leaflet.style', style)
348351
}
349352
return layer
350353
}

0 commit comments

Comments
 (0)