2011-02-24 3 views
0

현재 Google지도의 아이콘을 만들려면이 작업을 수행하십시오. 루프, 마커를 닫기 위해, 내가이 비슷한을 알고에다른 정보 창이 멋지게 닫습니다.

function createMarker(posn, title, html) { 
      var marker = new google.maps.Marker({ position: posn, title: title, draggable: false }); 
      marker['infowindow'] = new google.maps.InfoWindow({ content: html }); 

      infoWindows.push(marker['infowindow']); 
      google.maps.event.addListener(marker, "click", function() { 
       for (i = 0; i < infoWindows.length; i++) { 
        infoWindows[i].close(); 
       } 
       this['infowindow'].open(map, this); 
      }); 
      return marker; 
     } 

메신저 행복하지가 하나 refernce를 사용하여 수행 할 수 있습니다 :

경우 (정보창) infowindow.close()를; 내가 다른
markers[myPoint]['infowindow'].open(map, markers[myPoint]); 곳과 같은 일을하고 있기 때문에

내가 좋아하는 위의 코드를 사용하고있는 이유는 (myPoint는 숫자)입니다.

어떻게하면 오픈 infowindows를 닫고 좋은 방법으로 루프를 피할 수 있습니까?

답변

2

바로 지난 저장할 전역 변수에 정보창을 열어 :

var activeInfoWindow; 

function createMarker(posn, title, html) { 
    var marker = new google.maps.Marker({ position: posn, title: title, draggable: false }); 
    marker['infowindow'] = new google.maps.InfoWindow({ content: html }); 

    infoWindows.push(marker['infowindow']); 
    google.maps.event.addListener(marker, "click", function() { 
     if (activeInfoWindow == this['infowindow']) { 
      return; 
     } 
     if (activeInfoWindow) { 
      activeInfoWindow.close(); 
     } 

     this['infowindow'].open(map, this); 
     activeInfoWindow = this['infowindow']; 
    }); 
    return marker; 
} 
+0

http://code.google.com/apis/maps/documentation/javascript/reference.html#InfoWindow 버그 되세요. 그것은 정보창을 다시 표시하지 않습니다. 수정하려면 을 제거하십시오. (activeInfoWindow == this [ 'infowindow'] { return;} – nguyencse

2

그것은 단지 하나의 InfoWindow는 데있다 및 마커 클릭 이벤트에 당신이 정보창의의 setContent 속성 다음 오픈 이벤트를 호출하고 또 다른 방법 지도와 마커를 매개 변수로 사용하여

지도에서 10,000 개 이상의 마커가있는 응용 프로그램에서이 방법이 더 유용하다는 것을 발견했습니다.

은 참조 : 마커 다음 다음, 그것의 정보창에 닫기 버튼을 클릭하여 다시 마커에 클릭에 클릭하면

infoWindow = new google.maps.InfoWindow(); 

function createMarker(posn, title, html) { 
    var marker = new google.maps.Marker({ position: posn, title: title, draggable: false }); 
    marker['content'] = html; 
    google.maps.event.addListener(marker, "click", function() { 
     infoWindow.setContent(this['content']); 
     infoWindow.open(map, this); 
    }); 
    return marker; 
} 
관련 문제