How BMap component lifecycle and WebGL cleanup works
mainThe BMap component manages the lifecycle of the Baidu Map GL SDK.
Important for WebGL users: When using WebGL rendering, it is critical to destroy the map instance to prevent 'too many WebGL context' warnings in the browser. The component automatically calls map.destroy() when the component is unmounted (onUnmounted).
Initialization Flow:
- The component checks if it's running in a client environment (
isClient). - It asynchronously loads the Baidu Map GL script via
getScriptAsyncusing the providedakorapiUrl. - Once the script is loaded, it initializes the
BMapGL.Mapinstance. - It applies initial props (center, zoom, etc.) and binds events.
- If
pluginsare provided, it initializes them and emitspluginReady. - Finally, it emits
initdto signal the map is ready for use.