Skip to content

Commit

Permalink
Show location name as text-field on map
Browse files Browse the repository at this point in the history
  • Loading branch information
wkramer committed May 28, 2024
1 parent f396649 commit 09779dd
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/components/wms/LocationsLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
:layer-id="locationsCircleLayerId"
:paint="paintCircleSpecification"
/>
<mgl-symbol-layer
:layer-id="locationsTextLayerId"
:layout="layoutTextSpecification"
:paint="paintTextSpecification"
/>
</mgl-geo-json-source>
</template>

Expand All @@ -29,9 +34,10 @@ import {
MapLayerTouchEvent,
MapSourceDataEvent,
} from 'maplibre-gl'
import { watch, onBeforeUnmount } from 'vue'
import { watch, onBeforeUnmount, computed } from 'vue'
import { onBeforeMount } from 'vue'
import { addLocationIconsToMap } from '@/lib/location-icons'
import { useDark } from '@vueuse/core'
interface Props {
locationsGeoJson: FeatureCollection<Geometry, Location>
Expand All @@ -48,11 +54,29 @@ const props = withDefaults(defineProps<Props>(), {
const emit = defineEmits(['click'])
const isDark = useDark()
const layoutSymbolSpecification = {
'icon-allow-overlap': true,
'symbol-sort-key': 1,
}
const layoutTextSpecification = {
'text-field': ['get', 'locationName'],
'text-size': 12,
'text-overlap': 'never',
'text-padding': 10,
'text-justify': 'auto',
'text-variable-anchor': ['right', 'left'],
'text-max-width': 15,
}
const paintTextSpecification = computed(() => {
return {
'text-color': isDark.value ? 'rgb(255,255,255)' : 'rgb(0,0,0)',
}
})
const defaultOpacity = 0.75
const paintSymbolSpecification = {
Expand All @@ -71,6 +95,7 @@ const { map } = useMap()
const locationsCircleLayerId = 'location-circle-layer'
const locationsSymbolLayerId = 'location-symbol-layer'
const locationsTextLayerId = 'location-text-layer'
const locationsSourceId = 'location-source'
watch(
Expand Down

0 comments on commit 09779dd

Please sign in to comment.