I have a text box where I have the polygon Id like, "id_of_the_polygon_12345"
. Is it possible to get its extent and zoom onto it? I have figured out how to do it upon clicking on the map. But could not figure how to do the same knowing my poly Id.
-
1create a query task to return geometry.On task success complete, set map extent to the geometry.You will find more help on this link developers.arcgis.com/en/javascript/jsapi/querytask.html .– GunnerCommented May 27, 2013 at 8:10
Add a comment
|
1 Answer
I created a QueryTask and obtained the geometry of the feature. I then assigned the feature extent to the map extent so that it appears zoomed.
function searchGeometry(polyId){
//building a query
queryTask = new esri.tasks.QueryTask("URL_OF_THE_SERVICE");
//build query filter
query = new esri.tasks.Query();
query.returnGeometry = true;
query.where = "UNIQPOLYID = '" + polyId + "'";
queryTask.execute(query, queryResults);
}
function queryResults(featureSet){
var resultSet = featureSet.features;
var geom = resultSet[0].geometry;
//Convert the geographic geometry to WebMercator Geometry so that it can be set to my map.
var shape = esri.geometry.geographicToWebMercator(geom);
//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 you selected is not a polygon");
}
}