View pointer-move event has no mapPoint property for getting X,Y coordinates

2037
3
Jump to solution
03-27-2018 06:37 AM
TubaKumbara
Occasional Contributor

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

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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);
});

View solution in original post

3 Replies
ReneRubalcava
Frequent Contributor

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)

KenBuja
MVP Esteemed Contributor

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);
});
TubaKumbara
Occasional Contributor

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.

0 Kudos