는 V3

0

만 아약스 호출을 통해 두 번째 클릭에 개관, 나는 아약스 호출을 통해 위의는 V3

var openedInfoWindow = null; 
var infoWindow = new google.maps.InfoWindow(); 

function profileInitialiser(marker, location) { 
google.maps.event.addListener(marker, 'click', function(){ 
     new Ajax.Request('/ajax/', { 
     parameters: {'action':'profileInfo', 'id':location.id}, 
     onSuccess: function(transport){ 
      addInfoWindow(marker, transport.responseText, location.id); 
     } 
    }); 
}); 
} 

function addInfoWindow(marker, content, id) { 
    google.maps.event.addListener(marker, 'click', function() { 
    if (openedInfoWindow != null) { 
     openedInfoWindow.close(); 
    } 
    infoWindow.setContent(content); 
    infoWindow.open(this.map, marker); 
    openedInfoWindow = infoWindow; 
    google.maps.event.addListener(infoWindow, 'closeclick', function() { 
    openedInfoWindow = null; 
    }); 
}); 
} 

를 내지도에 정보창을 열어 코드 아래 사용하고, 개방하지 code, profileInitialiser 함수는 Google지도의 마커에로드하는 동안 호출합니다. 처음에는 ajax 호출을 통해 마커를 클릭하면 infowindow의 내용이 응답으로 제공됩니다. 두 번째 클릭시 infowindow가 열립니다. 다음 번에 infowindow를로드하는 마커를 클릭하면 첫 번째 클릭이 발생합니다.
이전에이 버그가 있었습니까? 어떤 사람이이 문제를 해결하도록 도와 줄 수 있습니까?

답변

0

AddInfoWindow 함수는 데이터가 서버에서 다시 돌아올 때 마커에 클릭 수신기를 추가하기 만합니다. 또한 infoWindow에서 내용을 열어야합니다.

var openedInfoWindow = null; 
var infoWindow = new google.maps.InfoWindow(); 

function profileInitialiser(marker, location) { 
// only do this on the first click 
google.maps.event.addListenerOnce(marker, 'click', function(){ 
     new Ajax.Request('/ajax/', { 
     parameters: {'action':'profileInfo', 'id':location.id}, 
     onSuccess: function(transport){ 
      addInfoWindow(marker, transport.responseText, location.id); 
     } 
    }); 
}); 
} 

function addInfoWindow(marker, content, id) { 
    // display the content when the marker is clicked   
    google.maps.event.addListener(marker, 'click', function() { 
    if (openedInfoWindow != null) { 
     openedInfoWindow.close(); 
    } 
    infoWindow.setContent(content); 
    infoWindow.open(this.map, marker); 
    openedInfoWindow = infoWindow; 
    google.maps.event.addListener(infoWindow, 'closeclick', function() { 
    openedInfoWindow = null; 
    }); 
    }); 
    // click on the marker to display the newly added infowindow 
    google.maps.event.trigger(marker, 'click'); 
} 
+0

난 당신의 코드를 따라하지만, 지금은 지속적으로 정보 창 (자동 트리거) 오는 마커를 클릭 : 여기

는 코드입니다. 원 클릭으로 마커를 클릭하면 아약스를 통해 콘텐츠를로드하고 정보 창을 엽니 다. 이것에 제안 해주세요. –

+0

addListener에서 addListenerOnce로 profileInitialiser를 수정 했습니까? – geocodezip

+0

아니요, profileInitialiser에서 수정하지 않았습니다. –

0

클릭 이벤트 수신기를 두 번 추가하는 이유는 무엇입니까? addInfoWindow 함수에서 리스너를 제거하기 만하면됩니다.

function addInfoWindow(marker, content, id) { 

if (openedInfoWindow != null) { 
    openedInfoWindow.close(); 
} 
infoWindow.setContent(content); 
infoWindow.open(this.map, marker); 
openedInfoWindow = infoWindow; 
google.maps.event.addListener(infoWindow, 'closeclick', function() { 
openedInfoWindow = null; 
}); 
}