back | source
How to add a new command into the context menu
  1. Calling via event handler
    map.Event.bind('beforeContextmenu', function(event) {
      var element = document.createElement('div');
      element.innerHTML = 'click me';
      element.style.cursor = 'pointer';
      element.onclick = function() {
        map.Ui.ContextMenu.visible(false);
        alert(event.location.lon + ', '
          + event.location.lat);
      };
      event.add(element);
    });
    • beforeContextmenu : Context menu is going to appear
    • event : Event is the object that sent when the thing happened
    • element: Element is the button that inserted in Context Menu
    • ContextMenu.visible : Show/Hide context menu