0

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++){              
       polyId[i]=result[i].feature.attributes["UNIQPOLYID"];
     }

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

2

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
    if(shape.type==='polygon'){
        //get extent
        var featureExtent=shape.getExtent();
        //now zoom to this extent
            map.setExtent(featureExtent);
    }else{
        //not a polygon
        alert("Shape is not a polygon");
    }

}
1

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()
map.zoomToExtent(featureBounds);
0

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()
map.centerAndZoom(center).then(()=>{
  //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.