toScreen returning null

866
2
Jump to solution
03-20-2018 12:46 PM
LA
by
New Contributor

Hi,

I am trying to obtain the screen coordinates of a particular location in a MapView using a code similar to this:

var webmap = new WebMap({...});
var view = new MapView({...});
var lat = Number(32.473565);
var lon = Number(-93.791870);
var testPoint = new Point({type: "point", latitude: lat, longitude: lon});
var testScreen = view.toScreen(testPoint);‍‍‍‍‍

However, I keep getting a null testScreen variable. I assume the error is in line 5, but the Point object gets created, it seems, without any errors. I left out the require statements but I am including "esri/geometry/Point" and
"esri/geometry/ScreenPoint". Could someone provide some sample code that shows how to use toScreen to go from a given latitude/longitude to screen coordinates?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You have to wait until the View is ready

view.when(function(){
  console.log(view.toScreen(testPoint));
}

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

You have to wait until the View is ready

view.when(function(){
  console.log(view.toScreen(testPoint));
}
LA
by
New Contributor

Ken, thanks.I have been using the promise on the WebMap since something similar to this had happened before with the WebMap, but I had overlooked waiting on the MapView to be ready.

0 Kudos