diff --git a/src/components/draw/draw-panel-features.vue b/src/components/draw/draw-panel-features.vue index 49d28657..bc303ad2 100644 --- a/src/components/draw/draw-panel-features.vue +++ b/src/components/draw/draw-panel-features.vue @@ -28,8 +28,15 @@ function onToggleFeatureEdit(featureId: String, isEditing: boolean) { // TODO: continue... } +function sortFunction(elements: HTMLCollection) { + const featureIds = [...elements].map(val => val.id) + drawStore.reorderFeatures(featureIds) +} + onMounted(() => { - useSortable(document.querySelector('.sortable-features')) + useSortable(document.querySelector('.sortable-features'), { + onSort: sortFunction, + }) }) @@ -38,6 +45,7 @@ onMounted(() => {
  • !feature.map_id) + .sort((a, b) => a.display_order - b.display_order) .map(feature => { - const newFeature = new DrawnFeature(feature) //create new instance to avoid converting ol feature to polygon - // newFeature.set('name', newFeature.label) //is this still needed? + const newFeature = new DrawnFeature(feature) // create new instance to avoid converting ol feature to polygon return convertCircleFeatureToPolygon(newFeature) }) return featuresToEncode.length > 0 diff --git a/src/stores/draw.store.ts b/src/stores/draw.store.ts index 24c68e52..102acbfd 100644 --- a/src/stores/draw.store.ts +++ b/src/stores/draw.store.ts @@ -82,6 +82,12 @@ export const useDrawStore = defineStore('draw', () => { } } + function reorderFeatures(featuresId: String[]) { + drawnFeatures.value = drawnFeatures.value.map(f => + Object.assign(f, { display_order: featuresId.indexOf(`f-${getUid(f)}`) }) + ) + } + return { activeFeatureId, editingFeatureId, @@ -90,6 +96,7 @@ export const useDrawStore = defineStore('draw', () => { drawnFeatures, featureEditionDocked, removeFeature, + reorderFeatures, toggleDrawActiveState, setDrawActiveState, setEditActiveState,