Pushpin Onclick Event?  
Author Message
Cadey





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

Hi has anyone managed to handle the on click event of a push pin yet because i cant find any events for such a thing

You can tell something happens because (in IE at least) you can hear the normal "tick" noise just like when you click a link, when you click on a pushpin, I need to be able to handle this even so I can action the users click on the pushpin



Windows Live Developer Forums11  
 
 
Cadey





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

Just in case any one else has had this problem or anyone can give me a better method than the one I have used.

To catch when my users click on a pin (and i no this is not perfect) i have combined two other events that are available to us in VE.

I first attached a function to the OnMouseOverCallback event. This simply sets a variable to equal the title (you could of course us ID) of the pin the user has put there mouse over, this then sets a timer to reset the variable back to nothing.

I then used the maps onclick event to test to see if this variable was not nothing, if its not then you can assume the user clicked when the mouse was over the pin and so call your handler.

If any one else can think of a better way please let me no as i really cant see any simple way to find out if a user has clicked on a pin or not

map.AttachEvent("onclick", GetClickedPin);

VEPushpin.OnMouseOverCallback = function(x,y,title, description)
  
{
    mouseoverpin = title;
    setTimeout(
'resetmouseover();', 1000);
    }

function resetmouseover() {

    mouseoverpin = '';

}

function GetClickedPin(e) {

if (mouseoverpin != '') {

    alert('bingo');

}

}


 
 
tex77





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

What I do is draw an image/div around the x y vars that the OnMouseOverCallback gives. This image/div can have all the normal onClick actions etc. And it stays, no timeout which imho is crappy. Also you can define any mouseover you want; instant. You can do anything you want really.

 
 
Cadey





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

thats a damn good idear my friend :) thank you, some time you cant see the wood for the trees!
 
 
cptscottie





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

I've attempted to implement the div during the onmouseovercallback but when I render it on the map, it does not stay above my pin, instead when I pan, the div also pans. Would you mind providing a snippet of code that explains what exactly you've done


 
 
Cadey





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

i too had that problem so i captured another couple of events to help me.

map.AttachEvent("onstartzoom", clearmouseover);

map.AttachEvent("onendcontinuouspan", clearmouseover);

map.AttachEvent("onendzoom", clearmouseover);

the clear mouse over function moves the div away from view, this should not be a problem as they cant move the map while they are over your div anyway. As soon as they stop moving the map they would have to put their mouse back over your pin to click on it again away.

function clearmouseover() {

var tempdiv = document.getElementById("mouseoverdiv")

mouseoverpin = '';

tempdiv.style.left = '-9999px';

tempdiv.style.top = '-9999px';

}

Hope that helps


 
 
tex77





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

I've attempted to implement the div during the onmouseovercallback but when I render it on the map, it does not stay above my pin, instead when I pan, the div also pans. Would you mind providing a snippet of code that explains what exactly you've done



I've got a div 'transpin' setup with no content. When the VEPushpin.OnMouseOverCallback is activated cause of a pin mouseover I move the div to the pin (x y) location and draw an transparent image (could be anything really) with an onMouseOver and onClick.

I'll post a sample code tomorrow, ain't got time for it now. Basicly it goes like this:

- VEPushpin.OnMouseOverCallback activated.
- move 'transpin' div to the x y -15
- fill 'transpin' div with an img with onmouseout & onclick
- show custom pop-up
- onMouseOut hide the two diffs

Might missed a few steps but i'll post working code tomorrow.

 
 
cptscottie





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

I can see how these methods are useful for capturing an onclick over a pin. However what I really want is to be able to put the div over the pin when the pin is created and leave it there instead of putting the div there on the mouseover. The reason being that I have text that must be displayed next to the pin such as (click here to finish polygon).

Any idea how to permanently get the div over the pins


 
 
cptscottie





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

I went ahead and did a little bit of experimenting. I've achieved the onclick event much more easily than trying to use the mouseover callback. Also I've rendered text next to the pin permanently (though it's positioned slightly lower than the pin image).

Here is some code:

var pinpoint = new parent.VEPushpin('pin_'+drawpts.length,new VELatLong(ll.Latitude,ll.Longitude),'picts/transparentpixel.gif',null,null,'VE_Pushpin_drawpoint',null,null);
map.AddPushpin(pinpoint);
document.getElementById('pin_'+drawpts.length).innerHTML += "Finish_Polygon";
document.getElementById('pin_'+drawpts.length).onclick =
function(){CompletePolygon();return false;}

function CompletePolygon()
{
alert('test');
}

Hope this helps.


 
 
Dr. Neil





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

I have just blogged on this and added content to the ViaVirtualEarth forum

http://www.viavirtualearth.com/VVE/Blog/1/133.ashx

http://www.viavirtualearth.com/VVE/Forum/2/448.ashx

Example can be found here

http://www.viavirtualearth.com/MyVirtualEarth/v3/dynamicpushpin.htm



 
 
Dr. Neil





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

I have updated the example to work with an array of pushpins.

http://www.viavirtualearth.com/VVE/Blog/1/135.ashx



 
 
pire





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

Hey this is great I hadn't thought about it. I was initially covering the pushpins with transparent layers, but I needed a right button click handler on them, so a little alteration to your code works like a charm cadey =)

Has anyone been able to find a mouseOut event for the pushpin there must be one because of the predefined on hover information but I can't find it anywhere...

toodles


 
 
Cadey





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

teh best way to handel that is to place an invisible div over the pushpin that has been clicked on, this div can have its own onmouseout event which will work jsut the same.
 
 
pire





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

super quick reply! =)

the thing is, i need the right button click from the mouse, if I cover the pushpin then I lose this functionality.


 
 
Mr Dave





PostPosted: Virtual Earth: Map Control Development, Pushpin Onclick Event? Top

Great example Dr. Neil! I hope there's a push to get more capabilties back to the pin in the next release - ability to easily do the pin click and the ability to easily number the pins would be great.

Anyone from the VE team able to comment on pin changes in the next drop fo the API