2009-04-16 6 views
1

Wie kann ich einen Pin mit einem Mausklick setzen? angesichts dieser der Code:Hinzufügen einer Push-Pin zu einer Karte mit Javascript

function AddPushpin() 
    { 
     var shape = new VEShape(VEShapeType.Pushpin, **map.GetCenter()**); 
     shape.SetTitle('sample'); 
     shape.SetDescription('This is shape number '+pinid); 
     pinid++; 
     map.AddShape(shape); 
    } 

es auf der Mitte zeigen ist ..

Sie haben keine Ahnung, wie man ein Bild auf dem Reißzwecke schweben hinzufügen?

+0

Ist dies Google Maps oder etwas anderes? –

+0

eigentlich ist dies Microsoft Visual Erde, es war nur ein Fehler, sorry. – bluestella

Antwort

0

Check-out this article ...

function InitMap() 
{ 
// add code to init your map.... 

// attach the onclick event... 
map.AttachEvent("onclick", MouseClick); 

} 

function MouseClick(e) 
    { 
     map.AddPushpin('pin', 
     e.view.latlong.latitude, 
     e.view.latlong.longitude, 
     88, 
     34, 
     'pin', 
     'MyPin', 
     1); 
    } 
+0

Ich habe das versucht, aber ich kann es nicht tun. :( – bluestella

1

Hier ist ein Beispiel, das eine Reißzwecke während des OnClick-Ereignis der Karte fügt hinzu und setzt die Foto-URL Shape innerhalb des InfoxBox um ein Bild anzuzeigen.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
    <title></title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=en-US"></script> 
    <script type="text/javascript"> 
    var map = null; 

    function GetMap() 
    { 
     map = new VEMap("myMap"); 
     map.LoadMap(); 

     // Attach the OnClick event 
     map.AttachEvent("onclick", OnClick_Handler); 

     // You could Dettach the OnClick event like this 
     //map.DetachEvent("onclick", OnClick_Handler); 
    } 

    function OnClick_Handler(e){ 
     // "sender" is the VEMap that raised the event 
     // "e" is the VE Map Event Object 

     // Get the Lat/Long where the Mouse was clicked 
     var pushpinLocation = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY)); 

     // Create the Pushpin Shape 
     var s = new VEShape(VEShapeType.Pushpin, pushpinLocation); 
     s.SetTitle("test pushpin"); 
     s.SetDescription("test description"); 

     s.SetPhotoURL("http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png"); 

     // Plot a Shape at the Clicked location 
     map.AddShape(s); 
    } 
    </script> 
</head> 
    <body onload="GetMap();"> 
     <div id='myMap' style="position:relative; width:400px; height:400px;"></div> 
    </body> 
</html> 
+0

es hat eine vertikale Bildlaufleiste, danke Chris :) – bluestella

+0

Oh, jetzt tut es. Es war nicht als ich es zum ersten Mal gepostet habe. Hmm ... Ich werde meine Notiz darüber löschen. –

+0

ehhehe .. es ist okay .. :) vielen Dank .. ich werde es in einer Weile versuchen :) – bluestella

Verwandte Themen