0

I am using the ArcGIS API for JavaScript.

Right now, I am trying to change the extent of a view dynamically.

<script>
    var view;
    var new_ext;

    require([
        "esri/views/MapView",
        "esri/WebMap",
        "esri/geometry/Extent",
        "dojo/on",
        "dojo/domReady!"
    ], function (MapView, WebMap, Extent) {
        var webmap = new WebMap({ portalItem: { id: "fedda3...." } });
        view = new MapView({
            map: webmap,
            container: "mapdiv",
            center: [-102.45, 47.75],
            zoom: 10
        });

        // Set the extent on the view
        view.extent = {
            xmin: 17.265, 
            ymin: 21.99, 
            xmax: 17.314, 
            ymax: 21.964,
            spatialReference: { wkid: 4326 }
        };
        new_ext = new Extent();    

    });

    function react_to_event() {

        // will be loaded by ajax later on
        new_ext = {
            xmin: 17.065, 
            ymin: 21.79, 
            xmax: 17.114, 
            ymax: 21.764,
            spatialReference: { wkid: 4326 }
        };

        view.goTo(new_ext);
    }         
</script>

function react_to_event() is just returning an "undefinied". What would be the right approach to animate the view to an other extent?

1 Answer 1

2

The Extent you are trying to send as the input to view.goTo(...) is not valid since you cannot autocast xmin, ymin, xmax, and ymax according to the documentation (see that there is only the "autocast" keyword on the spatialReference property - not on xmin, ymin, etc).

So instead of autocasting you should include the Extent module in your AMD includes:

require([
  "esri/Map",
  "esri/views/SceneView",
  "esri/views/MapView",
  "esri/geometry/Extent",
  "dojo/domReady!"
],
function(Map, SceneView, MapView, Extent) {

And then use the traditional "constructor-style" way to create the extent:

var new_ext = new Extent({
  xmin: 17.065, 
  ymin: 21.79, 
  xmax: 17.114, 
  ymax: 21.764,
  spatialReference: { wkid: 4326 }
});

Full working example here.

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.