2012-03-08 25 views
1

私はGoogleマップの座標の配列を持っています。各座標セットはそれ自身の個々のマーカーを取得します。ユーザーがマーカーを移動(マウスオーバー)すると、別のアイコンと交換されます(このアイコンはすべてのマーカーで同じです)。私の問題は、ユーザーがマウスオーバーをして元のアイコンを復元したいのであれば、最後に作成したマーカー(marker3.png)をすべてのマーカーに対して取得するということです。Google Maps APIマーカーマウスオーバー時のJavascriptホバー効果

多分あなたは考えがあります。スクリプトは次のとおりです。

$(document).ready(function(){ 
          var locations = [ 
          ['Dr. Christian Schrey', 52.499496, 13.316873, 4], 
          ['Dr. Teufel', 52.528664, 13.380232, 5], 
          ['Dr. Sebs Firma', 52.507839, 13.496490, 3], 

          ]; 

          initialize(); 
          var map; 
          function initialize() { 
          var myLatlng = new google.maps.LatLng(52.52427, 13.40629); 
          var myOptions = { 
           zoom: 11, 
           center: myLatlng, 
           mapTypeId: google.maps.MapTypeId.ROADMAP 
          } 
          map = new google.maps.Map(document.getElementById("Map"), myOptions); 

          var infowindow = new google.maps.InfoWindow(); 

          var marker, i; 
          var y = 0; 

          for (i = 0; i < locations.length; i++) { 
          y++; 
          image = 'http://xxx.de/test6/system/css/images/marker'+y+'.png'; 

          marker = new google.maps.Marker({ 
           position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
           map: map, 
           icon: image 
          }); 

          google.maps.event.addListener(marker, 'click', (function(marker, i) { 
           return function() { 
           infowindow.setContent(locations[i][0]); 
           infowindow.open(map, marker); 
           } 
          })(marker, i)); 

          google.maps.event.addListener(marker, "mouseover", function(event) { 
          this.setIcon("http://xxx.de/test6/system/css/images/pfote_clean.png"); 
          }); 

          google.maps.event.addListener(marker, "mouseout", function(event) { 
          this.setIcon(image); 
          }); 

          } 

         }; 
        }); 

私は助けていただきありがとうございます!ありがとうございました。

答えて

2

あなたはマーカーのオプション内のURLを格納することができる:

marker = new google.maps.Marker({ 
    position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
    map: map, 
    icon: image, 
    src:image//<- 
}); 

その後、あなたはコールバックの後半でURLを取得できるようになります:

this.setIcon(this.src); 
+0

Thxをたくさん!それはそれを修正! :) – Sebsemillia