pmiranda
pmiranda

Reputation: 8430

ArcGIS JavaScript API, zoom to extent

I want to move the zoom to an extent.

I have this var:

var extentGeo = esri.geometry.webMercatorToGeographic(map.extent);
console.log('extentGeo', extentGeo);
// { cache: undefined
// spatialReference: {wkid: 4326}
// type: "extent"
// xmax: -70.60487747064096
// xmin: -70.67328452935668
// ymax: -33.42183884025852
// ymin: -33.48435589231657 }

Is there a way to move the map using those extent.xmin, extent.ymin, extent.xmax, and extent.ymax ?

I also have this function to zoom to points with zoom:

zoomToLocationLatLon = function(lat,lng,showPoint,zoom) {
            var pt = new Point(lng, lat);
            if (showPoint === true) addGraphic(pt);
            (zoom) ? zoom : zoom = 15;
            map.centerAndZoom(pt, zoom);
        }

I'm trying to use that function, but I don't know the zoom of the layer, I need a zoom ta fits the whole layer.

Upvotes: 0

Views: 1606

Answers (1)

Below the Radar
Below the Radar

Reputation: 7635

Use the map.setExtent() method:

var extentGeo = esri.geometry.webMercatorToGeographic(map.extent);
map.setExtent(extentGeo);

Upvotes: 1

Related Questions