Select to view content in your preferred language

Zoom to Feature

1124
4
10-12-2012 11:38 AM
BrianLeroux
Frequent Contributor
I am new to javascript and am looking for a little guidance as to zooming to a single point in a feature layer.

I am adding a layer to my map that will only have 1 record based on an input field. I would like to center and zoom to that point when the app initializes and then when someone changes the value and clicks submit. For the life of me I can figure out how to zoom to the point that is in that layer. Here is my code to add the layer. Any suggestions? I've tried many things including querying the layer and zooming to the extent of the results with no luck. Please help.

HOPolicies = new esri.layers.FeatureLayer("http://webmapping/ArcGIS/rest/services/Policies/PoliciesSDE/MapServer/0", { 
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: ["*"] 
 }); 
temp = input.value
HOPolicies.setDefinitionExpression("POLICY_NO = '" + temp +"'");
map.addLayers([HOPolicies]);
0 Kudos
4 Replies
DouglasHall
Occasional Contributor
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/map.htm

dojo.connect(map, 'onLoad', function () {
    //start query and get point
    //map.centerAt(myPoint);
    // or
    //map.centerAndZoom(myPoint,12);
});
0 Kudos
BrianLeroux
Frequent Contributor
Thanks Douglas.

How do i assiggn myPOint to the one record in my feature layer? I have tried using the methods you mention but can't seem to pass hte correct data to get it to work properly.
0 Kudos
DouglasHall
Occasional Contributor
dojo.connect(map, 'onLoad', function () {
    var query = new esri.tasks.Query();
    var queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyFeedSample/MapServer/0");
    query.where = "OBJECTID > 0";
    query.returnGeometry = true;
    query.outFields = ["*"];
    queryTask.execute(query, function (results) {
        map.centerAndZoom(results.features[0].geometry, 12);
    }, function (error) {
        console.log(error);
    });
});
0 Kudos
AndrewBrown1
Deactivated User
I'm doing something very similar; however, i'm using a featureLayer and setting the definitionExpression. I would like to zoom to the features in my featureLayer that satisfy my definitionExpression. Is this possible?
0 Kudos