useMapboxBeforeLoad() is a composable that helps you interact with the Mapbox map in a smart way. It takes care of executing your code at just the right time - whether the map is already loaded or still in the process of loading. This makes it perfect for setting up your map configurations and event listeners without worrying about timing issues.
The composable is particularly useful when you need to interact with the map from child components or when you want to ensure map operations only happen after the map is fully loaded.
<script setup lang="ts">
const { map } = injectMapboxMapContext();
const events = ref(["resize", "remove", "load", "render", "idle", "error"])
useMapboxBeforeLoad((map) => {
events.value.forEach((eventName) => {
map?.on(eventName, (e) => {
emit(eventName, e);
})
})
});
</script>
declare function useMapboxBeforeLoad(callback: (map: Map) => void): void