Development Tip

Google Maps API v3 정보창 닫기 이벤트 / 콜백?

yourdevel 2020. 11. 3. 19:23
반응형

Google Maps API v3 정보창 닫기 이벤트 / 콜백?


내 Google지도 인터페이스에 열려있는 모든 정보창을 추적하고 싶지만 (이름을 배열에 저장) "x를 통해 닫을 때 배열에서 제거하는 방법을 알 수 없습니다. "각 항목의 오른쪽 상단 모서리에 있습니다.

내가들을 수있는 일종의 콜백이 있습니까? 아니면 다음과 같이 할 수 addListener("close", infowindow1, etc있습니까?


내가 여기 발견 한 유일한 일관성있는 해결책은에 대한 포인터를 유지하는 것입니다 infoWindow및 확인 .getMap()당신이이 종료되었는지 여부를 확인해야 할 때마다 방법을.

그 이유는 다른 요소를 클릭하면 closeclick이벤트가 발생 하지 않고 다른 이유로 인해 infoWindow가 닫힐 수 있기 때문 입니다.

var infoWindow = new google.maps.InfoWindow({ content: 'Something to put here.' });
infoWindow.open(map, infoWindow);

setInterval(function ()
{
    console.log("infoWindow is bound to map: "+(infoWindow.getMap() ? true : false));

}, 1000);

... 문자 그대로 infoWindow"X"버튼을 사용하여 닫혔 는지 여부 만 신경 쓰면 모니터링 closeclick이 괜찮습니다. 그러나 폐쇄되었거나 폐쇄 된 다른 이유가 있습니다.


closeclick도움이 될 수있는 infowindows 전화 이벤트가 있습니다.

var currentMark;
var infoWindow = new google.maps.InfoWindow({
            content: 'im an info windows'
        });
google.maps.event.addListener(marker, 'click', function () {
          infoWindow.open(map, this);
          currentMark = this;

});
google.maps.event.addListener(infoWindow,'closeclick',function(){
   currentMark.setMap(null); //removes the marker
   // then, remove the infowindows name from the array
});

이 시도:

var closeBtn = $('.gm-style-iw').next();
closeBtn.click(function(){
    //other things you want to do when close btn is click
    that.infowindow.close();
});

css / 위치를 변경 한 후에는 클릭 버튼이 Safari에서 작동하지 않기 때문에이 클릭 기능을 덮어 씁니다.

참고 URL : https://stackoverflow.com/questions/6777721/google-maps-api-v3-infowindow-close-event-callback

반응형