2012-06-01 5 views
1

내 인생에서 내가 할 수없는 이유는 무엇입니까? setMap(null)이 작동하지 않습니다. 나는 실제로 얼마나 많은 문서가 bindTo로 오버레이를 추가하는지에 대해 화가 났지만 그것을 제거하는 방법에 대해서는 한 마디도하지 못했다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?Google지도 API 3 - 바인딩 후 동그라미를 제거하십시오.

클릭하여 .radius_type에 동그라미를 만듭니다. 그런 다음 드롭 다운을 다른 모양으로 전환하면 원을 제거하지 않습니다.

내가 좋아하는지도 전화 해요 : 원을 제거

var map = new google.maps.Map(document.getElementById('map'), {...} 

// this toggles the shapes, but I can't get it to remove the circle for the marker 
$('.radius_type.selectee').click(function(){ 
     var shape = $(this).find('span').html(); 
     var opts= {...}; 

    switch(shape){ 
     case 'circle': // Here is the added circle to the second marker. 
      var circle = new google.maps.Circle(opts); 
      circle.setOptions({radius:17063,map:map}); 
      circle.bindTo('center',markers[1],'position'); 

      // It binds, now how to remove it? 

      break; 

     case 'square': 
      //tried - circle.setMap(null); 
      //tried - map.setMap(null); 
      //tried - google.map.event.setMap(null); 
      //tried - every web page on the topic. 
      // 
      // I don't understand how to unbind the circle from the marker. 
      var rect = new google.maps.rect(opts); 

      break; 

     case 'draw': 
      draw.setDrawingMode(google.maps.drawing.OverlayType.POLYGON); 
      break; 
    } 
}); 
+0

후, 귀하의 질문에 대답하고주세요 필수 대기 기간, 올바른 것으로 선택하십시오. 이것은 autoban을 위험에 빠뜨리지 않고 질문을 종료합니다. – Will

답변

2

사용 $('element').on('change',function())

0

다음 코드 시도 할 수 있습니다 :

circle.setCenter(null); 
circle.unbind('center'); 
+1

가독성을 높이기 위해 답안에 코드 형식을 추가했습니다. 왜 그리고 어떻게 작동하는지에 대한 코드에 설명을 추가했습니다. – NSNoob