The MapboxImage component allows you to add an image to the Mapbox GL map instance. Once added, the image can be referenced in Mapbox GL layers using properties like icon-image, background-pattern, fill-pattern, and line-pattern.
To use it, place the MapboxImage component inside a MapboxMap component. You can also use the default slot to render child components (like MapboxLayer) that depend on the image being loaded. The default slot is rendered only after the image has been successfully added to the map and the add event is emitted.
<template>
<MapboxMap
access-token="YOUR_TOKEN"
map-style="mapbox://styles/mapbox/streets-v11"
:center="[0, 0]"
:zoom="1">
<MapboxImage
src="https://example.com/icon.png"
id="my-icon">
<!-- The default slot ensures the layer only renders once the image is ready -->
<MapboxLayer
id="points-layer"
:options="{
type: 'symbol',
source: { type: 'geojson', data: ... },
layout: { 'icon-image': 'my-icon' }
}" />
</MapboxImage>
</MapboxMap>
</template>