Sign up ×
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!

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

4 Answers 4

Just as an addition to the answer of Laurentiu Turcu:

As I thought this is an interesting question I set up a jsfiddle which demonstrates how to show the popup at the last mousePosition when you select a feature:

so even if the question is 3 years old...perhaps someone can use this if he/she stumples across this question.

share|improve this answer

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 strategy (very resource intensive) is to listen to mousemove and constantly saving x and y values in global variables.

var mouseLat, mouseLon;
function init(){
  ..."mousemove", map, function(e) {
    var position =;
    var lonlat = map.getLonLatFromPixel(position);
    var lonlatTransf = lonlat.transform(map.getProjectionObject(), proj4326);
    mouseLat =;
    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 – ThomasG77 Nov 12 '14 at 23:07

You can get it with these ways:


or"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

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.