mapbox-gl-contextmenu - v1.6.0
    Preparing search index...

    Class ContextMenuItem

    A context menu item that can be added to a context menu.

    Menu items can display a label with optional content before and/or after it, and can be enabled or disabled. When clicked, menu items fire a "click" event with context data including the map, coordinates, and any features at the click location.

    const item = new ContextMenuItem({
    label: "Center here",
    start: { className: "fa-solid fa-crosshairs" }
    });

    item.on("click", ({ map, lngLat }) => {
    map.flyTo({ center: [lngLat.lng, lngLat.lat] });
    });

    menu.addItem(item);

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new context menu item.

      Parameters

      • options: ContextMenuItemOptions

        Configuration options for the menu item.

        Configuration options for creating a context menu item.

        • OptionalbuttonClassName?: string

          Custom CSS class name for the menu item's <button> element.

        • OptionalclassName?: string

          Custom CSS class name for the menu item's <li> element.

        • Optionaldisabled?: boolean

          Whether the menu item is disabled. Defaults to false.

        • Optionalend?: Content

          Content to display after the label.

        • label: string

          The text label to display.

        • Optionalstart?: Content

          Content to display before the label (e.g., an icon element).

      Returns ContextMenuItem

    Accessors

    Methods

    • Fires an event, calling all registered handlers for the event type.

      Type Parameters

      • K extends keyof ContextMenuItemEvents

      Parameters

      • type: K

        The event type to fire.

      • event: ContextMenuItemEvents[K]

        The event data to pass to the handlers.

      Returns this

      The instance for method chaining.

    • Checks whether there are any registered handlers for the specified event type.

      Type Parameters

      • K extends keyof ContextMenuItemEvents

      Parameters

      • type: K

        The event type to check.

      Returns boolean

      true if there are registered handlers for the event type, false otherwise.

    • Unregisters an event handler for the specified event type.

      Type Parameters

      • K extends keyof ContextMenuItemEvents

      Parameters

      • type: K

        The event type to stop listening for.

      • handler: EventHandler<ContextMenuItemEvents[K]>

        The function to remove from the event handlers.

      Returns this

      The instance for method chaining.

    • Registers an event handler for the specified event type.

      Type Parameters

      • K extends keyof ContextMenuItemEvents

      Parameters

      • type: K

        The event type to listen for.

      • handler: EventHandler<ContextMenuItemEvents[K]>

        The function to call when the event is fired.

      Returns this

      The instance for method chaining.