Select to view content in your preferred language

How to use definitionexpression in <sublayer>?

2970
16
08-26-2011 12:34 PM
BenKane
Regular Contributor
How do I implement a definition query using definitionexpression in the sublayer tag?  I see that it's possible but I can't find anywhere any sample code or syntax for how to implement this.
Tags (2)
0 Kudos
16 Replies
RobertScheitlin__GISP
MVP Emeritus
Ben,

  You can find the documentation on this here:

http://help.arcgis.com/en/webapps/flexviewer/help/01m3/01m30000000p000000.htm

<sublayer id="1" definitionexpression="ObjectId = 23"/>
0 Kudos
BenKane
Regular Contributor
Robert,
The only documentation there is:

Child tag specific to layers of type dynamic and tiles
<sublayer> supports the following properties:
    * id - the id, usually a number, of the sublayer within the Map Service.
    * popupconfig - URL to the xml configuration file the pop-up window. See Pop-up configuration files for more information.
    * definitionexpression - Limits the data to a subset of the available features in the map service layer. It is similar to the definition query for a layer in ArcMap.


Can sublayers support a popup and a definitionexpression simultaneously?
I have tried the format you specified, grouped with a popup as well as without the popup - neither works to limit the drawing of the feature in the viewer to the specified query.

Here is a sample from my config:

 <operationallayers> 
     <layer label="Tacoma M7.1" type="dynamic" visible="true" alpha="0.75" preload="open"
                   url="http://140.160.114.190/ArcGIS/rest/services/Seismic/Tacoma/MapServer"> 
      <sublayer id="1" definitionxpression="countyname = King" popupconfig="popups/PopUp_DBs_EF_CareFlty.xml"/>
     <sublayer id="2" popupconfig="popups/PopUp_DBs_UTIL_OilFlty.xml"/>


Thanks,
Ben
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ben,


   The secret is going to be the right SQL syntax. You are searching for a string so you need to have king in single quotes.  'King'
0 Kudos
BenKane
Regular Contributor
I thought you might say that...but unfortunately that doesn't help.  I had a brief moment of excitement when I noticed that I had a typo in the config with "definitionxpression" instead of "definitionexpression", but upon changing that still no luck...

I have tried the definitionexpression on other layers as well to avail.

-Ben
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ben,

   I'm not sure what you are doing wrong then... Here is one I got to work just fine on my end.

            <layer label="Louisville Landbase" type="dynamic" visible="true" alpha="0.4"
                   url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer">
                   <sublayer id="1" definitionexpression="LANDUSE_NAME = 'GENERAL COMM. AND OFFICE'"/>
            </layer>
0 Kudos
BrianOevermann
Frequent Contributor
Ben,

Aside from the attribute value quoting, it appears that you simply haven't "closed" the layer tag, although you may have simply not included it in your code sample.

 <operationallayers> 
     <layer label="Tacoma M7.1" type="dynamic" visible="true" alpha="0.75" preload="open"
                   url="http://140.160.114.190/ArcGIS/rest/services/Seismic/Tacoma/MapServer"> 
      <sublayer id="1" definitionexpression="countyname = 'King'" popupconfig="popups/PopUp_DBs_EF_CareFlty.xml"/>
     <sublayer id="2" popupconfig="popups/PopUp_DBs_UTIL_OilFlty.xml"/>
            </layer>
0 Kudos
CharlesHarris
Emerging Contributor
I'm having this same problem.  I know that I've structured my definitionexpression properly because I can place the syntax into the Where portion of the rest query and it returns the records just fine.

Any ideas?
0 Kudos
BrianOevermann
Frequent Contributor
Jeremy,

Can you post the config code that isn't working?  Like Robert, I have been able to get this to work.  My example is below.  I used a service whose feature class has a joined table, so I needed to fully qualify my field name.  Since you are able to query successfully via the REST dialog you have probably taken care of that if it is necessary.

            <layer label="General Data" type="dynamic" visible="true" alpha="0.4"
                   url="http://myServer/ArcGIS/rest/services/General_Mapservices/general/MapServer">
                   <sublayer id="0" definitionexpression="myDB.COI.SiteAddress.BusinessName='TARGET'"/>
            </layer>
0 Kudos
CharlesHarris
Emerging Contributor
Since this is a public service you can try it in your own viewer.  If I put "AGBUR = 'BIA' into the query at http://maps1.arcgisonline.com/ArcGIS/rest/services/USA_Federal_Lands/MapServer/2 it works fine.  I'm not sure what's missing
<layer label="USA Federal Lands - Reservations" type="dynamic" visible="false" alpha=".7"
                   url="http://maps1.arcgisonline.com/ArcGIS/rest/services/USA_Federal_Lands/MapServer"> 
                   <sublayer id="2" definitionexpression="AGBUR = 'BIA'"/> 
            </layer>
0 Kudos