In this article I will explain how to design a Virtual Earth application to load its pushpin content on demand. Although this technique is very well suited for use in high performance sites combined with Clustering and encoding I will cover only the basics to keep it simple.
This code works for both IE and Firefox.
The normal method to load a pushpin in VE is the following:
var map = null;
var pinID = 1;
map = new VEMap('myMap');
var pin = new VEPushpin( pinID, map.GetCenter(), null, 'My
pushpin', 'This is pushpin number '+pinID );
When the user mouses over the pin the content is shown.
If you have a large quantity of data you must send all the content to the client in order for the occasional user interaction. Additionally the content is only as current as when it was added to the map.
The first step is to add the pin with a mouse over call back:
function AddAJAXPin(latlon, icon_url, iconStyle)
var pin = new VEPushpin(pinID, latlon, icon_url,
pinID + "", "", iconStyle);
VEPushpin.ShowDetailOnMouseOver = false;
VEPushpin.OnMouseOverCallback = PinHover;
The mouse over call back then creates a custom pushpin popup, here I will use the VE default popup. The key is to create a div within the popup with a known ID that we will pass to our AJAX method:
function PinHover(x, y, title, details)
var ID = title;
var DivID = "VPOP" + ID;
window.ero.setContent("<div id='" + DivID + "'>Loading...</div>");
After we create the popup with some loading type text as a placeholder we call our method to get the real data:
//Get content from server based on the ID
var mydate= new Date();
var result = mydate.toTimeString();
var resultDiv = document.getElementById(DivID);
resultDiv.innerHTML = result;
This could use MS AJAX to call a web service directly or make a XMLHTTP request to a server page to get the required content.
Using this technique it is possible to show the most up to date information when the user rolls over the pin and also save a tonne of bandwidth by only getting content when it is required.
Using this technique you can completely redesign you application to have a fast and efficient way to just get the pin locations on initial load and a separate method to get the actual content on demand.
Combine this with some encoding on those pin locations and you have reduced the initial data sent to every client significantly.
Stay tuned for my next article Clustering Virtual Earth V2.
Have a comment to make or just say hello?