Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

point.

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
add comment

1 Answer 1

up vote 4 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);
    alert(f);
    //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
1  
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
add comment

Your Answer

 
discard

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.