Select to view content in your preferred language

Definition Query is not working

3782
12
06-11-2010 06:16 AM
FaisalBukhari
Deactivated User
Hi

Definition query is not working no error nut map is not refresh

here is code

var dynLay:ArcGISDynamicMapServiceLayer = myMap.getLayer("Region") as ArcGISDynamicMapServiceLayer;

var layerDefArr:Array=new Array();

var qry:String= new String();
qry="OBJECTID=1";
layerDefArr[0] = qry;

dynLay.layerDefinitions = layerDefArr;

dynLay.refresh();


any idea   Thanks in Advance
Tags (2)
0 Kudos
12 Replies
RobertScheitlin__GISP
MVP Emeritus
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>
0 Kudos
DasaPaddock
Esri Regular Contributor
Just a small clarification... you don't actually need to create empty strings at unused indexes. It's OK to use a sparse array like this:

<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>
0 Kudos
DavideRodomonti1
Deactivated User
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>


Hi Robert, do u have a widget for sample flex that do the same?

David
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
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.
0 Kudos
FaisalBukhari
Deactivated User
Thanks Robert you always

helpful
0 Kudos
DavideRodomonti1
Deactivated User
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.


Thank u Robert, I need it cause I would like to filter my layer and the map has to show me a part of this layer.

David
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
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.
0 Kudos
DavideRodomonti1
Deactivated User
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
0 Kudos
DavideRodomonti1
Deactivated User
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


Robert, can u help me?
0 Kudos