使用kml格式显示查询结果

  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的加载速度也许也会快一些,但我没有验证,只是猜测而已。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值