useMapContext
Reads the current map context from MapBase
Use it in custom layers when you need the resolved map size, normalized features, or the shared path generator
Throws an error if used outside MapBase
Return value
| Adapter | Type |
|---|---|
@d3-maps/vue | ComputedRef<MapContext> |
@d3-maps/react | MapContext |
See MapContext API
Usage
vue
<script setup lang="ts">
import { computed } from 'vue'
import { useMapContext } from '@d3-maps/vue'
const context = useMapContext()
const featureCountLabel = computed(() => `${context.value.features.length} features`)
</script>
<template>
<text
v-if="featureCountLabel"
x="12"
y="20"
font-size="12"
fill="#111"
>
{{ featureCountLabel }}
</text>
</template>Best Practice
- Use
useMapContextin components rendered insideMapBase - Use
MapBaseslot/render-prop context when that already gives you what you need - Use useCreateMapContext in the parent and pass the same
contextobject to bothMapBaseand any sibling UI that needs it