使用kml格式顯示查詢結果

來源:互聯網
上載者:User
 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.

  • The initialize function sets up the map, adding all of the necessary controls and specifying the coordinates and zoom level that the map should 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.

  • The executeQuery function 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 function mycallback adds the query results to the map, using the helper MapExtension class that was created in the initialize function.
  • 從代碼上看,使用kml的方式和使用其它方式的不同之處僅在於使用kml時需將qtask.execute()中的是否返回kml項設為true,然後在mycallback中直接將kml類型的參數添加入地圖即可。
  • 在效果上看,kml這種方式的查詢結果視覺效果更好,由於kml是基於xml的,我猜kml的載入速度也許也會快一些,但我沒有驗證,只是猜測而已。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.