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 have implemented a vector layer(using javascript) in open layers which is having point geometry.

Now my requirement is to show menu just besides with the point whenever we do right-click on


Can we do this in Open Layers?

Thanks, Gajendra

share|improve this question
It's doable, but not straight forward. Right clicks are not picked up by javascript by default (they are reserved for browser menus). – atlefren May 8 '12 at 13:55
If you try OL 3 I wrote an extension for this. – Jonatas Walker Jan 22 at 19:32
up vote 6 down vote accepted

there is an information here about right click select feature. i havent try it but it looks like it works.

myMap is OpenLayers.Map object and myVectorLayer is... OpenLayers.Layer.Vector.

myMap.div.oncontextmenu = function noContextMenu(e) {
    if(!e){ //dear IE...
        var e = window.event;
        e.returnValue = false;

    var f = myVectorLayer.getFeatureFromEvent(e);
    //f is the pointed vector.feature :)

    return false; //Prevent display of browser context menu

i hope it helps you...

share|improve this answer
Thanks a lot Aragon ! – G.S.Tomar May 9 '12 at 10:17
"getFeatureFromEvent(e)" was really a good pointer...I have used this to get point geometry(which is laid over vector feature) and further to show menu(for which I have used openlayer's popup)I have used (long,lat) of point. Following is the code which I have implmeneted to show menu besides with point geometry: – G.S.Tomar May 9 '12 at 10:25
var f = vectorLayerForHoleMarkers.getFeatureFromEvent(e); popup = new OpenLayers.Popup("chicken", new OpenLayers.LonLat(f.geometry.x,f.geometry.y), new OpenLayers.Size(200,200),true); popup.closeOnMove = true; myMap.addPopup(popup); – G.S.Tomar May 9 '12 at 10:28

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.