zoukankan      html  css  js  c++  java
  • ArcGIS Server 9.3前后台交互调用实现点定位

     

     ArcGIS Server 9.3前后台交互调用实现点定位

    (借助Coolite控件)

     

     

    本例实现的是双击左侧的树型列表中一项,在右侧地图上定位到这一项。实现了AJAX式的通过callback机制或者partialpostback 才能实现的的定位。

    1、首先在后台写要实现点定位的代码(首先声明本例子使用的是vs2008的开发环境),如下所示:

     

    //视频定位

        [AjaxMethod] //这个不能缺,是前台调用的依据

        public void CameraLocation(string id)

    //其中id是树形控件中项的一个属性

        {

           

          try

           {

              

               string strL = string.Format("ID='{0}'", id);

     

            if (strL != null)

              {

                    #region

    if(Map1.PrimaryMapResourceInstance.SupportsFunctionality(typeof(IQueryFunctionality)))

              {

            string resourceName = "摄像头";//要定位的mapreourceItem

     

                    ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality MapFunctionality = Map1.GetFunctionality(resourceName);

                  ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisResource = MapFunctionality.Resource;

     

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

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

     

    string[] sLyrIDs = null;

    string[] sLyrNames = null;

    pQueryFunctionality.GetQueryableLayers(null, out sLyrIDs, out sLyrNames, ESRI.ArcGIS.ADF.Web.FeatureType.Point);

    if (sLyrNames.Length > 0)

    {

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

    {

     ESRI.ArcGIS.ADF.Web.QueryFilter pQFilter = new ESRI.ArcGIS.ADF.Web.QueryFilter();

    pQFilter.WhereClause = strL;

    pQFilter.MaxRecords = 2;

    pQFilter.ReturnADFGeometries = true;

     DataTable pDT = pQueryFunctionality.Query(null, sLyrIDs[i], pQFilter); if (pDT != null)

     {

           if (pDT.Rows.Count > 0)

            {

               GraphicsLayer pGraLyr = ESRI.ArcGIS.ADF.Web.Converter.ToGraphicsLayer(pDT);

                          ESRI.ArcGIS.ADF.Web.Geometry.Point pSelGeo = pGraLyr.GeometryFromRow(pGraLyr.Rows[0]) as ESRI.ArcGIS.ADF.Web.Geometry.Point;

                                       

              this.ScriptManager1.AddScript("panZoomToXY(" + pSelGeo.X.ToString() + "," + pSelGeo.Y.ToString() + ");");

    //本例子使用了coolite.ext控件,其中ScriptManager1是ext控件的scriptManager 控件, panZoomToXY()是在前台写的javascript函数

                                      

             break;

                                   

                   }

                    pDT.Dispose();

                }

        else

              Response.Write("<script>window.alert('无法定位所查找的信息');");

     

                          }

     

                        }

                    }

     

                    #endregion

                }

     

            }

            catch (Exception Err)

            {

                SystemLog.WriteLog("视频定位出现错误", Err);

            }

        }

    2、添加一个js文件,然后在前台实现panZoomToXY函数。

     

    function panZoomToXY(x, y) {

         var map = $find('Map1');

        var point = new ESRI.ADF.Geometries.Point(x, y);

        map.panTo(point, true);

      var timeoutZoom = String.format("var map = $find('{0}');map.zoom(10000,new ESRI.ADF.Geometries.Point({1},{2}),true)", 'Map1', x, y);

      window.setTimeout(timeoutZoom, 1500);

     }

    3、然后在树形控件的双击事件中调用后台写的函数,调用代码如下:

    Coolite.AjaxMethods.CameraLocation(id);//视频定位

     

    4、本例子实现过程如下:通过双击树形控件中的一项,然后调用步骤3中的代码,然后3调用后台步骤1的代码,然后1在实现定位时调用前台的2js代码,最后实现了AJAX式的通过callback机制或者partialpostback 才能实现的定位。仔细体会吧!

    一起学习GIS及其二次开发,一起进步!
  • 相关阅读:
    apache 问题 You don't have permission to access /test.php on this server 解决方法
    setTimeout和setInterval实现定时器的区别
    视图Ext.Viewport和窗口Ext.Window用法
    JavaScript设置Cookie
    布局Layout
    html中select标签刷新后不回到默认值而是保持之前选择值
    设置session失效的几种方法
    面板Ext.Panel使用
    树TreePanel
    让html元素随浏览器的大小自适应垂直居中
  • 原文地址:https://www.cnblogs.com/tuncaysanli/p/1374492.html
Copyright © 2011-2022 走看看