三维地图与二维地图的联动,这里主要通过同步地图中心点来实现,再有就是对三维地图观察高度与二维地图比例尺的换算。
1 <html>
2
3 <head>
4 <title>MS Map</title>
5 </head>
6
7 <body onload="Init();" style="overflow-y:hidden">
8
9 <table width="100%" height="100%">
10 <tr><td><div id='myMap' style="position:relative; 100%; height:100%;"></div></td></tr>
11 <tr height="18px"><td>
12 <INPUT id="txtWhere" type="text" name="txtWhere" onkeyup="CheckAddressEnter()">
13 <INPUT id="find" type="button" value="查找" name="find" onclick="FindLoc();">
14 </td></tr>
15 </table>
16 <script type="text/javascript" src="http://www.skylineGlobe.com/SkylineGlobe/WebClient/PresentationLayer/SGAPI/v2.0/sgapi.js"></script>
17 <script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
18 <script type="text/javascript" language="jscript">
19
20 var globe = null;
21 var map = null;
22 var lock;
23 var lock2;
24 var lastlevel=-1;
25
26 function Init()
27 {
28 globe = new SGWorld();
29
30 sgFramework = new SGFramework();
31
32 sgFramework.events.attachEvent("onShowTool", onShowTool);
33 sgFramework.events.attachEvent("onHideTool", onHideTool);
34
35 lock=1;
36 lock2=1;
37
38 map = new VEMap('myMap');
39 map.LoadMap();
40 map.HideDashboard();
41 map.AttachEvent("onchangeview", myEventTester); //change to your event
42 map.AttachEvent("onstartpan", startpan);
43 map.AttachEvent("onendpan", endpan);
44 map.AttachEvent("onstartzoom", zoomstart);
45 map.AttachEvent("onendzoom", zoomend);
46
47
48 lock=0;
49 lock2=0;
50 onShowTool();
51 }
52
53 function onShowTool()
54 {
55 globe.attachEvent("onFrame",teOnFrame);
56 }
57
58 function onHideTool()
59 {
60 globe.detachEvent("onFrame",teOnFrame);
61 }
62
63
64 function startpan()
65 {
66 lock2=1;
67 }
68 function endpan()
69 {
70 lock2=0;
71 }
72 function zoomstart()
73 {
74 lock2=1;
75 }
76 var cs;
77 function zoomend(e)
78 {
79
80 if (cs==0)
81 {
82 if (lock==0)
83 {
84 mx = map.GetCenter().Longitude;
85 my = map.GetCenter().Latitude;
86
87
88 mh=21111111/(1 << e.zoomLevel);
89 globe.navigate.setPosition(new SGPosition(mx,my,mh));
90 }
91 }
92 cs=0;
93 lock2=0;
94 }
95
96 function myEventTester(e)
97 {
98 if (lock==0)
99 {
100 mx = map.GetCenter().Longitude;
101 my = map.GetCenter().Latitude;
102 mh=21111111/(1 << e.zoomLevel);
103 var pos = globe.navigate.getPosition();
104 mh=pos.height;
105
106 globe.navigate.setPosition(new SGPosition(mx,my,mh,0,pos.pitch));
107 }
108 }
109
110 function teOnFrame()
111 {
112 if (lock2==0)
113 {
114 lock=1;
115 lock2=1;
116 var pos = globe.navigate.getPosition();
117 map.PanToLatLong(new VELatLong(pos.y,pos.x));
118 var h=pos.height;
119 if (h<1) h=1;
120 level=Math.floor(Math.log(h)/Math.log(2.0)-5);
121 if (level<1) level=1;
122 if (level>19) level=19;
123 if (level!=lastlevel)
124 {
125 lastlevel=level;
126 cs=1;
127 map.SetZoomLevel(20-level);
128 }
129 lock2=0;
130 lock=0;
131 }
132 }
133
134 function CheckAddressEnter()
135 {
136 if (window.event.keyCode == 13)
137 FindLoc();
138 }
139
140 function FindLoc()
141 {
142 map.Find(null,document.getElementById('txtWhere').value);
143 //map.Find(document.getElementById('txtWhere').value);
144 }
145
146
147
148
149 </script>
150
151 </body>
152
153 </html>
2
3 <head>
4 <title>MS Map</title>
5 </head>
6
7 <body onload="Init();" style="overflow-y:hidden">
8
9 <table width="100%" height="100%">
10 <tr><td><div id='myMap' style="position:relative; 100%; height:100%;"></div></td></tr>
11 <tr height="18px"><td>
12 <INPUT id="txtWhere" type="text" name="txtWhere" onkeyup="CheckAddressEnter()">
13 <INPUT id="find" type="button" value="查找" name="find" onclick="FindLoc();">
14 </td></tr>
15 </table>
16 <script type="text/javascript" src="http://www.skylineGlobe.com/SkylineGlobe/WebClient/PresentationLayer/SGAPI/v2.0/sgapi.js"></script>
17 <script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
18 <script type="text/javascript" language="jscript">
19
20 var globe = null;
21 var map = null;
22 var lock;
23 var lock2;
24 var lastlevel=-1;
25
26 function Init()
27 {
28 globe = new SGWorld();
29
30 sgFramework = new SGFramework();
31
32 sgFramework.events.attachEvent("onShowTool", onShowTool);
33 sgFramework.events.attachEvent("onHideTool", onHideTool);
34
35 lock=1;
36 lock2=1;
37
38 map = new VEMap('myMap');
39 map.LoadMap();
40 map.HideDashboard();
41 map.AttachEvent("onchangeview", myEventTester); //change to your event
42 map.AttachEvent("onstartpan", startpan);
43 map.AttachEvent("onendpan", endpan);
44 map.AttachEvent("onstartzoom", zoomstart);
45 map.AttachEvent("onendzoom", zoomend);
46
47
48 lock=0;
49 lock2=0;
50 onShowTool();
51 }
52
53 function onShowTool()
54 {
55 globe.attachEvent("onFrame",teOnFrame);
56 }
57
58 function onHideTool()
59 {
60 globe.detachEvent("onFrame",teOnFrame);
61 }
62
63
64 function startpan()
65 {
66 lock2=1;
67 }
68 function endpan()
69 {
70 lock2=0;
71 }
72 function zoomstart()
73 {
74 lock2=1;
75 }
76 var cs;
77 function zoomend(e)
78 {
79
80 if (cs==0)
81 {
82 if (lock==0)
83 {
84 mx = map.GetCenter().Longitude;
85 my = map.GetCenter().Latitude;
86
87
88 mh=21111111/(1 << e.zoomLevel);
89 globe.navigate.setPosition(new SGPosition(mx,my,mh));
90 }
91 }
92 cs=0;
93 lock2=0;
94 }
95
96 function myEventTester(e)
97 {
98 if (lock==0)
99 {
100 mx = map.GetCenter().Longitude;
101 my = map.GetCenter().Latitude;
102 mh=21111111/(1 << e.zoomLevel);
103 var pos = globe.navigate.getPosition();
104 mh=pos.height;
105
106 globe.navigate.setPosition(new SGPosition(mx,my,mh,0,pos.pitch));
107 }
108 }
109
110 function teOnFrame()
111 {
112 if (lock2==0)
113 {
114 lock=1;
115 lock2=1;
116 var pos = globe.navigate.getPosition();
117 map.PanToLatLong(new VELatLong(pos.y,pos.x));
118 var h=pos.height;
119 if (h<1) h=1;
120 level=Math.floor(Math.log(h)/Math.log(2.0)-5);
121 if (level<1) level=1;
122 if (level>19) level=19;
123 if (level!=lastlevel)
124 {
125 lastlevel=level;
126 cs=1;
127 map.SetZoomLevel(20-level);
128 }
129 lock2=0;
130 lock=0;
131 }
132 }
133
134 function CheckAddressEnter()
135 {
136 if (window.event.keyCode == 13)
137 FindLoc();
138 }
139
140 function FindLoc()
141 {
142 map.Find(null,document.getElementById('txtWhere').value);
143 //map.Find(document.getElementById('txtWhere').value);
144 }
145
146
147
148
149 </script>
150
151 </body>
152
153 </html>