convert pixel x,y position on map to lat and long?

3210
13
04-20-2020 05:18 AM
CamCode
New Contributor III

My map takes up 100% width and height of the browser screen.. I have a draggable div that is super imposed over the map, I am capturing this divs position using offset(); to get the pixel top and left values currently.

My goals would be to convert these values to latitude and longitude... Could something like this be possible? 

0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus

Cam,

   Have you considered map.toMap(ScreenPoint)?

https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#tomap 

CamCode
New Contributor III

Thanks, I thought that may have been depreciated.

So how may that apply to the below scenario for instance?

          let ktop = $('elem').offset().top;
          let ktlft = $('elem').offset().left;
          coordinatesBx = ktop
          coordinatesBy =  ktlft
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Cam,

   Not sure what gave you that idea. The application would simply be:

var point = map.toMap(new ScreenPoint(coordinatesBx,coordinatesBy));
console.log("Lat: " + point.getLatitude() + ", Lon: " + point.getLongitude());
CamCode
New Contributor III

Gotchya. It is reported Uncaught ReferenceError: ScreenPoint is not defined

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

did you add the require for the ScreenPoint class?

0 Kudos
CamCode
New Contributor III

For some reason I am having a hard time in getting the import to resolve; is there a specific order this one should be called?

import ScreenPoint from "esri/geometry/ScreenPoint";
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Cam,

  Are you using 4.x or 3.x?

0 Kudos
CamCode
New Contributor III

Yes, 4.x.. tried to add that as a tag in OP. Is there a similar approach in 4.x?

0 Kudos