Virtual Earth – Set Pushpins to show default popup onclick

posted in: Uncategorized | 0

johnWeeGo.jpgIf you have played with Virtual Earth you will have noticed that if you click on a pushpin it actually cancels the mouseover event and your popup ballon doen’t appear. To fix this you need to add an onclick event manully through the DOM and then call the onmouseover event manually, There is a slight difference between browsers to take of also. Check out the solution


var map = null;
var pinID = 1;

function GetMap()
{
    map = new VEMap('myMap');
    map.LoadMap(new VELatLong(47.6, -122.33), 10 ,'h' ,false);

    AddClickablePin(new VELatLong(47.6, -122.33),null,"test","some nice details")
}

function AddClickablePin(location, icon_url, title, details)
{
    var pin = new VEPushpin(pinID, location, icon_url, title, details);
    map.AddPushpin(pin);
    var element = document.getElementById(pinID);
    element.onclick = EventHandlerOnClick;
    pinID++;
}


function EventHandlerOnClick(e)
{
    if (e!=null)
    {
        document.getElementById(e.currentTarget.id + "_" + map.GUID).onmouseover();
    } else
    {
        document.getElementById(window.event.srcElement.id).onmouseover();
    }
}