Create virtual terrestrial infobox when clicked instead of hovering?

Is it possible for the onclick message instead of mouseover to be displayed on the virtual earth infobox display?

I am currently using something like this:

...

var pin = new VEShape( VEShapeType.Pushpin, [location] ); pin.SetCustomIcon(icon_url); pin.SetTitle(title); pin.SetDescription(info_window_template); map.AddShape(pin); document.getElementById(pin.GetPrimitive().iid).onmouseover = EventHandlerOnMouseOver; } var EventHandlerOnMouseOver = function(e) { // Handle content loading... } 

...

However, if I try to change onmouseover to onclick, VE takes onclick and completely disables the infobox.

+7
javascript virtual-earth
source share
1 answer

You can accomplish what is described using events ... note that I am using Virtual Earth 6.2.

The trick is to suppress the onmouseover event and subscribe to the onclick event. When you find out whether the user clicked the form or not, you can call the ShowInfoBox method on the map control to make it display the info window.

And here is the code: =)

 // Begin by supressing the onmouseover event. Returning true // from an event handler disables the default Virtual Earth action map.AttachEvent('onmouseover', function(e) { if(e.elementID) return true; }); // Subscribe to the onclick event and react whenever we get an element id map.AttachEvent("onclick", function(e) { // elementID is null when someone clicks on the map and not on a shape if(e.elementID) { var shape = map.GetShapeByID(e.elementID); if(shape) map.ShowInfoBox(shape); } }); 

Please note that the infobox will be displayed even if you right-click on the figure; To avoid this, you can look at the leftMouseButton or rightMouseButton properties in the event object .

Literature:

+1
source share

All Articles