show x,y coordinates, changing the number of decimal places

2140
1
09-10-2011 04:31 AM
SwenWaschk
New Contributor III
Hi,

I'm working on an project using the ArcGIS API for JavaScript and i've added:
dojo.connect(map, "onLoad", function() {
          //after map loads, connect to listen to mouse move & drag events
          dojo.connect(map, "onMouseMove", showCoordinates);
          dojo.connect(map, "onMouseDrag", showCoordinates);
        });


and further on i've added:
function showCoordinates(evt) {
        //get mapPoint from event
         var mp = evt.mapPoint;
        //display mouse coordinates
        dojo.byId("info").innerHTML = mp.x + ", " + mp.y;
    }


since my map is in wkid: 28992 (or RD new for the dutch people here) just showing 123456, 345678 instead of say 6 decimal places would by ideal.

But how do I do this?
0 Kudos
1 Reply
SwenWaschk
New Contributor III
Never mind, I've found it:

function showCoordinates(evt) {
        //get mapPoint from event
         var mp = evt.mapPoint;
        //display mouse coordinates
        dojo.byId("info").innerHTML = mp.x.toFixed(0) + ", " + mp.y.toFixed(0);
    }


I just had to add: .toFixed(0) where (0) represents the decimal places.
0 Kudos