Programing

Google Maps API v3 : 이벤트 리스너를 제거하는 방법?

crosscheck 2020. 9. 11. 07:29
반응형

Google Maps API v3 : 이벤트 리스너를 제거하는 방법?


Google Maps API v3 에서 'bounds_changed'이벤트 리스너를 제거하려면 어떻게해야 합니까?

google.maps.event.removeListener(_???_);    

일반적으로 Google Maps API 문서에서 이러한 질문에 대한 답변을 찾을 수 있습니다.

Andrew가 말했듯이 addListener는 나중에 리스너를 제거하는 데 사용할 수있는 핸들을 반환합니다. 이는 단일 이벤트에 많은 리스너가있을 수 있고이를 제거하려면 연결된 각 리스너에 대한 참조를 저장해야하기 때문입니다.

동시에 모든 리스너를 제거하는 함수도 있습니다.

clearListeners(instance:Object, eventName:string);
//In your case:
google.maps.event.clearListeners(map, 'bounds_changed');

여기에 대해 읽을 수 있는 Google Maps API 참조 가 있습니다.


addListener는 나중에 removeListener에 전달할 수있는 핸들을 반환합니다.

var listenerHandle = google.maps.event.addListener(map, 'bounds_changed', function() {

google.maps.event.removeListener(listenerHandle);

이것은 현재 릴리스에서 작동하는 것 같습니다.

var listenerHandle = google.maps.event.addListener(map, 'bounds_changed', function() {
    // Handler code.
});
listenerHandle.remove();

리스너 객체를 잡을 수 없다면 리스너를 직접 제거 할 수 있습니다. google.maps.event.clearListeners(objectListened, 'event');

전의: google.maps.event.clearListeners(map, 'bounds_changed');

참고 URL : https://stackoverflow.com/questions/1544151/google-maps-api-v3-how-to-remove-an-event-listener

반응형