0

I am trying to set the extent for my ArcGIS map using the JavaScript API built in. Here's my code:

              const [Extent] = await loadModules(["esri/geometry/Extent"]);
              let response = new Extent();
              for (const datum of dataPoints) {
                let resExtent = new Extent(
                  datum.latitude,
                  datum.longitude,
                  datum.latitude,
                  datum.longitude,
                  response.spatialReference
                );
                response = await response.union(resExtent);
              }
              viewRef.current.goTo(response);

And my datum list is an array of coordinates such as: [..., {latitude: XXX, longitude: XXX}, ...]. The above code plots the coordinates on the map but the extent is not correct with issues like some points lie in the boundary of the map.

How can I resolve this issue ?

4
  • What are the spatial reference of the extent and the map? Dec 13, 2021 at 14:56
  • 1
    Could you explain (maybe a screenshot) what you mean with "the extent is not correct with issues like some points lie in the boundary of the map"? Do you just need the map to zoom out a little bit? Dec 14, 2021 at 6:15
  • Yes @BjornSvensson you are correct...I need to zoom out a bit to actually see those points. Also the points are not getting placed exactly at the center of my map....they are displaced somewhat towards left
    – Dragon
    Dec 14, 2021 at 11:04
  • Have you viewed Arcgis developers page? Here is the link: developers.arcgis.com/javascript/3/jshelp/intro_extents.html
    – Xi Jin
    Dec 15, 2021 at 7:57

1 Answer 1

1

You can expand your Extent a little to make sure that it zooms out a bit more. See https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Extent.html#expand viewRef.current.goTo(response.clone().expand(1.5));

Another aspect is that by default, the mapView will "snap" to the different zoom levels. It's possible that this snaps to a zoom level too far zoomed in. You can turn off this "snap to zoom" behavior by setting the constraints.snapToZoom to false when you create the mapView. See https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#constraints

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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