Converting a point to screen geometry

4815
4
04-20-2016 02:28 PM
JillianStanford
Occasional Contributor III

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

0 Kudos
4 Replies
BillGrow
New Contributor II

Hi Jill,

Are your input and output geometries in the same spatial reference (webmercator)?  If not, have you tried projecting your input point to webmercator before you pass it to the 'toScreenGeometry' function?  Does this happen when you are zoomed all the way in to the closest extent?  Is the screen location maybe being generalized on the map in the 'toMapGeometry' method (at the world view 1px could = miles of space)? 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jill,

  have you looked at the toScreen and toMap methods on the map object?

Map | API Reference | ArcGIS API for JavaScript | toScreen

0 Kudos
BillGrow
New Contributor II

Also, what is the ultimate goal here?  I feel like GIS > Screen > GIS would be better facilitated by simply adjusting the geometry/symbology, unless there is some UI/UX need for translation to screen px. 

Thanks,

~Bill

0 Kudos
JillianStanford
Occasional Contributor III

Hi!

Thank you so much for all of the replies. I really appreciate it.

Robert, you are correct. The Map object's toScreen and toMap methods do give me the expected results. Thanks for the suggestion!

However, Bill, your comments made me reevaluate my strategy. You are right that tweaking the symbology gave me what I was looking for.

Thanks!

Jill

0 Kudos