MapInstance API
Public methods and properties on the MapInstance object.
Each map on the page is represented by a MapInstance. In normal usage you access the instance indirectly through mwm_v2.add_action and the properties passed to your event handlers. The properties and methods below are the public-facing API.
Properties (via event handler)
These are available inside any event handler callback as { map, config, features, markers, controls }:
map
Object
The underlying map library instance (MapLibre GL JS, Mapbox GL JS, or Google Maps). Call native library methods directly on this.
config
Object
The map's full configuration. Includes config.id (WordPress post ID of the map) and all settings.
features
Array
Feature objects loaded onto the map (locations, lines, polygons).
markers
Array
Marker instances currently rendered on the map.
controls
Object
Control instances keyed by control name (e.g. controls.geocoder, controls.zoom).
Methods
showLayers()
Shows all feature layers on the map after they've been hidden with hideLayers().
hideLayers()
Hides all feature layers on the map. The map base style remains visible.
updateFeatures(features)
Replaces the map's current features with a new array. The map re-renders without reinitializing. Useful for dynamically loading or filtering features from your own data source.
updateConfig(config)
Updates the map configuration at runtime. The SDK diffs the incoming config against the current one and emits only the events needed to apply the relevant changes — so updating a single control won't trigger a full re-render.
remove()
Tears down the map instance and empties its container element. The instance is no longer usable after this is called.
Last updated