2011-01-06 6 views
0

Bitte helfen Sie mir eine Beschreibung auf Maus über Push Pin in Bing Karte hinzuzufügen? Oder helfen Sie mir bitte eine Funktion aufzurufen, wenn die Maus über durch den Push-Pin ist DankWie kann ich eine Beschreibung auf Pin auf Bing in der Zeit der Maus über hinzufügen?

<!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://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script> 
       <script type="text/javascript"> 

    var map = null; 
    function GetMap() { 

     // Initialize the map 

     map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), { credentials: "Ah6hamk-cQOK9E8CiVl2mvmNR1f0UWpQJXNKxuWNhDBWiFCbpreme4p6Qpj6C03s", mapTypeId: "r" }); 

    } 
    function ClickGeocode(credentials) { 
     map.getCredentials(MakeGeocodeRequest); 
    } 
    function MakeGeocodeRequest(credentials) { 
     var geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations/Cochin?output=json&jsonp=GeocodeCallback&key=" + credentials; 

     CallRestService(geocodeRequest); 

    } 
    function GeocodeCallback(result) { 
     //alert("Found location: " + result.resourceSets[0].resources[0].name); 

     if (result && 
      result.resourceSets && 
      result.resourceSets.length > 0 && 
      result.resourceSets[0].resources && 
      result.resourceSets[0].resources.length > 0) { 
      // Set the map view using the returned bounding box 
      var bbox = result.resourceSets[0].resources[0].bbox; 
      var viewBoundaries = Microsoft.Maps.LocationRect.fromLocations(new Microsoft.Maps.Location(bbox[0], bbox[1]), new Microsoft.Maps.Location(bbox[2], bbox[3])); 
      map.setView({ bounds: viewBoundaries }); 
      // Add a pushpin at the found location 
      var location = new Microsoft.Maps.Location(result.resourceSets[0].resources[0].point.coordinates[0], result.resourceSets[0].resources[0].point.coordinates[1]); 
      //alert(location); 
      var pushpin = new Microsoft.Maps.Pushpin(location); 
      map.entities.push(pushpin); 
     } 
    } 
    function CallRestService(request) { 
     var script = document.createElement("script"); 
     script.setAttribute("type", "text/javascript"); 
     script.setAttribute("src", request); 
     document.body.appendChild(script); 
    } 
</script> 

+0

Code Formatierung können Sie erhalten viel mehr Hilfe :) http://stackoverflow.com/editing-help – Dan

Antwort

1

Zwischen dem "var Reißzwecke" und „map.entities.push ... "Linien, füge hinzu, was ich unten habe. Das wird dich beginnen. Grundsätzlich fügen Sie einen Event-Handler hinzu.

Beachten Sie, dass das Ereignis zum "Pin" in diesem Fall hinzugefügt wird - aber zu anderen Objekten wie der "Infobox" hinzugefügt werden kann, wenn wir hier eines hatten. Es gibt nur wenige unterstützte Ereignisse - Dokument prüfen. Aber Sie können einige nette Sachen machen, sobald Sie das Ereignis verkabelt haben. Habe Spaß!

Code:

var pushpin = new Microsoft.Maps.Pushpin(location); 

Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', function() { 
alert("The mouse went over the pin");});    

map.entities.push(pushpin); 
0

Llewellyn Antwort gültig ist. Ein weiterer Ansatz ist, einen Wert für ‚Typname‘ Parameter in der Reißzwecke Spiel setzen:

var pushpin = new Microsoft.Maps.Pushpin(location, {typeName: 'pin123'}); 
map.entities.push(pushpin); 

nächsten, mit jQuery, können Sie Elemente oder fangen Ereignisse hinzufügen:

$(".pin123").mouseover(function() { alert("hey!"); }); 
Verwandte Themen