Zoomto FeatureLayer

736
4
04-29-2013 05:27 AM
gabrielvazquez
New Contributor
I sort of had two questions regarding featurelayers, wanted to see if anyone could help me out.

First off, I'm trying to do a simple zoomto or set extent to a featurelayer with a setdefinitionexpression. I'm using the feature hover layer as a starting example: http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/fl_hover.html. However I'm not defining the map initial extent, I was hoping to define the extent of the map based on the specific state defined in the feature layers definitionexpression and zoom to the featurelayer extent. So, basically page would load to specific state, ex: State="Maryland" and map would zoom to the polygon maryland, without a table, any user input, or by defining specific map extent before hand as is done in the example above.

I was able to get something like this working using a specific set of coordinates I defined, then by passing those coordinates into a graphic, then resetting the map extent to read the graphic points. However,  I was trying to keep this simple and use a featurelayer from our ArcGIS Server. Does anyone have any recommendations for how to simply zoom to a feature layer polygon.

Second question I believe is a bit simpler, does the featurelayer setdefenitionexpression option only accept or read text variables. I would much rather use a integer field. Not sure if I have to modify the setdefenitionexpression in some manner for this.

Thanks
0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Gabriel,

Take a look at a similar sample here.  Instead of using a definition query, this sample uses the Query Task.  The Query Task has an onComplete event, which returns a featureSet.  You can set the extent to the featureSet using the esri.graphicsExtent method:

var featureExtent = esri.graphicsExtent(featureSet.features);                    
 map.setExtent(featureExtent);


Also, to answer your second questions, you can use an integer value with the Query Task or setdefenitionexpression
0 Kudos
gabrielvazquez
New Contributor
Thanks for the info, I will try to use the query task and the onComplete event. I routinely use this type of approach with the silverlight apps I build so should work. I will let you know.


Thanks
0 Kudos
gabrielvazquez
New Contributor
Thanks, that works great. I am able to use the query.where option and zoom to a specific state. I wanted to ask you a follow up question though regarding using multiple query tasks. Right now I am querying a state polygon layer we have on our GIS Server. However, in addition to that state polygon layer I also want to query an incident layer we have and show the incidents layer on top of the state layer. so for example show incidents and state = "Maryland".

I guess my question is in regards to how should I do structure the code to handle multiple query tasks. Do I try and create two onComplete events, one for each query task and go from there?

Thanks again for your recommendation,
0 Kudos
SteveCole
Frequent Contributor
Now you're crossing into the realm of dojo.deferredLists in which you specify an list of queries to perform and then once they are all complete, a single callback function is triggered. Take a look at this sample in the API.
0 Kudos