Sunday, 23 December 2018

arcgis server - Zooming into a particular polygon


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 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?



Answer



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");

}

}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...