Display query results in kml format

Source: Internet
Author: User
Tags javascript extension
Description

This example shows how to return query results as kml. kml is an XML-based format for representing features and attributes. it's commonly used in Google maps and other geographic applications. returning query results in kml preserves the symbology originally set by the map author.

To run this example, pan to an area of the map click execute query. all of the highway features in the map extent will be overlaid on the map as a geoxml overlay (kml ). you can click a road segment to display an info window with attributes.

Click Clear map overlays to remove the kml features. Optionally, you can navigate to a new area of the map and execute the query again.

  • TheInitializeFunction sets up the map, adding all of the necessary controls and specifying the coordinates and zoom level that the map shocould use when the page opens. this function also creates a new mapextension that will help display the results.

    To prepare for the query, the function creates a new querytask, a class specific to the ArcGIS JavaScript extension. The URL of the map layer to be queried is passed to the querytask constructor:

    qtask = new esri.arcgis.gmaps.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Speciality/ESRI_StateCityHighway_USA/MapServer/0");

    The URL in the constructor references the highway layer that will be queried. in this case, it's the layer with index number 0 in the esri_statecityhighway_usa map service. to find the URLs for the layers you want to query in your own maps, use the Services Directory.

  • TheExecutequeryFunction runs when someone clicks the execute query button. this function gets the bounding box of the map, removes any existing overlays, and sets up the query conditions. it tells the query to return information from the length, type, admn_class, toll_rd fields. finally, the function uses the following line to run the task, thereby executing the query:

    qtask.execute(query, true, mycallback);

    The three arguments represent 1) the query conditions, 2) whether to return a ggeoxml overlay (kml), and 3) a callback function that runs immediately after the query is executed.

  • The callback functionMycallbackAdds the query results to the map, using the Helper mapextension class that was created in the initialize function.
  • From the code perspective, when using the kmlformula and using its own formula, you only need to set whether to return the kml item in qtask.exe cute () to true when using kml, and then add the kml type parameter to the map directly in mycallback.
  • In terms of the effect, the visual effect of the kml query results is better. Because kml is based on XML, I guess the loading speed of kml may be faster, but I didn't verify it, it's just speculation.

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.