여기 리셋 버튼이 v3에서 작동하도록하는 작은 해킹이 있습니다. 여기서 jQuery를 사용합니다.
var attachEventToResetButton;
// Attach event to the reset button
var attachResetEvent = function(){
var $resetImg = $('img[src*=mapcontrols3d6.png]');
// We have to check if the image is available yet.
// The reason is although the map has been loaded, the navigation might
// take some time to load and we don't know when it will be fully loaded.
// There doesn't seem to have an event for "Navigation loaded" in the API
// So here is a way to work around
if ($resetImg.length > 0)
{
$resetImg.css('cursor', 'pointer').attr('title', 'Return to center').click(function(){
alert('Clicked on reset button');
// Put your code to reset the map here. For example:
//map.setMapTypeId(MAP_TYPE_ID);
//map.setCenter(new google.maps.LatLng(LAT, LNG));
//map.setZoom(ZOOM_LEVEL);
});
window.clearInterval(attachEventToResetButton);
}
}
// Periodically checking to attach event to the reset button
attachEventToResetButton = window.setInterval(attachResetEvent, 500);
내가 한 것은 재설정 된 이미지 파일 이름이 'mapcontrols3d6.png'입니다. 그래서 이미지가로드되었는지 (즉, 사용 가능한지) 확인하기 위해 간격을 설정합니다. 그렇다면 함수에 함수를 추가합니다.
해킹이므로 다소 문제가 있습니다. 주된 것은 리셋 이미지 파일 이름에 의존해야한다는 것입니다. 따라서 Google은이를 업데이트하지 않습니다.
더 좋은 방법이 있습니까?
API v2를 사용하여 "배타적으로"나온 몇 가지 작은 동작이 v3에서 삭제 된 것 같습니다. 하지만 v3은 더 빠르고 가벼워 보인다. – Dougal