2011-01-06 8 views
0

ビン地図のプッシュピンにマウスオーバーの説明を追加してもらえますか? またはマウスがプッシュピンを介して終わったときに関数を呼び出すために私を助けてください おかげマウスオーバー時にビンに押しピンの説明を追加するにはどうすればいいですか?

「VAR画鋲」の間
<!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

あなたのコードをフォーマットすると、あなたを得ることができますもっと多くの助け:) http://stackoverflow.com/editing-help – Dan

答えて

1

と「map.entities.push ... "行には、私が以下にあるものを加えてください。それはあなたを始めるでしょう。基本的には、イベントハンドラを追加しています。

この場合、イベントは「ピン」に追加されますが、ここに「infobox」などの他のオブジェクトに追加することができます。サポートされているイベントはわずかです - ドキュメントをチェックしてください。しかし、イベントを結んでしまえば、素敵なものをやることができます。楽しむ!

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

ルウェリンの答えは有効です。別のアプローチは、プッシュピンラインの「型名」パラメータの値を入れている:

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

次、jQueryのを使用して、あなたは、要素を追加したり、キャッチイベントことができます。

$(".pin123").mouseover(function() { alert("hey!"); }); 
関連する問題