Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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 an OpenLayers interface with two maps side-by-side. They are synced so that any pan or zoom action on either map affects both of them.

I also have MousePosition controls on each map so that the user can see the lon/lat coords on mouseover. I like having a separate MousePosition on each map rather than a single one in an external div. I was able to sync the MousePosition controls to one another using the code below.

My question is this: Is there a better way to get a handle on the MousePosition elements? The getElement approach I'm using feels a bit hacky. Thanks."mousemove", map1, function (e) {
  var position = map1.getLonLatFromViewPortPx(e.xy).transform(WGS84_SM, WGS84);
  var lat =;
  var lon = position.lon.toFixed(5);
OpenLayers.Util.getElement("OpenLayers.Control.MousePosition_68").innerHTML =
                           "<label>" + lon + " " + lat + "</label>";
});"mousemove", map2, function (e) {
  var position = map2.getLonLatFromViewPortPx(e.xy).transform(WGS84_SM, WGS84);
  var lat =;
  var lon = position.lon.toFixed(5);
OpenLayers.Util.getElement("OpenLayers.Control.MousePosition_37").innerHTML =
                           "<label>" + lon + " " + lat + "</label>";
share|improve this question
up vote 1 down vote accepted

Why not just listen to the mouse-move event and write to your own div and just place it on top of your map with relative positioning and a high z-index? Then you'll know exactly the ID of each div and can write to it what you like.

share|improve this answer
Agreed, this seems like the best way to do it. Thanks. – vulture Sep 13 '12 at 6:52

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.