Creates a new context menu for Mapbox GL JS or Maplibre GL JS.
Optionaloptions: MapboxContextMenuOptionsConfiguration options for the context menu.
Configuration options for creating a Mapbox context menu. Extends ContextMenuOptions.
OptionalclassName?: stringCustom CSS class name for the menu element.
Optionaltheme?: ContextMenuThemeThe color theme: "light", "dark", or "auto" (follows system preference). Defaults to "auto".
Optionalwidth?: string | numberThe menu width as a CSS value (e.g., "200px") or number in pixels.
Sets the CSS class name for the menu element.
The class name to apply. Will be combined with the base menu class.
Gets the context menu items.
The context menu items.
Gets the theme of the context menu.
The current theme setting: "light", "dark", or "auto".
Sets the theme of the context menu.
The theme to use: "light" for light mode, "dark" for dark mode, or "auto" to follow the system preference.
Gets the width of the context menu.
The width as a string (e.g., "200px") or number (in pixels), or undefined if not set.
Sets the width of the context menu.
The width as a string (e.g., "200px") or number (in pixels), or undefined to use the default width.
Adds a menu item to the end of the context menu.
The menu item to add. Can be a ContextMenuItem, ContextMenuSeparator, or ContextMenuSub.
The context menu instance for method chaining.
Adds the context menu to a Mapbox GL JS or Maplibre GL JS map.
The map instance.
Optionaltarget: LayerTargetOptional target to restrict the menu to. Can be:
"building")["building", "poi"]){ featuresetId: "buildings", importId: "basemap" })Focus the first focusable item in the menu.
Inserts a menu item at the specified index.
The index at which to insert the item. If the index is out of bounds, the item will be added at the end.
The menu item to insert. Can be a ContextMenuItem, ContextMenuSeparator, or ContextMenuSub.
The context menu instance for method chaining.
Checks whether there are any registered handlers for the specified event type.
The event type to check.
true if there are registered handlers for the event type, false otherwise.
Removes the context menu from the map and cleans up event listeners.
Removes a menu item from the context menu, doing any clean up necessary.
The menu item to remove.
The context menu instance for method chaining.
A context menu for Mapbox GL JS and Maplibre GL JS.
Example