1

How can I retrieve the maximum and minimum latitude and longitude of the current view using the arcGIS javascript API (4.x)?


I can get the center lat and lon by using:

MapView.center.latitude and MapView.center.longitude.

I can also get the height and width in pixels using:

MapView.height and MapView.width.

However, I can't convert the pixel size to a lat/lon as the MapView.resolution property is 0. The MapView.extent is also null.


I am asking as I would like to query a database and only get the entries with a latitude and longitude within the view to save having to draw every point.

1 Answer 1

2

You can get the Extent of the MapView, which contains its xmin, xmax, ymin, and ymax values.

To get the extent upon loading the MapView use:

view.on("layerview-create", function() { console.log(view.extent.xmin); console.log(view.extent.xmax); console.log(view.extent.ymin); console.log(view.extent.ymax); });

2
  • Hi, I have tried using view.extent but when I output it via console.log(view.extent) it is null. It does work when I call this when the pointer moves e.g. view.on("pointer-move", function(){console.log(view.extent)}); though. Is there anyway to access the extent as soon as the page loads?
    – Matt Ellis
    Commented Nov 21, 2019 at 14:34
  • Take a look at this blog that shows when things are ready using JavaScript 4.x
    – kenbuja
    Commented Nov 21, 2019 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.