实现zoom to the selected feature之一:了解QueryAttributesTask control

Developing Web Applications with the Web ADF  

QueryAttributesTask control



The QueryAttributesTask control enables you to explicitly define the parameters used to query values in a field.  This control enhances the basic query capability of the SearchAttributesTask.  At runtime, the QueryAttributesTask query can provide a drop down list of preset choices or a textbox for general text entry.  Each query can also utilize a validator to restrict the values entered.  In addition, multiple queries can be grouped together to produce a single result.  Only feature layers in resources provided by a MapResourceManager can be used.  The results are provided as an ADO.NET DataSet to be displayed in a TaskResults control.  
A QueryAttributesTask creates a single query on one map layer. The query may have compound criteria. For example, you can define a query on a cities layer that selects cities with a population greater than a value entered by the user, and with a name that begins with a value entered by the user.

Assembly: ESRI.ArcGIS.ADF.Tasks.dll
Class: ESRI.ArcGIS.ADF.Tasks.QueryAttributesTask
JavaScript libraries: display_common.js, display_dotnetadf.js, display_task.js, display_floatingpanel.js
Using the QueryAttributesTask control

  1. Add supporting controls to the page

    In order to take full advantage of the QueryAttributesTask control, a number of supporting controls must be available.  Set up a Web application with MapResourceManager and Map controls using their discussion topic as a guide. Add a TaskResults control using that control's discussion topics as a guide. At runtime, the TaskResults control will display the results of QueryAttributesTask. Users can then interact with the results to change map extent, display selected features, or re-execute the task. TaskResults also displays a message to the user while the query executes.

    To hide the query form when the application starts up, and to allow the user to call up the form from a link on the page, add a Menu control from the standard ASP.NET Navigation tools, and then add a TaskManager from the ArcGIS Web Controls toolbox group. If you want to display the query form immediately upon application startup, you can skip adding these controls.

    Be sure to set the BuddyControl property of the TaskManager to the Menu control you added. Also set the Map property of the TaskResults control to the Map control you added, if you want users to see results highlighted on the map when selected.
  2. Add a QueryAttributesTask control
    In Visual Studio, display the prepared Web form in design mode, select the Toolbox and expand the ArcGIS Web Controls tab.  Drag and drop a QueryAttributesTask control into the TaskManager control; or, if you did not add a TaskManager control, just drag the QueryAttributesTask onto the page. Your page might resemble the following layout, arranged using a table:

    Web page with QueryAttributesTask 
  3. Set the required properties for the QueryAttributesTask control

    In design mode, click the QueryAttributesTask, which will display the smart tag arrow in the upper right of the control. Click on this arrow to display the smart tag menu. This menu displays common properties that you can set, though others are available in the Properties window for the control.

    QueryAttributesTask smart tag menu

    a. Task results container : Click the first item in the smart tag menu to choose the Task Results container, or click the TaskResultsContainers property button in the Properties window. This brings up the BuddyControl collection editor. Click Add to add an item to the collection. With the TaskResults1 item selected, in the right side of the dialog, click the drop-down list and select the TaskResults control you added earlier. This is where the QueryAttributesTask will place results when the user executes a query.

    QueryAttributesTask result container dialog


    b. Set up the query : Click the second item in the smart tag menu to edit the query, or click the PredefinedQuery attribute button in the Properties window. This opens the query attributes editor form. The editor form allows you to create a query for users to interact with. You can create a simple query with a single value for users to enter, or a complex query with compound criteria. The example shown below queries a layer with two criteria: city name and population size. In this example, cities are found that have a name that starts with the value the user enters, and that have a population greater than a value the user enters.

    QueryAttributesTask query editor

    • In the Resource Manager drop-down list, select the MapResourceManager control added earlier.
    • In the Resource drop-down list, select the resource item that contains the layer you want to allow users to query.
    • In the Layer drop-down list, select the layer that you want users to query.
    • In the Query Entries section, click Add to create a new query clause. This displays the Form Entry Editor. In the Label Text box, enter the text that you want to display to the user for this query item. Next, select the Associated Field from the drop-down list. This is the field that is queried in this query item. Choose the Operator that compares the value entered by the user to the field values. Note that if using 'like', no wildcard character is added by default to the user's value, and partial text values are not matched. You need to modify the where expression with the Custom Where Expression option (see below).
    • Optionally, you may set a default value or create a pick list for users to choose from. The default value displays in the input box. The user may accept this value or change it. If you choose the Show Pick List option, you need to specify a list of items. The user must choose from among these values in a drop-down list. The user cannot enter an arbitrary value if you choose the pick list option. You may enter values manually in the pick list, or click the Get Sample Values button to retrieve the unique values of the field from the layer. Be aware that this can retrieve a very large number of values.
    • You may also choose to validate the user's input. This is recommended both for a better user experience and for filtering out malicious input. Validation can be done with a range of values or using regular expressions. See texts or online resources on regular expressions for information and common regular expressions. You may also include an Error Message to display if the user's input fails validation.
    • When finished setting up the form entry item, click OK to close the dialog. The form entry item will be added to the Query Entries in the Query Attributes Editor.

      QueryAttributesTask form entry
    • If you want to create a compound query with multiple criteria, click Add in the Query Attributes Editor to add additional query form items. For each form entry item you add, the user is prompted to enter a value.
    • By default, multiple form entry items are queried with "and" criteria. In the example above, only cities that match both the name AND the population values entered by the user will be found. To change the concatenation rules to use OR, you must modify the query using the Custom Where Expression option.

    Custom Where Expression: You can use the Custom Where Expression option to create or modify the selection expression. To use this option, check the box on the Query Attributes Editor and then enter or modify the expression in the expression text box. You can use the Insert Field option to insert a field from the layer selected for the query. You can also use the "Insert User Input Placeholder" to add placeholders (e.g., "{0}") for text that users would enter.

    In the example below, the where expression has been modified with the form entry editor so that a wildcard (%) is used to compare the user's value with names in the layer field. In this case, names that begin with the value entered by the user are matched.

    QueryAttributesTask custom where expression

    c. Visibility of the QueryAttributesTask control: If you added Menu and TaskManager controls, you can have the query form not display at startup. Instead, the form displays when the user clicks the query link in the Menu control. To hide the query form at startup, select the QueryAttributesTask control, and in the Property window, set the Visible property to false.
  4. Setting the position of query form

    By default, the QueryAttributesTask form appears in a floating window, which the user may drag to a new position within the Web page. The opening position does not necessarily correspond to its position on the Web page design form. If preferred, the query window may be fixed at a specific position.

    To fix the position of the query form at a specific location, set the position style of the QueryAttributesTask or a containing control or DIV. To set the style, switch the web page from Design view to HTML view in Visual Studio. Find the QueryAttributesTask in the page listing. Insert a style attribute within the control tag, and set its position properties to specific values. Use "position:absolute" to set the query form at an exact position on the page. Use "position:relative" to fix the position relative to its placement to other controls. In the following example, we use relative placement is used to ensure the query window is placed within a table cell:

    <td>
        <esriTasks:QueryAttributesTask style="position:relative;top:5px;left:0px;"
        ID="QueryAttributesTask1" runat="server" ...>
        </esriTasks:QueryAttributesTask>
        <td>

    When fixing the position of the query window, you may want to set the CloseButton, Draggable, ExpandCollapseButton, HeightResizable and WidthResizable properties to false to disallow modifying the query form. Setting Draggable to false disallows moving the query window.
  5. Other properties for QueryAttributesTask

    Some of the properties you may wish to modify for your application include:
    • Title: displayed at the top of the query form to the user. You should change this from the default, which is the ID of the control. Choose a title that describes what the query does. An example would be, "Find cities where...".
    • ButtonText: text for the button the user clicks to execute the query.
    • MaxRecords: maximum number of features found by the query. Default is 50.
    • FeatureSelectionColor: after query results display, and the user checks the box next to a feature, the feature is highlighted with this color on the map.
    • ShowDetailsInTable: whether to display feature attributes in the query results for each feature.
  6. Using the QueryAttributesTask at runtime

    Using the QueryAttributesTask is similar to using the SearchAttributesTask, except that the user sees more text clues for the form items, and multiple entry form items can be added by the site designer. An example of the query form the user might see would be:

    QueryAttributesTask user entry form

    The user enters values for each form item, then clicks Find. The results are displayed in the TaskResults control output. See TaskResults for a discussion and examples of using the results from a query.
posted @ 2007-07-12 14:23  四两  阅读(918)  评论(0编辑  收藏  举报
加油,哥们,现在开始!