Select to view content in your preferred language

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

3822
13
04-20-2020 05:18 AM
CamCode
Regular Contributor

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
CamCode
Regular Contributor
Thanks for looking. Below is my 4.x attempt.. It is returning 'point.getLatitude()....' is not a function.
          let ktop = $('elem1').offset().top;
          let ktlft = $('elem2').offset().left;
          
          let point = view.toMap(ktop,ktlft);
          console.log("Lat: " + point.getLatitude() + ", Lon: " + point.getLongitude());
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Cam,

  So elem1 and elem2 are html element that are positioned on or over the view?

0 Kudos
CamCode
Regular Contributor

Yes, I just used short hand variables. It is a draggable div element directly over the full screened map.

      const view = myAPP.mapview
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Cam,

   The toMap method is expecting an object with x and y.

view.toMap({x:ktop,y:ktlft});

Try that