Skip to content

Menu

Menu is the right-click context menu. It extends UIComponent. It pops up a menu containing several menu items on the map, usually used with the right-click event of a map or a geometry. It supports custom menu items, a maximum height and show/hide animations.

js
import { Menu } from "maptalks";

const menu = new Menu({
  items: [
    { item: "Item 1", click: () => {} },
    { item: "Item 2", click: () => {} }
  ]
});

menu.addTo(map).show(coordinate);

Constructor

js
new Menu(options)

Parameters:

  • options — Menu options. Some properties match the Menu.options table below.

options

NameTypeDescriptionDefault
itemsArrayThe menu item list. Each element is { item, click, children, ... }[]
widthNumberThe menu width160
maxHeightNumberThe maximum height of the menu0
customBooleanWhether custom content is usedfalse
animationStringThe show animation typenull
animationDelayNumberThe animation delay10
animationOnHideBooleanWhether to animate on hidefalse
autoPanBooleanWhether to auto-pan the map when shownfalse

Member Methods

  • setItems(items): Menu — Sets the menu item list.
  • getItems(): Object[] — Gets the menu item list.
  • addTo(owner): Menu — Attaches the menu to owner.
  • getOffset(): Point — Gets the menu offset.
  • getTransformOrigin(): String — Gets the transform origin of the menu.