0

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.

1

1 Answer 1

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.