Google Maps API v3을 사용 중이며 현재 확대/축소 수준을 기준으로 마커를 오프셋해야합니다. 'ZOOM_CHANGED'이벤트 트리거시 JS의 전역 변수 설정 - Google지도 API
google.maps.event.addListener (지도, 기능() { current_zoom_level = map.getZoom (:
나는 전역 변수 current_zoom_level 및 확대/축소에 대한 이벤트 리스너가); alert (current_zoom_level); });초기화 코드와 오프셋을 계산하는 코드에서이 비트를 사용해 보았습니다. 경고는 정확한 현재 줌 레벨을 표시하지만 build_loan_markers()에서 액세스 할 때 (여기서 오프셋을 계산 함) current_zoom_level은 정의되지 않습니다.
function build_loan_markers() {
var offset; 알림 (current_zoom_level); if (! window.current_zoom_level) { window.current_zoom_level = 1; } 오프셋 = 1 / (window.current_zoom_level^2); 경고 ('zoom :'+ current_zoom_level + 'offset :'+ offset); 등 }
이 변수를 어떻게 전역 적으로 설정할 수 있습니까?
게시물의 코드를 형식화하십시오. – plexer