How to convert the extent of Mapview to lat/lon?

04-21-2020 01:39 AM
New Contributor

Hi, guys.

I have got the extent of the map view from its extent property. As I need to load the data async from the backend when the user drags the map, so every time after user drag and stops, I need to send an API to the backend, which takes the current map lat/long on the four corners of the screen to the params of the API. I find the extent of the Mapview property, but its format is different from the lat/long. Is there any way or API to get the suitable lat/long of the four corners of the screen on the map?

Thank you.

Tags (1)
0 Kudos
2 Replies
Esri Regular Contributor

Hi Lucas Liu‌,

You can re-project your extent to spatial reference wkid 4326. That is lat/long.

I assume you are using arcgis js 4.xx

Here is my sample code of view extent change with reprojection  - 

And here are some help reference

projection | ArcGIS API for JavaScript 4.15 

GeometryService | API Reference | ArcGIS API for JavaScript 3.32 

0 Kudos
MVP Esteemed Contributor


 An even simpler way than Than suggests (assuming you are using an ESRI Basemap) is to use WebMercatorUtils to convert the view which is in WebMercator (WKID 102100) to Geographic (WKID 4326). 

require(["esri/geometry/support/webMercatorUtils"], function(webMercatorUtils) {
  var latLonExtent = webmercatorUtils.webMercatorToGeographic(view.extent);
  var xMin = latLonExtent.xmin;
  var yMin = latLonExtent.ymin;
  var xMax = latLonExtent.xmax;
  var yMax = latLonExtent.ymax;
0 Kudos