I am getting the polygon id by doing

identifyParams.geometry = evt.mapPoint;
identifyParams.mapExtent = map.extent;
identifyTask.execute(identifyParams, function(result) { 
     var i;
     var polyId= new Array();
     for(i=0; i<result.length;i++){              

I want to zoom in to the polygon when the value of i is 1. How will I zoom in to that particular polygon?


You need to get the geometry of the feature, and then zoom to it's extent.

I would use a function like this:

function ZoomTofeature(feature){
//get the geometry of the feature
var shape=feature.geometry;
//check if geometry is polygon
        //get extent
        var featureExtent=shape.getExtent();
        //now zoom to this extent
        //not a polygon
        alert("Shape is not a polygon");


You may just zoom to the feature's geometry bounds. It also works for other type of features.

//Assume the polyFeature is the feature you want to zoom to.
var featureBounds = polyFeature.geometry.getBounds()

You may also use the centerAndZoom API, this method accepts an argument of type mapPoint. You can get the centroid of a polygon by chaining getCenter() after getExtent()

var center = feature.geometry.getExtent().getCenter()
  //do something

The API Reference gives an example in another method description, see toScreen(mapPoint) https://developers.arcgis.com/javascript/3/jsapi/map-amd.html

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.