Query widget

This page describes an older version, please read about the latest version at:
http://resources.arcgis.com/en/help/flex-viewer/concepts/

The Query widget enables end users to query information from a map service by executing a pre-defined query. The Viewer application configurer and/or Web application designer would pre-create the query and enable it within the Query widget. From an end user perspective, executing the query is simple and is performed with a single button click. It is designed to work on a single layer.

Defining a Query

The query used in the Query widget is defined in its configuration file. Three items need to be specified:

  1. The layer to apply the query on.
  2. The query statement, for example
    ADDRESS like '%AVE'
    
    (default is 1=1 which will return all features).
  3. The attribute fields to retrieve for the returned features that satisfy the query. You can either specify the exact fields to use or ask for all fields to be returned.

Below is the Query widget XML configuration file code sample that specifies the three items above:

<configuration>
    <layer>URL address of layer to apply query on</layer>
    <query>Query statement</query>
    <fields all="true"></fields> <!-- when all="true", it means retrieve all fields -->
    ...
</configuration>

Query Example 1

In the Viewer application (default setting), a Query widget has been configured to query the Louisville Public Safety map service for police stations. The widget is called Louisville Police and located in the widget tray in the Viewer UI. When the Query widget is activated, the query immediately executes and returns a result set in the widget dialog, shown in the graphic below.

Screenshot of Query widget

The XML sample code below is from the Louisville Police widget's configuration file.

...
<layer>http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_PublicSafety_Louisville/MapServer/3</layer>
<query>1=1</query> <!-- 1=1, means select all features -->
    <fields all="false"> <!-- all="false" means it does not get all fields, only the fields specified below -->
        <field name="PD_NAME"/>
        <field name="ADDRESS" alias="Address"/>
    </fields>
...

When an item in the returned result list is selected in the widget dialog, the map display zooms to its location. In this example, the map centers on the location of the selected police station in the City of Louisville, KY. A symbol (in this case, the Louisville Police widget icon) is placed at its location on the map with an Info Popup window containing some the returned attribute fields from the query.

Clicking the Filter results button allows end users to filter the Query widget's returned result list based on a pre-defined filter (e.g., based on an attribute). The filter is defined by the <filterresults> tag in the widget configuration file. In this example, it is the Address field.

Query Example 2

Another Query widget example can be found in the config-all.xml Viewer application configuration file, which is available in the flexviewer installation directory. This query widget is called Traffic Camera and queries the Louisville Public Safety map service to find traffic cameras around the city.

In addition to the traffic camera locations, this widget also displays the current traffic camera video feed in the Info Popup window associated with each returned feature.

The XML sample code below is from the Traffic Camera widget's configuration file.

...
<layer>http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_PublicSafety_Louisville/MapServer/3</layer>
<query>1=1</query> <!-- 1=1, means select all features -->
    <fields all="false"> <!-- all="false" means it does not get all fields, only the fields specified below -->
        <field name="DESCRIPTION"/>
        <field name="URL"/> <!-- URL address of the camera video feed -->
        <field name="LAST_UPDATED" alias="UPDATED"/>
    </fields>
...

Conceptual Workflow

Requires: map or feature service layer

Test drive the Query widget or read its tag reference.

2/15/2012