-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #533 from geoadmin/feat_BGDIINF_SB-3193_geoadmin_g…
…roup_of_layers BGDIINF_SB-3193 : topics are now group of layers
- Loading branch information
Showing
10 changed files
with
508 additions
and
561 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import GeoAdminLayer from '@/api/layers/GeoAdminLayer.class' | ||
import LayerTypes from '@/api/layers/LayerTypes.enum' | ||
|
||
/** | ||
* Description of a group of layers, or category of layers, in the context of the catalogue. This | ||
* group can't be added directly on the map, only its layer children can. | ||
* | ||
* This is used to describe categories in the topic navigation / representation. | ||
*/ | ||
export default class GeoAdminGroupOfLayers extends GeoAdminLayer { | ||
/** | ||
* @param {String} id Unique identifier of this group of layer | ||
* @param {String} name Name of this layer group, in the current i18n lang | ||
* @param {GeoAdminLayer[]} layers Description of the layers being part of this group | ||
*/ | ||
constructor(id, name, layers) { | ||
super(name, LayerTypes.GROUP, id, id) | ||
this.layers = [...layers] | ||
} | ||
|
||
clone() { | ||
let clone = super.clone() | ||
clone.layers = this.layers.map((layer) => layer.clone()) | ||
return clone | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script setup> | ||
import LayerCatalogueItem from '@/modules/menu/components/topics/LayerCatalogueItem.vue' | ||
import { defineProps } from 'vue' | ||
import { useStore } from 'vuex' | ||
const { layerCatalogue, compact } = defineProps({ | ||
layerCatalogue: { | ||
type: Array, | ||
required: true, | ||
}, | ||
compact: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}) | ||
const store = useStore() | ||
function clearPreviewLayer() { | ||
if (store.state.layers.previewLayer) { | ||
store.dispatch('clearPreviewLayer') | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="menu-topic-list" data-cy="menu-topic-tree" @mouseleave="clearPreviewLayer"> | ||
<LayerCatalogueItem | ||
v-for="item in layerCatalogue" | ||
:key="item.getID()" | ||
:item="item" | ||
:compact="compact" | ||
/> | ||
</div> | ||
</template> |
185 changes: 185 additions & 0 deletions
185
src/modules/menu/components/topics/LayerCatalogueItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
<script setup> | ||
/** | ||
* Node of a layer catalogue in the UI, rendering (and behavior) will differ if this is a group of | ||
* layers or a single layer. | ||
*/ | ||
import AbstractLayer from '@/api/layers/AbstractLayer.class' | ||
import GeoAdminGroupOfLayers from '@/api/layers/GeoAdminGroupOfLayers.class' | ||
import LayerLegendPopup from '@/modules/menu/components/LayerLegendPopup.vue' | ||
import { ActiveLayerConfig } from '@/utils/layerUtils' | ||
import { FontAwesomeIcon, FontAwesomeLayers } from '@fortawesome/vue-fontawesome' | ||
// importing directly the vue component, see https://github.com/ivanvermeyen/vue-collapse-transition/issues/5 | ||
import CollapseTransition from '@ivanv/vue-collapse-transition/src/CollapseTransition.vue' | ||
import { computed, defineProps, onMounted, ref, watch } from 'vue' | ||
import { useStore } from 'vuex' | ||
const { item, compact, depth } = defineProps({ | ||
item: { | ||
type: AbstractLayer, | ||
required: true, | ||
}, | ||
compact: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
depth: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
}) | ||
// Declaring own properties (ex-data) | ||
const showChildren = ref(false) | ||
const showLayerLegend = ref(false) | ||
// Mapping the store to the component | ||
const store = useStore() | ||
const activeLayers = computed(() => store.state.layers.activeLayers) | ||
const openThemesIds = computed(() => store.state.topics.openedTreeThemesIds) | ||
const hasChildren = computed(() => item?.layers?.length > 0) | ||
/** | ||
* Flag telling if this layer can be added to the map (so if the UI should include the necessary | ||
* element to do so) | ||
*/ | ||
const canBeAddedToTheMap = computed(() => { | ||
// only groups of layers from our backends can't be added to the map | ||
return item && !(item instanceof GeoAdminGroupOfLayers) | ||
}) | ||
const isPresentInActiveLayers = computed(() => | ||
activeLayers.value.find((layer) => layer.getID() === item.getID()) | ||
) | ||
const isCurrentlyHidden = computed( | ||
() => | ||
isPresentInActiveLayers.value && | ||
activeLayers.value.find((layer) => layer.getID() === item.getID() && !layer.visible) | ||
) | ||
// reacting to topic changes (some categories might need some auto-opening) | ||
watch(openThemesIds, (newValue) => { | ||
showChildren.value = showChildren.value || newValue.indexOf(item.getID()) !== -1 | ||
}) | ||
// reading the current topic at startup and opening any required category | ||
onMounted(() => { | ||
showChildren.value = openThemesIds.value.indexOf(item.getID()) !== -1 | ||
}) | ||
function startLayerPreview() { | ||
if (canBeAddedToTheMap.value) { | ||
store.dispatch('setPreviewLayer', item) | ||
} | ||
} | ||
function onItemClick() { | ||
if (hasChildren.value) { | ||
showChildren.value = !showChildren.value | ||
} else { | ||
const matchingActiveLayer = store.getters.getActiveLayerById(item.getID()) | ||
if (matchingActiveLayer) { | ||
store.dispatch('toggleLayerVisibility', matchingActiveLayer) | ||
} else { | ||
store.dispatch('addLayer', new ActiveLayerConfig(item.getID(), true)) | ||
} | ||
} | ||
} | ||
</script> | ||
<template> | ||
<div class="menu-topic-item" data-cy="topic-tree-item"> | ||
<div | ||
class="menu-topic-item-title" | ||
:class="{ group: hasChildren }" | ||
:data-cy="`topic-tree-item-${item.getID()}`" | ||
@click="onItemClick" | ||
@mouseenter="startLayerPreview" | ||
> | ||
<button | ||
class="btn d-flex align-items-center" | ||
:class="{ | ||
'text-danger': isPresentInActiveLayers || isCurrentlyHidden, | ||
'btn-lg': !compact, | ||
'btn-rounded': hasChildren, | ||
}" | ||
> | ||
<FontAwesomeLayers v-if="hasChildren"> | ||
<FontAwesomeIcon class="text-secondary" icon="fa-regular fa-circle" /> | ||
<FontAwesomeIcon size="xs" :icon="showChildren ? 'minus' : 'plus'" /> | ||
</FontAwesomeLayers> | ||
<FontAwesomeIcon | ||
v-if="canBeAddedToTheMap" | ||
:class="{ | ||
'ms-1': hasChildren, | ||
}" | ||
:icon="`far ${ | ||
isPresentInActiveLayers && !isCurrentlyHidden | ||
? 'fa-check-square' | ||
: 'fa-square' | ||
}`" | ||
/> | ||
</button> | ||
<span class="menu-topic-item-name">{{ item.name }}</span> | ||
<button | ||
v-if="canBeAddedToTheMap" | ||
class="btn" | ||
:class="{ 'btn-lg': !compact }" | ||
data-cy="topic-tree-item-info" | ||
@click.stop="showLayerLegend = true" | ||
> | ||
<FontAwesomeIcon icon="info-circle" /> | ||
</button> | ||
</div> | ||
<CollapseTransition :duration="200"> | ||
<ul | ||
v-show="showChildren" | ||
class="menu-topic-item-children" | ||
:class="`ps-${2 + 2 * depth}`" | ||
> | ||
<LayerCatalogueItem | ||
v-for="child in item.layers" | ||
:key="`${child.getID()}`" | ||
:item="child" | ||
:depth="depth + 1" | ||
:compact="compact" | ||
/> | ||
</ul> | ||
</CollapseTransition> | ||
<LayerLegendPopup | ||
v-if="showLayerLegend" | ||
:layer-id="item.getID()" | ||
@close="showLayerLegend = false" | ||
/> | ||
</div> | ||
</template> | ||
<style lang="scss" scoped> | ||
@import 'src/scss/webmapviewer-bootstrap-theme'; | ||
@import 'src/modules/menu/scss/menu-items'; | ||
.menu-topic-item { | ||
border-bottom: none; | ||
&-title { | ||
@extend .menu-title; | ||
cursor: pointer; | ||
&.active { | ||
color: $primary; | ||
} | ||
border-bottom-width: 1px; | ||
border-bottom-color: $gray-400; | ||
&.group { | ||
border-bottom-style: solid; | ||
} | ||
&:not(.group) { | ||
border-bottom-style: dashed; | ||
} | ||
} | ||
} | ||
.menu-topic-item-name { | ||
@extend .menu-name; | ||
} | ||
.menu-topic-item-children { | ||
@extend .menu-list; | ||
} | ||
</style> |
Oops, something went wrong.