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

其基本原理是叠加一个自定义图层,然后对这个图层进行一个定义好的查询,返回结果也是在这个自定义图层里面显示。

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)添加到地图中去。

    <script type="text/javascript"> var gmap = null; var qtask = null; var query = null; var mapExtension = null; var gOverlays = null; function initialize() { // GMap construction gmap = new GMap2(document.getElementById('gmap')); gmap.addMapType(G_NORMAL_MAP); gmap.addMapType(G_SATELLITE_MAP); gmap.addControl(new GLargeMapControl()); gmap.addControl(new GMapTypeControl()); gmap.setCenter(new GLatLng(33.97142760360439, -117.3805046081543), 17); // RIVERSIDE (Polyline, Polygon) gmap.enableScrollWheelZoom(); //Create MapExtension utility class mapExtension = new esri.arcgis.gmaps.MapExtension(gmap); // Query Task qtask = new esri.arcgis.gmaps.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/1"); GEvent.addListener(qtask, "complete", function() { //console.debug("'query task complete' event fired!!!"); }); // Query query = new esri.arcgis.gmaps.Query(); } function executeQuery() { var cent = gmap.getCenter(); var bounds = gmap.getBounds(); // clear gOverlays overlays and event listeners mapExtension.removeFromMap(gOverlays); // set query parameters query.queryGeometry = bounds; query.returnGeometry = true; query.outFields = ["POP2000","POP2007"]; // execute query task qtask.execute(query, false, mycallback); } function mycallback(fset) { //JS literal class esri.arcgis.gmaps.OverlayOptions var overlayOptions = { strokeColor:"#FF0000", strokeWeight:3, strokeOpacity:0.75, fillColor:"#000066", fillOpacity:0.4 }; //JS literal class esri.arcgis.gmaps.InfoWindowOptions with tabs var infoWindowOptionsTabs = { contentTabs:[{label:"POP2000", content:"

    The Value of attribute /"POP2000/" is {POP2000}"}, {label:"POP2007", content:"

    The Value of attribute /"POP2007/" is {POP2007}"} ], selectedTab:0 } gOverlays = mapExtension.addToMap(fset,overlayOptions,infoWindowOptionsTabs); } </script>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的学生查询窗口示例: 首先,我们需要在WinForm窗口中添加以下控件: - 一个Label用于显示“学号”文本 - 一个TextBox用于输入学号 - 一个Button用于触发查询操作 - 一个DataGridView用于显示查询结果 代码如下: ```csharp public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // 设置DataGridView的列头 dataGridView1.Columns.Add("Name", "姓名"); dataGridView1.Columns.Add("Age", "年龄"); dataGridView1.Columns.Add("Gender", "性别"); } private void button1_Click(object sender, EventArgs e) { // 获取学号输入框中的值 string studentID = textBox1.Text; // 根据学号查询学生信息 // 这里省略查询操作,直接模拟查询结果 DataTable dt = new DataTable(); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Age", typeof(int)); dt.Columns.Add("Gender", typeof(string)); dt.Rows.Add("张三", 18, "男"); dt.Rows.Add("李四", 19, "女"); // 将查询结果显示在DataGridView中 dataGridView1.Rows.Clear(); foreach (DataRow row in dt.Rows) { dataGridView1.Rows.Add(row["Name"], row["Age"], row["Gender"]); } } } ``` 在窗口加载时,我们通过代码添加了DataGridView的列头,用于显示查询结果。当用户点击查询按钮时,我们从学号输入框中获取学号,然后执行查询操作(这里省略了实际的查询操作,直接模拟了查询结果),将查询结果显示在DataGridView中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值