The mapElement factory is an internal utility used to create Vue component options for Google Maps elements. It automates the lifecycle of a Google Maps object within a Vue component, including:
- Initialization: It waits for the
$mapPromise to resolve before initializing the underlying Google Maps object. - Property Mapping: It maps Vue props to the underlying Google Maps instance using
mappedProps. - Event Binding: It binds Google Maps events to Vue component methods via the
events configuration. - Lifecycle Hooks: It provides
beforeCreate and afterCreate hooks to allow custom logic during the instantiation of the map element. - Cleanup: It automatically calls
.setMap(null) on the instance during the Vue destroyed lifecycle hook to prevent memory leaks, provided the instance supports it.
Note: This is a low-level factory function. For standard usage, refer to the high-level component APIs provided by @gmap-vue/v3 or @gmap-vue/v2.
// Example of the configuration object structure passed to mapElement
const options = {
name: 'myElement',
ctr: () => MyGoogleMapsClass,
ctrArgs: (options, props) => [/* args for constructor */],
mappedProps: { /* mapping logic */ },
events: { /* event bindings */ },
props: { /* Vue props */ },
beforeCreate: (options) => { /* logic before instantiation */ },
afterCreate: (instance) => { /* logic after instantiation */ }
};