Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to add a context menu on right click for various elements on my GeoJSON layer (I'm doing a road map so on a right click on the road at any part I want to show the context menu).

I've managed to get the left click working fine by using the onEachFeature and doing the following

function onEachFeature(feature, layer) {
            click: showAssetInfo,
            contextmenu: contextreg


 function showAssetInfo(e) {
        AssetMouseClick(, e.latlng);

For the context menu I have followed the example here . The context menu library is found here

I have the following that gets called on the document ready (jQuery)

    selector: 'path.leaflet-clickable',
    zIndex: 99999,
    callback: function (key, options) {
        var m = "clicked: " + key;
        window.console && console.log(m) || alert(m);
    items: {
        "edit": { name: "Edit", icon: "edit" },
        "cut": { name: "Cut", icon: "cut" },
        "copy": { name: "Copy", icon: "copy" },
        "paste": { name: "Paste", icon: "paste" },
        "delete": { name: "Delete", icon: "delete" },
        "sep1": "---------",
        "quit": { name: "Quit", icon: "quit" }

I've tested it and the selector does return the GeoJSON features, also if it attach the same menu to something else it works correctly.

Is there something I am missing here?

Also is there a good way to pass in the objectid to the menu when it starts up so I can use it when calling the different options of the menu

I have created this fiddle to demonstrate

share|improve this question

The event management for Leaflet and jQuery for this use case seems to conflict.

Instead of struggling with debugging, you should better use an alternate solution like this contextMenu dedicated lib for Leaflet.

share|improve this answer

have you checked out anything like this

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Yes that is the library I linked to above, am I missing something – Daniel Powell Mar 20 '13 at 9:30
I've been playing around with your jsfiddle example and getting nowhere. Pretty maddening. I'm more or less a newb with javascript but I was thinking of not using the plugin.It seems that the $.contextMenu is being ignored completely. – geomajor56 Mar 21 '13 at 14:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.