. "esri/map", "esri/geometry/webMercatorUtils", "dojo/dom", I want to release in the future a web app that requires moving elements inside a canvas. Using a simple logging function the coordinates I receive (plus or minus 5 for mouse imprecision) are (98, 473), (487, 470), (969, 471), (969, 190).
#Get mouse coordinates of svg group object javascript code#
Var mp = (evt.mapPoint) ĭojo.byId("info").innerHTML = mp.x + ", " + mp.y Code To test this in a simple manner, I put three rectangles in global svg space at (100, 500), (500, 500), (1000, 500), and (1000, 200). Following is how the function gets the coordinates and writes them to the "info" tag: To display the coordinates in geographic, use the utility object to perform the conversion. The first (var map) is the name of the object, the second ( esri.Map) is the name of the class, and the third ('map') is the. The following line creates the map: var map new esri.Map('map') 'Map' appears three times in the above line. Of course, it was a bit more complicated, but this is the code i want to share with you.
#Get mouse coordinates of svg group object javascript update#
Since the map data is in Web Mercator the resulting coordinates will display in Web Mercator. This is made possible by event listeners that update the the x and y coordinates whenever the mouse moves. I had to display several photos where the user can click over an interesting point and have its coordinates passed through a form. These events both pass map point coordinates to the showCoordinates function. One listens for onMouseMove and the other listens for onMouseDrag, but they both call the function showCoordinates:ĭojo.connect(map, "onMouseMove", showCoordinates) ĭojo.connect(map, "onMouseDrag", showCoordinates) Positions are then measured in pixels from the top left corner, with the positive x. That is, the top left corner of the document is considered to be the point (0,0), or point of origin. These two lines add event listeners to the map. For all elements, SVG uses a coordinate system or grid system similar to the one used by canvas (and by a whole lot of other computer drawing routines). The first (var map) is the name of the object, the second ( esri.Map) is the name of the class, and the third ("map") is the name of the div which will contain the map. "Map" appears three times in the above line. This is made possible by event listeners that update the the x and y coordinates while the mouse moves. This sample reports the coordinates of the mouse pointer as the user hovers or drags the mouse across the map.
