take a look on layer definitions property for ArcGISDynamicMapServiceLayer<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags">
<!-- ArcGIS API 3.1 -->
<!-- Adobe SDK 4.6 -->
<s:layout>
<s:VerticalLayout paddingBottom="10"
paddingLeft="10"
paddingRight="10"
paddingTop="10"
gap="10"/>
</s:layout>
<fx:Script>
<![CDATA[
import com.esri.ags.events.LayerEvent;
import com.esri.ags.layers.supportClasses.LayerDefinition;
import mx.collections.ArrayCollection;
import mx.utils.StringUtil;
import spark.events.IndexChangeEvent;
[Bindable]
private var definitions:Array;
[Bindable]
private var visibleLayers:ArrayCollection = new ArrayCollection([1]);
[Bindable]
private var landuseNames:ArrayCollection = new ArrayCollection(
[
"GENERAL COMM. AND OFFICE",
"INDUSTRIAL",
"MULTI-FAMILY RESIDENTIAL",
"PARKS, CEMETERIES, ETC.",
"PUBLIC AND SEMI-PUBLIC",
"SINGLE FAMILY RESIDENTIAL",
"VACANT AND UNDEVELOPED"
]
);
[Bindable]
private var definitionConditions:ArrayCollection = new ArrayCollection(
[
"like",
"equals"
]
);
[Bindable]
private var defPart1:String = "LANDUSE_NAME";
protected function onSetDefinitionClick(event:MouseEvent):void
{
definitions = new Array(); // reset definitions
var layerDefinition:LayerDefinition = new LayerDefinition();
layerDefinition.layerId = 1; // "LandUse"
if (ddlConditions.selectedIndex == 1) // equals
{
layerDefinition.definition = StringUtil.substitute("{0} = '{1}'", defPart1, ddlValues.selectedItem);
}
else // like
{
layerDefinition.definition = StringUtil.substitute("{0} like '%{1}%'", defPart1, txtInput.text);
}
definitions.push(layerDefinition);
// set cursor busy, and restore it after update ended
map.cursorManager.setBusyCursor();
dynamicLayer.addEventListener(LayerEvent.UPDATE_END,
function onUpdateEnd(event:LayerEvent):void {
dynamicLayer.removeEventListener(LayerEvent.UPDATE_END, onUpdateEnd);
map.cursorManager.removeBusyCursor();
});
// update layer
dynamicLayer.refresh();
}
protected function onClearDefinitionClick(event:MouseEvent):void
{
definitions = null; // remove definitions
// set cursor busy, and restore it after update ended
map.cursorManager.setBusyCursor();
dynamicLayer.addEventListener(LayerEvent.UPDATE_END,
function onUpdateEnd(event:LayerEvent):void {
dynamicLayer.removeEventListener(LayerEvent.UPDATE_END, onUpdateEnd);
map.cursorManager.removeBusyCursor();
});
// update layer
dynamicLayer.refresh();
}
protected function onConditionChange(event:IndexChangeEvent):void
{
// switch inputs
if (ddlConditions.selectedIndex == 0) //like
{
txtInput.visible = txtInput.includeInLayout = true;
ddlValues.visible = ddlValues.includeInLayout = false;
}
else
{
txtInput.visible = txtInput.includeInLayout = false;
ddlValues.visible = ddlValues.includeInLayout = true;
}
}
]]>
</fx:Script>
<s:HGroup verticalAlign="middle" gap="10">
<s:Label text="{defPart1}" />
<s:DropDownList id="ddlConditions"
selectedIndex="0"
dataProvider="{definitionConditions}"
change="onConditionChange(event)"/>
<s:TextInput id="txtInput"
width="250"
text="PUBLIC"/>
<s:DropDownList id="ddlValues"
selectedIndex="0"
width="250"
dataProvider="{landuseNames}"
visible="false"
includeInLayout="false" />
<s:Button label="Set definition"
click="onSetDefinitionClick(event)" />
<s:Button label="No definition"
click="onClearDefinitionClick(event)" />
</s:HGroup>
<esri:Map id="map">
<esri:ArcGISDynamicMapServiceLayer id="dynamicLayer"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer"
layerDefinitions="{definitions}"
visibleLayers="{visibleLayers}"/>
</esri:Map>
</s:Application>
layer definition not setwith layer definitionFrom REST API helpDefinition expression allows you to filter the features of individual layers in the exported map by specifying definition expressions for those layers.