|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionThis short article explains how to create a Virtual Earth 3D map using only JavaScript and some html. The example will only work in Internet Explorer with a plugin installed. The Html-ElementsFirst create a new html-File and reference the Virtual Earth API: <html>
<head>
<title>Virtual Earth 3D Mashup</title>
<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<script>
Here comes some JavaScript code …
</script>
</head>
<body onload="GetMap();" bgcolor=#000000>
<div id="myTitle" style="FONT: 100% Arial bold; TEXT-ALIGN: center; FONT-WEIGHT: bold; COLOR: #fff; POSITION: relative;">Virtual Earth 3D</div>
<div id="myMap" style="position:relative; width=100% height:500px;"></div>
</body>
</html>
The ScenesNow we can create some scenes to display on the map. We need a variable for the Virtual Earth map Object <script>
var map = null;
var timer = null;
function VirtualEarth3DScene(title, lat, lon, alt, view, heading)
{
this.Title = title;
this.ViewSpec = new VEMapViewSpecification(new VELatLong(lat, lon), null, alt, view, heading);
}
var scenes = new Array();
scenes.push( new VirtualEarth3DScene("San Francisco, California", 37.794008, -122.394352, 202.916620191187, -7.57928192941064, 284.330758577285) );
scenes.push( new VirtualEarth3DScene("Seattle, Washington", 47.619498, -122.347999, 212.752614734694, -13.4638485035358, 131.77967769793) );
var numScenes = scenes.length;
var sceneIndex = -1;
var updateInterval = 2000;
...
</script>
Next we setup an array of scenes and push two VirtualEart3DScene objects into the array. I also need the variables numScenes containing the number of scenes, the actual scene The function GetMap and MapLoadCpThe function function GetMap()
{
map = new VEMap("myMap");
map.onLoadMap = MapLoadCp;
map.LoadMap(null, 2, VEMapStyle.Aerial);
}
function MapLoadCp()
{
map.SetMapMode(VEMapMode.Mode3D);
map.HideDashboard();
timer = setInterval('IncrScene();ShowNextScene()', updateInterval);
}
Last the function call of setIntervall executes Complete the codeLast we implement the function ShowNextScene and IncrScene. The first function gets a scene out of the array of scenes. It sets the innerHTML for the div element function ShowNextScene()
{
if ( sceneIndex == 0)
{
updateInterval = 20000;
clearInterval(timer);
timer = setInterval('IncrScene();ShowNextScene();', updateInterval);
}
var scene = scenes[sceneIndex];
document.getElementById("myTitle").innerHTML = scene.Title;
map.SetMapView(scene.ViewSpec);
}
The last one is also only a helper function to update the function IncrScene()
{
++sceneIndex;
sceneIndex = sceneIndex % numScenes;
}
The ResultTry this online example.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||