AnsweredAssumed Answered

Converting a point to screen geometry

Question asked by jestanford on Apr 20, 2016
Latest reply on Apr 25, 2016 by jestanford

Hi All,

Ultimately what I'm trying to do is convert a map point to a screen point so that I can offset it by a distance in screen units and then convert it back to map point so I can place it on the map.

 

I'm trying to do this using the toMapGeometry and toScreenGeometry methods in the screenUtils module but they don't work as I expect them to.

 

Taking the offset out of the equation for a minute, what's confusing is that if I take a map point and convert it to a screen point and then convert it back to a map point again the X and Y are not the same as the original point. Shouldn't they be the same? Am I using these methods incorrectly?

 

Here's my code (for whatever reason syntax highlighting is not working for me today...):

 

var screenGeo = screenUtils.toScreenGeometry(this.map.extent, this.map.width, this.map.height, evt.geometry);

var mapPointGeo = screenUtils.toMapGeometry(this.map.extent, this.map.width, this.map.height, screenGeo);

 

//Ouput:

?evt.geometry

    type: "point"

    x: -88.18114353491255

    y: 41.7207439952267

?screenGeo

    type: "point"

    x: 64564

    y: 33899

?mapPointGeo

    type: "point"

    x: -83.94943230599165

    y: 98.94651940930635

 

I was expecting evt.geometry and mapPointGeo to be the same.

 

There are two other methods that are depreciated: toMapPoint and toScreenPoint. These do work as expected (once I do some geographic/web merc conversion).

 

Any ideas?

Thanks!

Jill

Outcomes