You need to use contextMenu.addHandler() to add your custom menu item and contextMenu.removeHandler() remove menu items passing in the function to the context menu. After some rooting around the code, I've discovered that the following will work:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9" />
<title>Context Menu</title>
<script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.2.1/jsl.js?with=all"></script>
</head>
<body>
<div id="mapcanvas" style="width:800px; height:400px;" > </div>
<script type="text/javascript">
/////////////////////////////////////////////////////////////////////////////////////
// Don't forget to set your API credentials
//
// Replace with your appId and token which you can obtain when you
// register on http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
//
/////////////////////////////////////////////////////////////////////////////////////
// Get the DOM node to which we will append the map
var mapContainer = document.getElementById("mapcanvas");
// Create a map inside the map container DOM node
var map = new nokia.maps.map.Display(mapContainer, {
components: [
new nokia.maps.map.component.panning.Drag(),
new nokia.maps.map.component.panning.Kinetic()
],
'zoomLevel': 2,
'center': [43.09, -53.674]
});
var contextMenu = new nokia.maps.map.component.ContextMenu();
/* Add a Custom item */
var myHandler = function(contextMenuEvent, group) {
group.addEntry(
"Custom Item",
function(activationEvent) {
alert( "Clicked");
});
}
// Remove Zoom
contextMenu.removeHandler(nokia.maps.map.component.ContextMenu.zoomHandler);
// Remove Routing
if (nokia.maps.routing.component !== undefined){
contextMenu.removeHandler(nokia.maps.routing.component.ContextMenuHandler);
}
// Add something else.
contextMenu.addHandler(myHandler);
map.components.add(contextMenu);
</script>
</body>
</html>