现在的位置: 首页 > 综合 > 正文

使用一个信息窗口显示查询结果

2013年10月03日 ⁄ 综合 ⁄ 共 4248字 ⁄ 字号 评论关闭
其基本原理是叠加一个自定义图层,然后对这个图层进行一个定义好的查询,返回结果也是在这个自定义图层里面显示。

Click Clear Map Overlays to remove the results. You can pan to a new area of the map and click Execute Query again to see a new set of results.

This example contains three JavaScript functions:

  • 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.

    initialize函数定义了所有必要的控制按钮并标明了地图被第一次打开时所用的坐标系和放大水平,从而创建了一幅用户自定义地图;此外还创建了一个MapExtension,以供executeQuery()使用;添加了一个使用rest定义的task并初始化了一个query成员。

    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/Demographics/ESRI_Census_USA/MapServer/1");

    The URL in the constructor references the census block group layer that will be queried. In this case, it's the layer with index number 1 in the ESRI_Census_USA map service. To find the URLs for the layers you want to query in your own maps, use the Services Directory.

    创建query中使用的url是和将要查询的人口调查数据有关的。

  • 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 the POP2000 and POP2007 fields. Finally, the function uses the following line to run the task, thereby executing the query:

    qtask.execute(query, false, mycallback);

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

    执行一个查询,一般需要执行这几步:

    (1)获得地图的bounding box (2)清除其它的叠加图层 (3)建立查询条件 (4)执行查询

    建立查询条件时所使用的参数一般为:

    query.queryGeometry = bounds;

    query.returnGeometry = true;

     query.outFields=["POP2000","POP2007"]; 

    执行查询的代码:

    qtask.execute(query, false, mycallback);//qtask指向一个支持query task的图层(Type: Feature Layer
    这三个参数分别代表:
    query:查询条件
    false:是否返回kml文件
    mycallback:一个函数,此函数在这个查询执行后立即运行

  • The function mycallback uses JavaScript literal class OverlayOptions to define how the result polygons are symbolized. Then the tabs in the info window are configured using the InfoWindowOptions class. The array of contentTabs has a label for the tab and a content string in which you can include HTML. You can use a field name in curly braces (Example: {POP2007}) to get the value of the field for a given feature.

    The MapExtension helper object that was created in the initialize function adds the query result features to the map.

    mycallback: 用一个OverlayOptions类的对象定义结果图形的表示方案,用InfoWindowOptions类的一个对象定义在info窗口中的tabs。contentTabs使用label来定义在tab中显示的文字,并将要显示的结果以HTML的方式放到content中去。     

    最后,使用MapExtention对象将在executequery()中查询的图层以相应的方式(OverlayOptions,InfoWindowOption)添加到地图中去。

抱歉!评论已关闭.