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'm have been searching for several hours and do not find a way to get mouse coordinates after a SelectFeature, which returns the feature by itself. I saw that this has been asked several times earlier, so I try again !

Thanks very much,


share|improve this question
I need an answer to this aswell. –  netbrain Mar 27 '12 at 9:12

4 Answers 4

You can get it with these ways:



map.events.register("click", map, function(e) { 
    var latlon = map.getLonLatFromViewPortPx(e.xy) ;


new OpenLayers.Control.SelectFeature(layer,{


            "featureselected": function(e) {       

i hope it helps you....

share|improve this answer
Aragon, I think he is asking for mouse coordinates (mostly to display Popup) and not map coordinates. What your answer telling is to get map coordinates. –  Suraj Jul 1 '14 at 10:49

my strategy (very resource intensive) is to listen to mousemove and constantly saving x and y values in global variables.

var mouseLat, mouseLon;
function init(){
  map.events.register("mousemove", map, function(e) {
    var position = this.events.getMousePosition(e);
    var lonlat = map.getLonLatFromPixel(position);
    var lonlatTransf = lonlat.transform(map.getProjectionObject(), proj4326);
    mouseLat = lonlatTransf.lat;
    mouseLon = lonlatTransf.lon;
    OpenLayers.Util.getElement("coords").innerHTML = "Lat: "+ mouseLat+" | Lon: "+mouseLon;

when the feature is selected, i access these values from inside onFeatureSelect(event)

share|improve this answer
To decrease resource consumption, use debounce/throttle techniques benalman.com/projects/jquery-throttle-debounce-plugin –  ThomasG77 Nov 12 '14 at 23:07

When you init the map add this control:

mapMousePosition = new OpenLayers.Control.MousePosition({
        displayProjection: new OpenLayers.Projection(displayProjection)

In your handler get lonLat like this:

 var lonLat = map.getLonLatFromPixel(
      new OpenLayers.Pixel(
share|improve this answer

My appologies for adding commenting here, reputations less than 50....tony gil, I'm new here, can you break that down or make it more simpler. And everyone, I know how to display mouse position coordinates, my only problem is that where it is currently displaying (lower right corner) I want do display map/laters attribute. So is it possible to display either on the left corner or in the toolbar...

share|improve this answer

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.