Recent Blog Posts RSS
ViaWindowsLive on Via Virtual Earth Blog
The new ViaWindowsLive community site has launched and features not only a definitive set of resources on all Live Services from Microsoft but also a special section on Virtual Earth including a new site gallery for you to upload your sites, new articles on Version 6, including getting started guide, an interactive quick guide, location finder and more. Subscribe to the VWL aggregated blog to stay in touch with everything Live Services related. Find all the great content from this site and much, much more. Explore how other Live Services can compliment Virtual Earth and your applications.
Version 5 URL changed - Error: 'VEMap' is undefined on Via Virtual Earth Blog
It has been reported that the old url to access the Version5 javascript for Virtual Earth no longer works. This is effecting sites worldwide.
The correct way to reference the Version 5 javascript is:
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5"></script>
If you have been effected a forum thread has been started here
Silverlight Virtual Earth viewer on Via Virtual Earth Blog
With the launch of silverlight yesterday I was digging around and found this viewer for Virtual Earth by Greg Schechter. It does use the 1.1 alpha of silverlight. It gives some interesting ideas for where Virtual Earth could be headed. Certainly the demo of the performance of silverlight compared to javascript for processing showed a significant increase. This could be very useful.
And of course on the gamer front check this out by Andy Beaulieu and shoot down some UFO's over Birdseye images.
John.
So much new Virtual Earth Imagery Worldwide. on Via Virtual Earth Blog
I subscribe to all the VE blogs and recently the posts about updated imagery has been more and more frequent.
The latest is here and for myself downunder we saw three updates, Canberra, Newcastle and Uluru:


Derek Chan posts 3 Articles in a month! on Via Virtual Earth Blog
A big thank you to the efforts of Derek Chan who posted his third VE article today (he actually had it ready weeks ago but had to wait for Mr Bottleneck here at VVE ;) )
The 3 articles are all relivant to Version 5 of Virtual Earth and deal with the Mini Map, debugging javascript and now custom pins in routes.
All these can now be found in our articles section.
If you have something to contribute send us an email.
John (The bottleneck)
Adding Your Own Context Menu RSS
This article is written for an old version of the Virtual Earth platform. While still available for reference purposes, it is unlikely to work if implemented.
In this tutorial I'll explain how to add your own context menu (right click popup menu) to your Virtual Earth application. I have used this technique in my MapStats application.
It will look like this when you right click the map:

We'll need two overload to members of the VE_MapControl class. Put these lines at the top of your OnPageLoad function:
VE_MapControl.prototype._CallContextMenu=function(e){if(!e)e=this._CreateEvent();if(this.onContextMenu)this.onContextMenu(e);}
VE_MapControl._ContextMenu = function(e){if(!e)e=window.event;e.cancelBubble=true;var t=VE_MapControl.GetTarget(e);var c=VE_MapControl.FindControlByTileImage(t);c._CallContextMenu(c._CreateEvent(c.GetLatitude(VE_MapControl.GetMouseY(e)),c.GetLongitude(VE_MapControl.GetMouseX(e))));if(!c||c.debug){return true;}return false;}
Now we can 'hook' the onContextMenu event of your map control. In this event we can draw our popup menu. We'll also need to remove the popup menu when the user left clicks the map. Let's add the following code after you created the map control 'map' in your OnPageLoad function:
map.onContextMenu=popupmenu;
map.onMouseClick=removepopupmenu;
You can now already capture the context menu event by implementing the popupmenu function, this was the most important part. If you want to create the same context menu as you see at the screenshot, you'll need to follow the rest of the article as well. Copy the following to your CSS file (yes, all this for the menus):
/* The gifs can be found at http://www.msgweb.nl/mapstats/view/drop_down_triangle.gif,
and http://www.msgweb.nl/mapstats/view/drop_down_triangle_hover.gif.
please copy them to your own server. */
ul, li{margin:0;padding:0;}
ul.pmenu {
position:absolute;
margin: 0;
padding: 1px;
list-style: none;
width: 150px; /* Width of Menu Items */
border: 1px solid #ccc;
background:white;
display:none;
z-index:10;
}
ul.pmenu li {
position: relative;
}
ul.pmenu li ul {
position: absolute;
left: 150px; /* Set 1px less than menu width */
top: 0;
display: none;
z-index:10;
}
/* Styles for Menu Items */
ul.pmenu li a {
display: block;
text-decoration: none;
color: black;
padding: 2px 5px 2px 20px;
}
ul.pmenu li a:hover {
background:#335EA8;
color:white;
}
ul.pmenu li a.parent {
background:url('drop_down_triangle.gif') no-repeat 140px 4px;
}
ul.pmenu li a.parent:hover {
background:#335EA8 url('drop_down_triangle_hover.gif') no-repeat 140px 4px;
}
/* IE \*/
* html ul.pmenu li { float: left; height: 1%; }
* html ul.pmenu li a { height: 1%; }
* html ul.pmenu li ul {left:147px;}
/* End */
ul.pmenu li:hover ul, ul.pmenu li.over ul { display: block; } /* The magic */
ul.pmenu li ul{left:150px;}
Now, we need to add the actual menu to your HTML code. A basic menu looks like this (add it to your HTML body):
<ul id="popupmenu" class="pmenu">
<li><a href="#" onclick='' class="parent">Switch view</a>
<ul class="pmenu">
<li><a href="#" onclick="map.SetMapStyle('h')">Hybrid</a></li>
<li><a href="#" onclick="map.SetMapStyle('r')">Road</a></li>
<li><a href="#" onclick="map.SetMapStyle('a')">Aerial</a></li>
</ul>
</li>
<li><a href="#" onclick='' class="parent">Zoom</a>
<ul class="pmenu">
<li><a href="#" onclick="map.ZoomIn()">In</a></li>
<li><a href="#" onclick="map.ZoomOut()">Out</a></li>
</ul>
</li>
<li><a href="#" onclick="alert('Point coordinates:\nLatitude: '+popupevent.latitude+'\nLongitude: '+popupevent.longitude);">Point coordinates</a></li>
</ul>
Now, add this code to your OnPageLoad function to make sure the submenus show up in every browser:
navRoot = document.getElementById("popupmenu");
for (i=0; i<navRoot.childNodes.length; i++)
{
node = navRoot.childNodes[i];
if (node.nodeName=="LI")
{
node.onmouseover = function()
{
this.className+=" over"; //Show the submenu
}
node.onmouseout=function()
{
this.className.replace(" over", ""); //Hide the submenu
}
}
}
Well, we're almost there. The last thing that needs to be done is implementing the popupmenu and removepopupmenu functions, to actually show/hide the menu:
function removepopupmenu(e)
{
var menu = document.getElementById('popupmenu').style.display='none'; //Hiding the menu
}
function popupmenu(e)
{
var menu = document.getElementById('popupmenu');
menu.style.display='block'; //Showing the menu
menu.style.left = map.GetX(e.longitude); //Positioning the menu
menu.style.top = map.GetY(e.latitude);
}
I hope you find this tutorial useful. If you've got any questions, feel free to contact me.
The HTML/CSS list menu technique used in this article can be found at A List Apart.
Good luck with your application!
Article contributed by Yousef El-Dardiry. Have you got something to contribute?


