MapView toScreen returns wrong screenpoint

373
3
09-11-2019 03:17 AM
EemeliP
New Contributor II

Hi,

I have an application that loads a Webmap from portal using ArcGIS JS version 4.12. Then I navigate to certain point with MapView goTo function. That works fine. Then I need to convert the Point into ScreenPoint in order to do a hittest. When I do the "toScreen" conversion it returns a point on screen that is not on the right place.

Am I missing something here, or should somehow take the spatial reference of the map into account. The Point I create from x and y coordinates points into the right place. Why does the "toScreen" point into a wrong place even though the goto leads into right place? I have tried to change or set different spatial references for the point before "toScreen" but it does not seem to help.

Example:

var point = new Point();
point.longitude = "-2.12953405978807";
point.latitude = "50.6877745154717";

// screenPt is x: 1210, y: 416 although it should be something like x: 959  & y: 528.
var screenPt = _view.basemapView.view.toScreen( point );‍‍‍‍‍‍
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Eemeli,

  Why are you using the basmapView and not just the _view to get the screen point?

var screenPt = _view.toScreen(point);
0 Kudos
EemeliP
New Contributor II

Hi Robert,

Actually using "basemapView.view" was just the last experiment I had and accidentally left it there as an example. I have the same result when using "_view": the generated screen point is out of screen.

var screenPt = _view.toScreen( point );
0 Kudos
EemeliP
New Contributor II

Hi,

I think I was able to resolve this. It was about timing as there was on-going "pan" and therefore the original point was "moving on the screen" and the resulted screenpoint was more or less random.

I fixed this by waiting that the view animation is done:

_view.watch( "animation",function( response ) {

     if( response && response.state !== "running" ) {

           var screenPt = _view.toScreen( point );
     }
}‍‍‍‍‍‍‍


0 Kudos