2012-11-04 2 views

답변

0

이 질문은이 답변과 비슷합니다. Google Maps API v3: Close infowindow when DOM element is clicked - 답변이 적용됩니다.

마우스 오버 이벤트를 감지하려는 주요 차이점은 참조 질문 및 답변에서 언급 한 "click" 이벤트 대신 "mouseover" 이벤트가 발생한다는 것입니다.

google.maps.event.addListener(marker, 'mouseover', function() { 
    infowindow.setContent(contentString); 
    infowindow.open(map, marker); 
}); 

문제가 여러 마커를 처리하는 것은 중요하지 않습니다. 다음과 같이 할 수 있습니다. -

var infowindow = null; 
. 
. 
. 
/* now inside your initialise function */ 
infowindow = new google.maps.InfoWindow({ 
    content: "holding..." 
}); 

for (var i = 0; i < markers.length; i++) { 
    var marker = markers[i]; 
    google.maps.event.addListener(marker, 'mouseover', function() { 
     //open the infowindow when it's not open yet 
     if(contentStringCal!=infowindow.getContent()) 
     { 
      infowindow.setContent(contentStringCal); 
      infowindow.open(map, marker); 
     } 
    }); 

    google.maps.event.addListener(marker, 'click', function() { 
     //when the infowindow is open, close it an clear the contents 
     if(contentStringCal==infowindow.getContent()) 
     { 
      infowindow.close(map, marker); 
      infowindow.setContent(''); 
     } 
     //otherwise trigger mouseover to open the infowindow 
     else 
     { 
      google.maps.event.trigger(marker, 'mouseover'); 
     } 
    }); 

    //clear the contents of the infwindow on closeclick 
    google.maps.event.addListener(infowindow, 'closeclick', function() { 
      infowindow.setContent(''); 
    }); 
} 
+0

너의 앤서는 타이지만 멀티 마커는 내지도. 예를 들면 다음과 같습니다. http://fiddle.jshell.net/spYYh/13/ – user1798101

+0

For 루프에서 addLister를 사용하여 모든 마커에 추가하는 방법을 보여주기 위해 업데이트되었습니다. 마커) 및 각 마커 자체 HTML 콘텐츠가 있습니다. –

관련 문제