useCreateMapContext
Creates a reusable map context in the parent
Use it when MapBase and sibling UI should share the same resolved map state
Return value
| Adapter | Type |
|---|---|
@d3-maps/vue | ComputedRef<MapContext> |
@d3-maps/react | MapContext |
See MapContext API
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
config? | MapProps | — | When context is not provided, has same props as MapBase |
context? | MapContext | — | Optional existing context to reuse instead of creating a new one |
Usage
Create the context once in the parent, pass it to sibling UI by prop, and pass the same object into MapBase
vue
<script setup lang="ts">
import { computed } from 'vue'
import {
useCreateMapContext,
type MapData,
} from '@d3-maps/vue'
const props = defineProps<{
data: MapData
}>()
const context = useCreateMapContext(computed(() => ({
fit: props.data,
width: 420,
})))
</script>
<template>
<Toolbar :context="context" />
<MapBase :context="context">
<MapFeatures :data="props.data" />
</MapBase>
</template>If neither config nor context is provided, the helper creates a context from map defaults
Best Practice
- Use
useCreateMapContextin the parent when controls, toolbars, or other sibling UI need the same map context asMapBase - Use useMapContext inside custom layers rendered under
MapBase - Use
MapBaseslot or render-prop context when that already gives you what you need