Using Definition Expressions in the AGIS API for Flex to Restrict Feature Display

by | Apr 26, 2010

In the first article in our series on the ArcGIS Server API for Flex we covered some basic concepts including how to create maps and add layers. We covered both tiled and dynamic map service layers. In this brief post you will learn how to apply a definition expression to your dynamic map service layer to restrict the features displayed from a layer.  For instance, in the figure below we are plotting only those counties that suffered a population loss from 2000 to 2007.
Definition expressions are used to display only features that meet certain attribute requirements. As of ArcGIS Server 9.3 layer definitions can only be applied against an instance of ArcGISDynamicMapServiceLayer. As you can see in the code example below the <esri:layerDefinitions> tag, which is a property of ArcGISDynamicMapServiceLayer, is nested inside an instance of this class.
In this case we are applying the layer definition to the ESRI_Census_USA map service which contains the layers you see in the figure below.
What we’ll need to do is create an array of string values for each layer that you see above. This string value is the layer definition that will be applied to the layer. Since there are six layers (0 to 5) in the service we’ll need to define a string value for each layer. For layers that do not need to have a layer definition applied (census block points, census block groups, and states) we will simply create an empty string.
Now let’s spend a few minutes discussing what this code accomplishes. We first create an Array with the <mx:Array> tag. Inside our Array we define one String value for each layer. In the event that you do not want to apply a layer definition to a layer you simply leave the <mx:String> tag empty. In this exercise we are only applying layer definitions to the county layers. Our layer definition query is to find counties where the population was greater in 2000 than it was in 2007. This query needs to be surrounding by a CDATA tag which simply informs the web server that the contents are to be interpreted literally. Without this tag the web server would view the greater than sign (>) as part of either an MXML or HTML tag.
ArcGIS 10 and Version 2.0 of the API for Flex
With the release of version 2.0 of the ArcGIS Server API for Flex at the ArcGIS Server 10 release you will be also be able to apply a definition expression to the new FeatureLayer object.
Next time we’ll examine spatial and attribute queries using the ArcGIS Server API for Flex


Recent Posts

Eric Pimpler
Eric is the founder and owner of GeoSpatial Training Services ( and has over 25 years of experience implementing and teaching GIS solutions using ESRI, Google Earth/Maps, Open Source technology. Currently Eric focuses on ArcGIS scripting with Python, and the development of custom ArcGIS Server web and mobile applications using JavaScript. Eric is the author of Programming ArcGIS with Python Cookbook - 1st and 2nd Edition, Building Web and Mobile ArcGIS Server Applications with JavaScript, Spatial Analytics with ArcGIS, and ArcGIS Blueprints. Eric has a Bachelor’s degree in Geography from Texas A&M University and a Master's of Applied Geography degree with a concentration in GIS from Texas State University.

Sign up for our weekly newsletter
to receive content like this in your email box.