InfoTip的用法(C#Webgis)

在Web应用中使用InfoTip(转载,翻译后)

1.在地图网页的<body>后面加入下面的代码:

<script>


            if (!document.layers&&!document.all&&!document.getElementById)
                        event="test"
                       
            function showtip(current,e,text){

                        if (document.all||document.getElementById){
                        thetitle=text.split('<br>')
                        if (thetitle.length>1){
                        thetitles=''
                        for (i=0;i<thetitle.length;i++)
                        thetitles+=thetitle
                        current.title=thetitles
                        }
                        else
                        current.title=text
                        }

                        else if (document.layers){
                        document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
                        document.tooltip.document.close()
                        document.tooltip.left=e.pageX+5
                        document.tooltip.top=e.pageY+5
                        document.tooltip.visibility="show"
                        }
            }
            function hidetip(){
                        if (document.layers)
                        document.tooltip.visibility="hidden"
            }

</script>

2。在</body>前加入下面代码:

<script language="javascript">
                  var img = document.getElementById('MapControl1_Image');
                  img.useMap = "#WOTips";
</script>

3。进入visual studio 2003的IDE,在地图的aspx页上任何地方加入Literal Control。
鼠标右击Map Control选择属性,在Map Control的属性窗口选择事件页,双击PreRender 事件,此时PreRender事件注册信息会自动加入到InitializeComponent方法中,同时创建空的private void MapControl1_PreRender(object sender, System.EventArgs e)处理函数。在PreRender事件处理程序中加入如下代码:
      //为不同视野下的地图图像创建热区

      StringCollection areaTagCollection = this.getImageMapHotSpots();
      string areaHTML = "";
      System.Collections.Specialized.StringEnumerator sEnum = areaTagCollection.GetEnumerator();
      while (sEnum.MoveNext())
      {
            areaHTML += ((string) sEnum.Current);
      }
                 
      Literal1.Text = "<map id ='WOTips' name='WOTips'>" + areaHTML + "</map>";

4。把下面方法加入代码窗口:

  private System.Collections.Specialized.StringCollection getImageMapHotSpots()
  {
   StringCollection areaTags = new StringCollection();

   MapInfo.Mapping.Map rMap = MapControl1.Map;
                 
   MapInfo.Engine.ISession  rMSession = MapInfo.Engine.Session.Current; //获得Session
   MapInfo.Data.Catalog catalog = rMSession.Catalog;
   MapInfo.Data.Table tabWorld = catalog.GetTable("Worldcap");

   MapInfo.Data.MIDataReader dr = tabWorld.ExecuteReader();
   while(dr.MoveNext())
   {
    MapInfo.Geometry.Point sPoint = (MapInfo.Geometry.Point)dr.Current.Geometry;
    MapInfo.Geometry.Envelope env = sPoint.Envelope;
    MapInfo.Geometry.DRect sRect = env.Bounds;
                 
    string tiptext = (string) dr.Current[1];

    MapInfo.Geometry.DisplayTransform dt = rMap.DisplayTransform;
    System.Drawing.Rectangle rect;
    dt.ToDisplay(sRect, out rect);
    string coords = (rect.Right-10) + "," + (rect.Top-20) + "," + (rect.Left + 10)  + "," + (rect.Bottom + 10);


    string tag = "<area shape ='rect' coords ='" + coords + "'  onmouseover='showtip(this,event,\"" + tiptext + "\")' onMouseout='hidetip()' />";
    areaTags.Add(tag);
   }
           
   dr.Dispose();
   return areaTags;
  }

posted @ 2005-07-06 16:10  刺猬的家  阅读(1264)  评论(5)    收藏  举报