Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User settings: added switch to turn location names on and off #909

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions src/assets/DefaultUserSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,52 @@
"group": "UI"
},
{
"id": "ui.map.theme",
"id": "ui.hierarchical-menu-style",
"type": "oneOfMultiple",
"label": "Basemap",
"value": "carto-db-automatic",
"label": "Menu style",
"value": "auto",
"items": [
{
"value": "carto-db-automatic",
"icon": "mdi-theme-light-dark"
"value": "auto",
"icon": "mdi-responsive"
},
{
"value": "carto-db-light",
"icon": "mdi-weather-sunny"
"value": "tree",
"icon": "mdi-file-tree"
},
{
"value": "carto-dark-matter",
"icon": "mdi-weather-night"
"value": "column",
"icon": "mdi-view-week"
}
],
"group": "UI"
},
{
"id": "ui.hierarchical-menu-style",
"id": "ui.map.theme",
"type": "oneOfMultiple",
"label": "Menu style",
"value": "auto",
"label": "Basemap",
"value": "carto-db-automatic",
"items": [
{
"value": "auto",
"icon": "mdi-responsive"
"value": "carto-db-automatic",
"icon": "mdi-theme-light-dark"
},
{
"value": "tree",
"icon": "mdi-file-tree"
"value": "carto-db-light",
"icon": "mdi-weather-sunny"
},
{
"value": "column",
"icon": "mdi-view-week"
"value": "carto-dark-matter",
"icon": "mdi-weather-night"
}
],
"group": "UI"
"group": "Map"
},
{
"id": "ui.map.showLocationNames",
"type": "boolean",
"label": "Show location names",
"value": true,
"group": "Map"
}
]
74 changes: 40 additions & 34 deletions src/components/wms/LocationsLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:paint="paintCircleSpecification"
/>
<mgl-symbol-layer
v-if="showNames"
:layer-id="locationsTextLayerId"
:layout="layoutTextSpecification"
:paint="paintTextSpecification"
Expand All @@ -38,6 +39,11 @@ import { watch, onBeforeUnmount, computed } from 'vue'
import { onBeforeMount } from 'vue'
import { addLocationIconsToMap } from '@/lib/location-icons'
import { useDark } from '@vueuse/core'
import { useUserSettingsStore } from '@/stores/userSettings'

const settings = useUserSettingsStore()
const isDark = useDark()
const { map } = useMap()

interface Props {
locationsGeoJson: FeatureCollection<Geometry, Location>
Expand All @@ -54,8 +60,6 @@ const props = withDefaults(defineProps<Props>(), {

const emit = defineEmits(['click'])

const isDark = useDark()

const layoutSymbolSpecification = {
'icon-allow-overlap': true,
'symbol-sort-key': 1,
Expand Down Expand Up @@ -92,8 +96,6 @@ const paintCircleSpecification = {
'circle-stroke-width': 1.5,
}

const { map } = useMap()

const locationsCircleLayerId = 'location-circle-layer'
const locationsSymbolLayerId = 'location-symbol-layer'
const locationsTextLayerId = 'location-text-layer'
Expand All @@ -106,6 +108,40 @@ watch(
},
)

watch(
() => props.selectedLocationId,
() => {
highlightSelectedLocationOnMap()
},
)

onBeforeMount(() => {
if (map) {
for (const layerId of [locationsCircleLayerId, locationsSymbolLayerId]) {
map.on('click', layerId, clickHandler)
map.on('mouseenter', layerId, setCursorPointer)
map.on('mouseleave', layerId, unsetCursorPointer)
}
map.on('sourcedata', sourceDateLoaded)
}
addLocationIcons()
})

onBeforeUnmount(() => {
if (map) {
for (const layerId of [locationsCircleLayerId, locationsSymbolLayerId]) {
map.off('click', layerId, clickHandler)
map.off('mouseenter', layerId, setCursorPointer)
map.off('mouseleave', layerId, unsetCursorPointer)
}
map.off('sourcedata', sourceDateLoaded)
}
})

const showNames = computed(() => {
return settings.get('ui.map.showLocationNames')?.value
})

function addLocationIcons() {
if (map) addLocationIconsToMap(map, props.locationsGeoJson)
}
Expand Down Expand Up @@ -134,36 +170,6 @@ function sourceDateLoaded(e: MapSourceDataEvent) {
}
}

onBeforeMount(() => {
if (map) {
for (const layerId of [locationsCircleLayerId, locationsSymbolLayerId]) {
map.on('click', layerId, clickHandler)
map.on('mouseenter', layerId, setCursorPointer)
map.on('mouseleave', layerId, unsetCursorPointer)
}
map.on('sourcedata', sourceDateLoaded)
}
addLocationIcons()
})

onBeforeUnmount(() => {
if (map) {
for (const layerId of [locationsCircleLayerId, locationsSymbolLayerId]) {
map.off('click', layerId, clickHandler)
map.off('mouseenter', layerId, setCursorPointer)
map.off('mouseleave', layerId, unsetCursorPointer)
}
map.off('sourcedata', sourceDateLoaded)
}
})

watch(
() => props.selectedLocationId,
() => {
highlightSelectedLocationOnMap()
},
)

function highlightSelectedLocationOnMap() {
if (!map?.getSource(locationsSourceId)) return
const locationId = props.selectedLocationId ?? 'noLayerSelected'
Expand Down
2 changes: 1 addition & 1 deletion src/stores/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const parameterGroupKey = 'units.parameterGroup.'
export const useUserSettingsStore = defineStore({
id: 'userSettings',
state: (): UserSettingsState => ({
groups: ['Units', 'Datum', 'UI'],
groups: ['Units', 'Datum', 'UI', 'Map'],
items: defaultUserSettings,
convertDatum: false,
useDisplayUnits: true,
Expand Down
Loading