2012-07-08 4 views

답변

4

랩지도 요소 및지도를 재설정 할 때 다음, 단지 전체 맵 사업부를 제거하고 다시 -

내 여기 jsfiddle을 참조하십시오. 이렇게하면 문제가 해결됩니다.

gmap3 설명서에 따르면 dom 요소를 제거하기 전에 맵에서 destroy를 호출해야합니다.

HTML 코드

<div> 
    <div id="map"></div> 
</div> 

<a href="#" onclick="restore();">restore</a>​ 

자바 스크립트

var dlat = 53.9783997; // default map latitude 
var dlng = -1.5666347; // default map longitude 
var dzoom = 6; // default map zoom 
var dmaptype = "roadmap"; // default map type 
// create gmap 
$('#map').gmap3({ 
    action: 'init', 
    options: { 
     center: [dlat, dlng], 
     zoom: dzoom, 
     mapTypeId: dmaptype, 
     mapTypeControl: true, 
     mapTypeControlOptions: { 
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU 
     }, 
     navigationControl: true, 
     scrollwheel: true, 
     streetViewControl: true 
    } 
}); 


function restore() { 

    $('#map').gmap3({ 
     action: 'destroy' 
    }); 

    var container = $('#map').parent(); 
    $('#map').remove(); 
    container.append('<div id="map"></div>'); 

    // create new gmap 
    $('#map').gmap3({ 
     action: 'init', 
     options: { 
      center: [dlat, dlng], 
      zoom: dzoom, 
      mapTypeId: dmaptype, 
      mapTypeControl: true, 
      mapTypeControlOptions: { 
       style: google.maps.MapTypeControlStyle.DROPDOWN_MENU 
      }, 
      navigationControl: true, 
      scrollwheel: true, 
      streetViewControl: true 
     } 
    }); 

}​ 
+0

그게 작동하지 않습니다. Alex에게 환호 –

3

여기에 다른 방법이다 : 오히려지도를 파괴하고 완전히를 다시보다 초기 상태를 저장 수 있고 그 상태로 복원 이렇게 : http://jsfiddle.net/UvAL3/1/

(이러한 함수는 V2에서 API의 일부로 존재 함)

관련 문제