ArcGIS Server 中的動態文字標註(及其他圖形)

 此處所說的動態標註,是指動態顯示地圖上某一要素的動態信息。還是通過熟悉的Callback機制來實現。由於獲取地圖上某一要素的動態信息過程可能不同。本文只描述過程以及共享部分代碼。

1、首先寫一個javascript函數用來間隔一定時間不停的執行,以保證要素信息的動態性。另外需要在MapResourcemanager 中加入一臨時圖層(GraphicsLayer),標註的信息就在此圖層上顯示。

<script type="text/javascript">

        function Show() {

           SetCustomOperation(FSShow)    // Callback前臺函數     

        }

 //每間隔20秒執行一次show函數

        Ext.onReady(function() {

          setInterval(Show, 20000);

        });   

function SetCustomOperation(sVal)

       {

            var message ='';

            message +=',' + sVal;

            var context ='Map1'

            <%=sCallBack%>              

   }  

  </script>

2、後臺首先要從數據庫去動態獲取要標註的地圖要素的實時信息以及獲取到此要素的座標值。接着就是就是標註了。主要代碼如下:

 

 ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;

               //查找ElementGraphicsLayer

 ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality Tempfunc = map.GetFunctionality("TempEle"); // TempEle爲動態資源圖層名

 ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource  gResource = Tempfunc.Resource as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource;

 

foreach (System.Data.DataTable dt in gResource.Graphics.Tables)

 {

    if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)

     {

        glayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;

         break;

     }

 }

    //如果沒有ElementGraphicsLayer就新增加一個ElementGraphicsLayer

 if (glayer == null)

   {

       glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();

      gResource.Graphics.Tables.Add(glayer);

   }

              

 ESRI.ArcGIS.ADF.Web.Geometry.Point point = new ESRI.ArcGIS.ADF.Web.Geometry.Point(X, Y);

//此處X,Y即爲需要標註的某一點要素的X,Y座標值

 //這裏我看過,可以加入更多的圖形

 ESRI.ArcGIS.ADF.Web.Display.Symbol.TextMarkerSymbol pMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.TextMarkerSymbol();

 pMarkerSymbol.Text = string.Format("{0}", str); 

/*此處str即爲標註要素的動態信息字符串,此處是通過間隔一定時間從數據庫獲取的*/

 pMarkerSymbol.Font.Size = 20;

 pMarkerSymbol.Transparency = 0;

 ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge1 = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(point, pMarkerSymbol);

 glayer.Add(ge1);

 Map1.RefreshResource(gResource.Name);


發佈了25 篇原創文章 · 獲贊 2 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章