In-depth introduction to Javascript API (V)-Query & Find queries

Source: Internet
Author: User
Query is one of the common functions of webgis. map-based query has evolved in many forms. Currently, there is no fixed mode for displaying the query in what form, which is suitable for webgis, what forms can meet the needs of applications. For example, to describe the most typical scenario, click the map to display a TIP small window, showing the simple information of the query object, the small window provides a "details" link, click it to display the data card on the webpage. There is also such a form, such as a drop-down box to select the point element, and the DIV below the map shows the property information of the Choice Point, this in the [url =] ArcGIS Server Development Series (5) -- The Custom Toolbar tool [/url] is implemented through the ADF. How can the Ags Javascript API complete these functions?
Content directory:

1. Query property data (no map)
2. Move the mouse to display Query results
3. Find to query the map and display the corresponding property data at the bottom of the page.

1. you can only Query attributes without returning map information. In this case, you do not need to create an esri. layers. arcGISMapServiceLayer object to process the map, but you need to introduce "esri. tasks. query, and create a QueryTask object:
QueryTask =
New esri. tasks. QueryTask ("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5 ");

A webgis query generally involves parameters that determine the returned results, including whether to return ry, The queried attribute fields, the query method ("SPATIAL_REL_INTERSECTS" by default), and The Where statement, for example:
Query =
New esri. tasks. Query ();
Query. returnGeometry =
False;
Query. outFields = ["SQMI", "STATE_NAME", "SUB_REGION", "POP2000", "POP2007", "MALES", "FEMALES"];

Execute the query and write the result to the callback function showResults:
Function execute (stateName ){
Query. text = stateName;
QueryTask.exe cute (query, showResults );
}

All the results will be written to the showResults parameter Featureset object, traversing this object to get the desired property results.

Query Method:

2. moving the mouse to display Query results is one of the common Query methods. The most important thing is to use Ajax asynchronous transmission to display a small amount of information in a Tip, with high access efficiency, good experience. Here, we can decide whether to specify a layer area element for hover query by default, or click the element to be queried, and then query by hover. The former is used as an example, and the other methods are similar.

The query function mainly includes the following code lines:
Var queryTask =
New esri. tasks. QueryTask ("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3 ");
Var query =
New esri. tasks. Query ();
Query. returnGeometry =
True;
Query. outFields = ["NAME", "POP2000", "POP2007", "POP00_SQMI", "POP07_SQMI"];
Query. where =
"STATE_NAME = 'South Carolina lina '";

The difference between "query. text" and "query. where" is that the former executes the where query using the "like" method, and the latter directly writes an SQL statement.

Tip ui is an InfoWindow
Var infoTemplate =
New esri. InfoTemplate ();
InfoTemplate. title =
"$ {NAME }";
InfoTemplate. content =
"<B> 2000 Population: </B >$ {POP2000} <br/>"
+
"<B> 2000 Population per Sq. Mi.: </B >$ {POP00_SQMI} <br/>"
+
"<B> 2007 Population: </B >$ {POP2007} <br/>"
+
"<B> 2007 Population per Sq. Mi.: </B >$ {POP07_SQMI }";
Map. infoWindow. resize (205,125 );

After the mouse moves to the specified area, the query TIPs is displayed or hidden by the onmousemove and onmouseout events.
Dojo. connect (map. graphics, "onMouseOver", function (evt ){
Var content = evt. graphic. getContent ();
Map. infoWindow. setContent (content );
Var title = evt. graphic. getTitle ();
Map. infoWindow. setTitle (title );
Evt. graphic. setSymbol (highlightSymbol );
Map. infoWindow. show (evt. screenPoint, map. getinfo1_wanchor (evt. screenPoint ));
});

Dojo. connect (map. graphics, "onMouseOut", function (evt ){
Map. infoWindow. hide ();
Evt. graphic. setSymbol (symbol );
});

3. find Query, similar to the Query function, but different from the REST service, Query Needs to specify a specific REST layer service, such as "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3 ", while Find only needs to provide the current map service "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer", and then through properties to control which layer to Find.
FindTask =
New esri. tasks. FindTask ("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer ");
FindParams =
New esri. tasks. FindParameters ();
FindParams. returnGeometry =
True;
FindParams. layerIds = [0, 1, 2];
FindParams. searchFields = ["CITY_NAME", "NAME", "SYSTEM", "STATE_ABBR", "STATE_NAME"];

In this way, you can easily query multiple layers. js Code only needs to set layerIds and add "dojo. require ("esri. tasks. find ");". The Query results are displayed at the bottom of the page. Ajax is used to refresh the page. dojox. grid can be used to complete this process. The Find search can only be in the like mode and is case-insensitive. This is another difference from Query.

Blog garden link: http://www.cnblogs.com/flyingis/archive/2008/07/29/1255373.html

This topic is highlighted by flyingis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.