Skip to content

Commit

Permalink
feat: create a style manager - apply to in memory layers (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed Feb 21, 2025
1 parent 2e5eb2a commit 1fb4418
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
10 changes: 5 additions & 5 deletions map/client/components/selection/KSelectedLayerFeatures.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</template>
<!-- Feature properties rendering -->
<template v-slot:default-body="prop">
<KView v-if="isFeaturePropertiesNode(prop.node)"
<KView v-if="isFeaturePropertiesNode(prop.node)"
class="q-pa-md full-width"
:values="prop.node"
:schema="schema"
Expand Down Expand Up @@ -118,7 +118,7 @@ const layerActions = computed(() => {
}, {
id: 'reset-style-selected-features',
label: 'KSelectedLayerFeatures.RESET_FEATURES_STYLE_LABEL',
icon: 'las la-paint-brush',
icon: 'las la-ban',
handler: resetSelectedFeaturesStyle,
visible: isLayerDataEditable(props.item.layer)
}, {
Expand Down Expand Up @@ -164,7 +164,7 @@ const featureActions = computed(() => {
}, {
id: 'reset-style-selected-feature',
label: 'KSelectedLayerFeatures.RESET_FEATURE_STYLE_LABEL',
icon: 'las la-paint-brush',
icon: 'las la-ban',
handler: resetSelectedFeatureStyle,
visible: isLayerDataEditable(props.item.layer)
}, {
Expand Down Expand Up @@ -200,11 +200,11 @@ const root = computed(() => {
label: getLabel(feature.properties)
}, feature.properties)] // Properties only for node displaying it
}, feature)) // Target feature is required as context for actions
// For each feature add a node containing
// For each feature add a node containing
// Replace default layer actions with new ones
return Object.assign({
icon: getIcon(props.item.layer),
label: getLabel(props.item.layer),
label: getLabel(props.item.layer)
}, _.omit(props.item.layer, ['icon', 'actions']), { actions: layerActions.value, children })
})
Expand Down
11 changes: 7 additions & 4 deletions map/client/components/styles/KStyleManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { computed, ref } from 'vue'
import _ from 'lodash'
import sift from 'sift'
import { KGrid } from '../../../../core/client/components'
import { Filter, Sorter, Store, api } from '@kalisio/kdk/core.client'
import { Filter, Sorter, api } from '@kalisio/kdk/core.client'
import KStyleEditor from './KStyleEditor.vue'
import { useCurrentActivity } from '../../composables/activity.js'
import { isLayerStyleEditable, editLayerStyle } from '../../utils/utils.layers.js'
Expand Down Expand Up @@ -121,7 +121,7 @@ const toolbar = computed(() => {
]
})
const layerMenuContent = computed(() => {
const visibleLayers = CurrentActivity.value.getLayers().filter(sift({ isVisible: true, scope: 'user', _id: { $exists: true } }))
const visibleLayers = CurrentActivity.value.getLayers().filter(sift({ isVisible: true, scope: 'user' }))
return _.map(visibleLayers, layer => {
return {
id: layer._id,
Expand All @@ -132,8 +132,11 @@ const layerMenuContent = computed(() => {
})
// Functions
function applyToLayer (layer, styleToApply) {
editLayerStyle(layer, styleToApply)
async function applyToLayer (layer, styleToApply) {
await editLayerStyle(layer, styleToApply)
if (!layer._id) {
await CurrentActivity.value.resetLayer(layer)
}
}
function applyToSelection (styleToApply) {
const type = { Point: 'point', LineString: 'line', Polygon: 'polygon' }
Expand Down
1 change: 1 addition & 0 deletions map/client/i18n/map_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"ADD_LAYER": "Add a layer",
"EDIT_LABEL": "Edit properties",
"EDIT_LAYER_STYLE_LABEL": "Edit style",
"RESET_LAYER_STYLE_LABEL": "Reset style",
"FILTER_DATA_LABEL": "Filter data",
"VIEW_DATA_LABEL": "View data",
"CHART_DATA_LABEL": "Chart data",
Expand Down
1 change: 1 addition & 0 deletions map/client/i18n/map_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"ADD_LAYER": "Ajouter une couche",
"EDIT_LABEL": "Editer les propriétés",
"EDIT_LAYER_STYLE_LABEL": "Editer le style",
"RESET_LAYER_STYLE_LABEL": "Réinitialiser le style",
"FILTER_DATA_LABEL": "Filtrer les données",
"VIEW_DATA_LABEL": "Voir les données",
"CHART_DATA_LABEL": "Graphique des données",
Expand Down
10 changes: 10 additions & 0 deletions map/client/mixins/mixin.activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,16 @@ export const activity = {
isLayerStyleEditable: layers.isLayerStyleEditable,
isLayerDataEditable: layers.isLayerDataEditable,
async resetLayer (layer) {
// Keep track of data as we will reset the layer
let geoJson
if (typeof this.toGeoJson === 'function') geoJson = await this.toGeoJson(layer.name)
// Reset layer with new setup but keep track of current visibility state
// as adding the layer back will restore default visibility state
const isVisible = this.isLayerVisible(layer.name)
await this.removeLayer(layer.name)
await this.addLayer(layer)
if (isVisible) await this.showLayer(layer.name)
if (geoJson && (typeof this.toGeoJson === 'function')) this.updateLayer(layer.name, geoJson)
},
configureLayerActions (layer) {
let actions = _.get(this, 'activityOptions.layers.actions', [])
Expand Down Expand Up @@ -222,6 +226,12 @@ export const activity = {
// this one can be triggered from a toolbar to accept or reject changes
await this.stopEditLayer(status)
},
async onResetLayerStyle (layer) {
await layers.editLayerStyle(layer, {})
if (!layer._id) {
await this.resetLayer(layer)
}
},
async onRemoveLayer (layer) {
// Stop any running edition
if ((typeof this.isLayerEdited === 'function') && this.isLayerEdited(layer)) await this.stopEditLayer('reject')
Expand Down
5 changes: 4 additions & 1 deletion map/client/utils/utils.layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ export function isMeasureLayer (layer) {
export async function editLayerStyle (layer, style) {
style = _.pick(style, ['point', 'line', 'polygon'])
if (layer._id) {
return await api.getService('catalog').patch(layer._id, { 'cesium.style': style, 'leaflet.style': style })
await api.getService('catalog').patch(layer._id, { 'cesium.style': style, 'leaflet.style': style })
} else {
_.set(layer, 'cesium.style', style)
_.set(layer, 'leaflet.style', style)
}
return layer
}
Expand Down

0 comments on commit 1fb4418

Please sign in to comment.