<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:esri="http://www.esri.com/2008/ags"
layout="absolute"
styleName="plain"
pageTitle="Definition Query">
<mx:Script>
<![CDATA[
private function test():void
{
var dynLay:ArcGISDynamicMapServiceLayer = myMap.getLayer("Region") as ArcGISDynamicMapServiceLayer;
var layerDefArr:Array=new Array();
var qry:String= new String();
qry="OBJECTID=1";
layerDefArr[0] = "";
layerDefArr[1] = "";
layerDefArr[2] = "";
layerDefArr[3] = "";
layerDefArr[4] = "";
layerDefArr[5] = qry;
dynLay.layerDefinitions = layerDefArr;
dynLay.refresh();
}
]]>
</mx:Script>
<esri:Map id="myMap">
<esri:extent>
<esri:Extent xmin="-122.2" ymin="24.89" xmax="-70.59" ymax="46.92">
<esri:SpatialReference wkid="4326"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer
url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:ArcGISDynamicMapServiceLayer id="Region" name="Region" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"/>
</esri:Map>
<mx:Button x="41" y="536" label="Button" click="test()"/>
</mx:Application>
<mx:Script>
<![CDATA[
private function test():void
{
var dynLay:ArcGISDynamicMapServiceLayer = myMap.getLayer("Region") as ArcGISDynamicMapServiceLayer;
var layerDefArr:Array = new Array();
layerDefArr[5] = "OBJECTID=1";
dynLay.layerDefinitions = layerDefArr;
}
]]>
</mx:Script>
Faisal,
The definition query array needs to have a query string for each layer in the map service even if the query string is just an empty string. Here is a working example. Wait for the states and counties to draw and when you click the button the only state that will draw it's boundary is Washington.<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:esri="http://www.esri.com/2008/ags" layout="absolute" styleName="plain" pageTitle="Definition Query"> <mx:Script> <![CDATA[ private function test():void { var dynLay:ArcGISDynamicMapServiceLayer = myMap.getLayer("Region") as ArcGISDynamicMapServiceLayer; var layerDefArr:Array=new Array(); var qry:String= new String(); qry="OBJECTID=1"; layerDefArr[0] = ""; layerDefArr[1] = ""; layerDefArr[2] = ""; layerDefArr[3] = ""; layerDefArr[4] = ""; layerDefArr[5] = qry; dynLay.layerDefinitions = layerDefArr; dynLay.refresh(); } ]]> </mx:Script> <esri:Map id="myMap"> <esri:extent> <esri:Extent xmin="-122.2" ymin="24.89" xmax="-70.59" ymax="46.92"> <esri:SpatialReference wkid="4326"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/> <esri:ArcGISDynamicMapServiceLayer id="Region" name="Region" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"/> </esri:Map> <mx:Button x="41" y="536" label="Button" click="test()"/> </mx:Application>
David,
Nope I don't see much sense in creating a widget for this as one would probably only use a definition query in very limited circumstances.
David,
You would not want a widget with a user interface on the screen for this ability to use a definition query on one layer though (at least I would not). You can easily add code like the sample demonstrates to the MapManager.mxml and then you would not have a need for a widget.
Thanks Robert, I better explain what I need....I have a geodatabase with plans NOT georeferenced, so they are overlayed ... and I want to build a widget that makes me easy to select which plan I want to see and then show it (and only it) on the map through a definition query...one more thing..Should I use a Spatial Reference? If yes which one should I use? cause plans come from a simple CAD file not georeferenced.
David