Select to view content in your preferred language

Change what features are displayed during runtime

977
6
10-06-2010 04:25 AM
BrianPangtay
Regular Contributor
Say that one is using the US_States layer. Initially, one would display all the states. Then, the user would like to only show states that begin with a certain string. For example, one wants the Where clause to be "STATE_NAME LIKE "NORTH%" to display only states that begin with NORTH in the name without displaying the other states.

In ArcMap, this kind of problem is solved via a Query Definition. FeatureLayer's have a property called Where that serves the same function. Can one change a FeatureLayer's Where clause during runtime?

If not, how does one display only those features that meet certain attribute criteria?

Thanks for your help.
0 Kudos
6 Replies
DarinaTchountcheva
Frequent Contributor
Hi bpangtay,

Yes, you can change the where clause of the FeatureLayer at runtime. All you have to do is:

FeatureLayer fLayer = Map.Layers["queryLayer"] as FeatureLayer;
string where = "STATE_NAME LIKE 'NORTH%'";
//set the where clause of the feature layer 
fLayer.Where = where;
fLayer.Update();


And if you need to manipulate the Graphics on the layer after they have been updated, you can handle the UpdateCompleted event.

Good Luck!
0 Kudos
BrianPangtay
Regular Contributor
That's exactly what I needed.

Thanks so much.
0 Kudos
JasonThiel
Emerging Contributor
That sounds easy enough but what if you are dealing with thousands of features?  For example gas stations.  Initially, the query layer is off.  The user uses a "widget" to check a box to enable gas stations layer.  The user then chooses "Exxon" from a drop box of 10 gas stations.
This would send "where name = exxon" to the server?  or does the server return all gas stations and the client side selects all Exxon stations from the full list?

In the state example below, all states are first returned then the user updates the where clause.  FLayer.update() must call the service, right?
0 Kudos
DarinaTchountcheva
Frequent Contributor
Jason,

To see what features you will get back and how Update works exactly, please go to the API reference:

http://help.arcgis.com/en/webapi/silverlight/apiref/api_start.htm

Find the FeatureLayer in the Client assembly, and review its Mode property and Update method.

The FeatureLayer has also a Geometry property that you can use to apply a spatial filter and show only the Exxon gas stations in Texas, for example.
0 Kudos
JasonThiel
Emerging Contributor
Yikes!  I didn't realize this was silverlight.

Does Flex work similarly?

My gas station example illustrates what I need to do for about 5 different feature layers.  I've search desktop client documents, arc server docs, and esri flex area but can't seem to locate anything that really talks about "user defined criteria" to a query layer.  Am i missing something obvious?

thanks in advance.
0 Kudos
DarinaTchountcheva
Frequent Contributor
LOL

The Flex API works similarly.
Here is the link to the Flex resourses:

http://help.arcgis.com/en/webapi/flex/index.html

I would recommend downloading the Flex Viewer in the Quick Links on the right site of the page.
It has configuration files that you can configure to fit your data, and you don't have to do any programming. There are also a lot of custom widgets created by the community and I am pretty sure there is an Attribute Query widget you can use, if it is not built in the viewer already. Sorry, I haven't played with the viewer for a while.

Good Luck!
0 Kudos