ArcgisServer9.3 中矩形选择查询的实现(利用Ext控件的AJAX技术)

 

效果同于ArcgisServer9.3 中矩形选择查询的实现(利用callback机制)

 

1、首先加入一个htmlButton控件, 同时实现本博客中的一个下拉列表控件无刷新的控制另外一个下拉列表控件(利用Coolite.Ext控件);例外添加一个Gridview控件并将它放在一个div中,同时将它们放在一个updatepane中;如下所示:

<input id="Button3"type="button"

value="矩形框选" onclick="selectRectangle()" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >

   <ContentTemplate>

       <div id="griddiv" style=" overflow:auto; width:240px; height:300px;" >

         <asp:GridView ID="GridView1" runat="server" AllowPaging="true" AutoGenerateColumns="true" OnPageIndexChanging="GridView1_PageIndexChanging" >

         </asp:GridView>

     </div>

   </ContentTemplate>

 </asp:UpdatePanel>

2、在前台用javascript实现拉一个矩形框的操作,如下:

<script language="javascript" type="text/javascript">

 

//在地图上拉一个矩形框

function selectRectangle() {

    var map = $find('Map1');

   

    map.set_mouseMode(ESRI.ADF.UI.MouseMode.Custom);

   

    map.getGeometry(ESRI.ADF.Graphics.ShapeType.Envelope,useRectangle, null, 'red', '#0000FF', 'crosshair', true);

 

}

 

//获取所画矩形的顶点坐标,并调用后台函数实行矩形选择查询得到查询结果

function useRectangle(inputGeometry) {

    var map = $find('Map1');

    var env = inputGeometry.getEnvelope();

    var griddiv = document.getElementById("griddiv");

 

    var Xmin = env.get_xmin();

    var Ymin = env.get_ymin();

    var Xmax = env.get_xmax();

    var Ymax = env.get_ymax();

   

//调用后台的矩形查询的方法,并返回查询结果result,显示在GridView中

    Coolite.AjaxMethods.QueryRectangle(Xmin, Ymin, Xmax, Ymax, {

        success: function(result) {

            if (result != "") {

                griddiv.innerHTML = result;

            }

        }

});

 

}

</script>

 

3、后台实现矩形框选择的查询代码如下:

[AjaxMethod]

 public string QueryRectangle(double Xmin,double Ymin,double Xmax,double Ymax)

{

 try

 {

    ESRI.ArcGIS.ADF.Web.Geometry.Envelope env = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(Xmin, Ymin, Xmax, Ymax);

 

     string strRes = Session["ResName"].ToString();

     string strLayer = Session["LayerName"].ToString();

 

       ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gisfunctionality = Map1.GetFunctionality(strRes);

             ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = gisfunctionality.Resource;

             bool supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));

 if (supported)

   {

                    ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;

 

         qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)

gisresource.CreateFunctionality( typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);

              string[] lids;

               string[] lnames;

        qfunc.GetQueryableLayers(null, out lids, out lnames);

 

                    ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();

                    spatialfilter.ReturnADFGeometries = true;

                    spatialfilter.MaxRecords = 10000;

                    spatialfilter.Geometry = env;

 

  for (int i = 0; i < lids.Length; i++)

    {

       if (lnames[i] == strLayer)

       {

          DataTable datatable = qfunc.Query(gisfunctionality.Name, lids[i], spatialfilter);

       datatable.TableName = gisresource.Name + "_" + lnames[i];

 

      if (datatable.Rows.Count > 0)

      {

string datasetName = string.Format("选择要素 - {0}", datatable.TableName);

                System.Data.DataSet dataset = newSystem.Data.DataSet(datasetName);

            dataset.Tables.Add(datatable);

 

           this.GridView1.DataSource = dataset;

           this.GridView1.DataBind();

            Session["Gridview1"] = dataset;

 

           string returnstring = null;

 

       using (System.IO.StringWriter sw = new System.IO.StringWriter())

           {

                     HtmlTextWriter htw = new HtmlTextWriter(sw);

                    GridView1.RenderControl(htw);

                       htw.Flush();

                    returnstring = sw.ToString();

           }

           return returnstring;

                               

      }

     else

      {

        return "未查询到任何信息!";

      }

                         

    }

                       

      }   

     }    

    }

  catch (Exception ex)

   {

            SystemLog.WriteLog("矩形选择要素出错!", ex);

   }

return "未查询到任何信息!";

}

4、另外GridView分页的实现参照本博客其他文章。这样就实现了矩形选择查询,仔细体会吧。

转载于:https://www.cnblogs.com/tuncaysanli/archive/2009/02/13/1390302.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值