随心所欲

做个幸福的人
posts - 147, comments - 1402, trackbacks - 28, articles - 0
  博客园 :: 首页 :: 新随笔 ::  :: 订阅 订阅 :: 管理

VirtualEarth的一个例子程序

Posted on 2006-06-25 09:46 随心所欲 阅读(1262) 评论(0)  编辑 收藏 网摘 所属分类: AJAX : Atlas

1:页面代码:可以添加按钮测试执行SetPushPinsInfo或者SetPolylineInfo函数。

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MapAnywhere1.aspx.cs" Inherits="Module_Views_MapAnywhere" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>MapAnywhere</title>
    <atlas:ScriptManager ID="sm1" runat="server" EnablePartialRendering="true">
    </atlas:ScriptManager>

    <script src="http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>

    <script>
     function GetMap()
      {
           map = new VEMap('myMap');
           map.LoadMap(new VELatLong(36.654097,116.968688),8);//for default place,JiNan,Shandong,China
           //map.FindLocation('Singapore,Singapore,Asia');
      }  
      function FindLoc()
      {
           map.FindLocation(document.getElementById('txtWhere').value);
           //map.SetZoomLevel(4);
      } 
      function DeleteAllPushpins()
      {
           map.DeleteAllPushpins();
      }
      function DeleteAllPolylines()
      {
           map.DeleteAllPolylines();
      } 
      function SetPushPins(pins)
      {
         for (var i=0;i<pins.length;i++)
         {
              var pinInfo=pins[i];
              var pin=new VEPushpin(pinInfo[0],new VELatLong( pinInfo[1],pinInfo[2]) ,pinInfo[3],pinInfo[4],pinInfo[5]);
              map.AddPushpin(pin);
         }
       }
      function SetPolyline(pId,points)
      {
         poly = new VEPolyline(pId,points);
         poly.SetWidth(3);
         poly.SetColor(new VEColor(0,150,100,100));
         map.AddPolyline(poly);
         map.SetMapView(points);
       }        
      function SetPushPinsInfo()
      {
          var pins=new Array(new Array('1','0','0',null,'name1','xx'),new Array('2','10','11',null,'name2','xxx'));
          SetPushPins(pins);
      }
      function SetPolylineInfo()
      {
          var ponits=new Array(new VELatLong(1,0),new VELatLong(2,10),new VELatLong(4,4));
          SetPolyline(1,ponits);
      }                   
    </script>

</head>
<body onload="GetMap();">
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="Location Name"></asp:Label>
                        <asp:TextBox ID="txtWhere" runat="server" Width="300">  </asp:TextBox>
                        <input id="Button1" onclick="FindLoc()" type="button" value="Locate" /></td>
                    <td>
                        <input id="Button4" onclick="DeleteAllPushpins()" type="button" value="RemovePins" />
                        <input id="Button5" onclick="SetPolylineInfo()" type="button" value="RemoveRoutes" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <div id='myMap' style="position: relative; width: 600px; height: 500px;">
                        </div>
                    </td>
                    <td valign="top">
                        <atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional">
                            <ContentTemplate>
                                <br />
                                <asp:Button ID="lbt_showPin" runat="server" Text="ShowPushPins" />
                                <br />
                                <asp:Button ID="lbt_showRoute" runat="server" Text="ShowRoute" />
                            </ContentTemplate>
                        </atlas:UpdatePanel>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>


2:后台代码:就是构造向SetPushPinsInfo、SetPolylineInfo一样的js函数而已。
       举个例子
       string points = "new Array(";
        for (int i = 0; i < routes.Tables[0].Rows.Count; i++)
        {
            DataRow row = routes.Tables[0].Rows[i];
            string pid = row["PathID"].ToString();
            points += String.Format("new VELatLong({0},{1})", row["Latitude"].ToString(), row["Longitude"].ToString());
            points += ",";
        }
        points = points.Substring(0, points.Length - 1);
        points += ")";
        this.lbt_showRoute.Attributes["onclick"] = String.Format("SetPolyline({0},{1})", shipmentID, points);





标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2006-07-12 11:08 编辑过
Google站内搜索

China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
开发者征途系统新作:《设计模式——基于C#的工程化实现及扩展》

相关文章:

相关链接:

历史上的今天:
2005-06-25 家乡流传的几个故事
 
Google