Var mp = webMercatorUtils.webMercatorToGeographic(evt.mapPoint) ĭom.byId("info").innerHTML = mp.x.toFixed(3) + ", " + mp.y. the map is in web mercator but display coordinates in geographic (lat, long) after map loads, connect to listen to mouse move & drag events "esri/map", "esri/geometry/webMercatorUtils", "dojo/dom", Var mp = (evt.mapPoint) ĭojo.byId("info").innerHTML = mp.x + ", " + mp.y Code It also needs to take into account any scrolling and the position of the image inside the. import MousePosition from ol/control/MousePosition.js import OSM from ol/source/OSM.js. Following is how the function gets the coordinates and writes them to the "info" tag: event method to find the coordinates of the mouse when it is clicked. Example of a mouse position control, outside the map. To display the coordinates in geographic, use the utility object to perform the conversion. Since the map data is in Web Mercator the resulting coordinates will display in Web Mercator. 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) These two lines add event listeners to the map. 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. The event object that is passed to the handler contains some. This is made possible by event listeners that update the the x and y coordinates while the mouse moves. To get the mouse coordinates relative to an HTML5 Canvas, we can create a getMousePos() method which returns the mouse coordinates based on the position of. When tracking mouse movement, you usually need to know the actual position of the mouse pointer. This sample reports the coordinates of the mouse pointer as the user hovers or drags the mouse across the map.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |