ArcGIS Server 9.3 ADF实现定位

(1)启动VS2008,新建一个“Asp.net网站”。

(2)在Default页面中拖入一个MapResourceManager控件,如图1所示。

图1 MapResourceManager控件

(3)单击“Edit Resources",系统弹出MapResourceItem集合编辑器如图2,然后点击“添加”按钮,添加一个地图资源,如图3,并完成相关的配置,配置的步骤这里略。

       

                             图2 MapResourceItem集合编辑器                                                                                                               图3 添加一个地图资源

(4)在Default页面中拖入Map控件,然后在Map控件属性中的“MapResourceManager”选项中上面配置的地图资源服务,如图4。

(5)在Default页面中拖入Toolbar控件,并在Toolbar控件的“BuddyControls”属性中选择第4步骤拖入的Map对象,如图5和图6。

         

               图4 配置Map的地图资源                                                                          图5 Toolbar属性窗口                                                          图6 设置Toolbar的BuddyControl属性

(6)单击Toolbar的“ToolbarItem”属性,如图7,系统弹出“ToolbarCollectionEditorForm”的对话框,如图8。

       

                              图7 ToolbarItem属性                                                                                              图8 ToolbarCollectionEditorForm

(7)把Map Navigation下面的项目全部Add到Current ToolBar Content,然后单击OK。

(8)在Default页面中添加一个输入框和定位按钮以及响应代码等等,代码如下:

    <table><tr>
    <td>请输入市级行政名称</td>
    <td><input id = '输入名称' type="text"/></td>
    <td><input id = 'OkBut' type="button" value="定位" onclick ="javascript:
    SearchPostion();"/></td>
    </tr></table>
    <script language ="javascript" type ="text/javascript">
    function SearchPostion()
    {
    var StrName=document.getElementById('输入名称').value;
    
    if (StrName == '')
    {
    alert('请输入定位的市名称');
    return;
    }
    var context="Map1";
    var message;
    message=StrName;
    <%=sADFCallBackFunctionInvocation%>
    }
    </script>

、(9)在服务器端代码中,编写响应代码,如下:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page, ICallbackEventHandler
{
    public String sADFCallBackFunctionInvocation;
    protected void Page_Load(object sender, EventArgs e)
    {
        //生成客户端脚本段
        sADFCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "message", "processCallbackResult", "context", "postBackError", true);
    }

    #region ICallbackEventHandler 成员
    public void RaiseCallbackEvent(string eventArgument)
    {
        System.Collections.IEnumerable func_enum = null;
        //获取当前Map1控件所有functionality
        func_enum = Map1.GetFunctionalities();

        System.Data.DataTable datatable;
        //对所有的functionality的进行遍历
        foreach (ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gisfunctionality in func_enum)
        {
            ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = null;
            //得到该Functionality的resource
            gisresource = gisfunctionality.Resource;
            //判断该resource是否支持IQueryFunctionality
            bool supported = false;
            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;
                //获得图层的layerID和layerName,GetQueryableLayers的重载方法可以指定图层类型
                qfunc.GetQueryableLayers(null, out lids, out lnames);
                int selindex = -1;
                for (int i = 0; i < lids.Length; i++)
                {
                    if (lnames[i] == "行政区划")//找到行政区划图层
                    {
                        selindex = i;
                        break;
                    }
                }

                //设置过滤器的过滤条件
                ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();
                spatialfilter.ReturnADFGeometries = true;
                spatialfilter.MaxRecords = 100;
                spatialfilter.WhereClause = "名称='" + eventArgument + "'";//名称为行政区划的名称(属性表中的字段)

                //对指定的图层进行查询,查询的结果保存为
                datatable = qfunc.Query(null, lids[selindex], spatialfilter);
                if (datatable != null)
                {
                    if (datatable.Rows.Count > 0)
                    {
                        for (int j = 0; j < datatable.Columns.Count; j++)
                        {
                            if (datatable.Columns[j].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))
                            {
                                ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)datatable.Rows[0][j];
                                Map1.Zoom(geom);
                                sADFCallBackFunctionInvocation = Map1.CallbackResults.ToString();
                                return;
                            }
                        }
                    }
                }
            }
        }
    }

    #endregion
    public string GetCallbackResult()
    {
        return sADFCallBackFunctionInvocation;
    }

}

(10)系统运行结果,如图9和图10.

图9 系统运行结果

图10 定位结果(PS:箭头和“这里是就是青岛”可不是系统生成的)

转载于:https://www.cnblogs.com/zhangzhen/archive/2013/04/26/3045804.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值