Hello. I'm using JS 4.6.
I'm able to get x,y coordinates with view's click event. But i want to get xy coordinates with mouse move. For this i tried to get x,y below code. But i'm seeiny mouse X and Mouse Y, Not mappointX and Mappoint.Y
Below code has no problem (click event).
appConfig.activeView.on("click", function(evt){
alert(evt.mapPoint.x);
alert(evt.mapPoint.Y);
})
below code has problem (no mappoint property for evt)
appConfig.activeView.on("pointer-move", function(evt){
alert(evt.mapPoint.x);
alert(evt.mapPoint.Y);
})
Thanks inadvance
Solved! Go to Solution.
In the documentation, it shows that the pointer-move event doesn't return a MapPoint, but it still returns an x and y coordinate. You can use those coordinate to create a MapPoint.
view.on('pointer-move', (evt) => {
console.log(evt.x,evt.y);
var point = view.toMap(evt);
console.log(point.x, point.y);
});
If you need the mapPoint on pointer events, you can use the Views toMap() method.
You can just pass it the event directly, like const pt = view.toMap(event)
In the documentation, it shows that the pointer-move event doesn't return a MapPoint, but it still returns an x and y coordinate. You can use those coordinate to create a MapPoint.
view.on('pointer-move', (evt) => {
console.log(evt.x,evt.y);
var point = view.toMap(evt);
console.log(point.x, point.y);
});
Thanks for sample. working good.
But i see different values for same location between click event and pointer-move event.
click returning x= 25.9666 y = 19.3333 (Decimal Degree)
pointer-move returning : x= 8095424.24577 y = 1587845.544875 (webmercator)
and i used webMercatorUtils.webMercatorToGeographic function to return as deciamldegree.
So, All working good now. Thanks.