3

google map api v3를 사용하여 마커에 서클을 바운드했습니다. 마커를 드래그 가능하게 만들면 서클도 움직이기 때문에이 점을 알고 있습니다.Google지도 API v3 마커에 연결된 서클 숨기기 및 표시

어떻게 마커를 클릭하면 원을 참조 할 수 있습니까? 원이 보이지 않으면 그 원을 보여줄 필요가 있습니다. 여기

, 나는 나뿐만 아니라 중앙 바인딩 바인딩 밖으로 rem'd지도를 할 필요가 생각하는 저를 주도 유래에 대한 답을 발견 마커와 원

var markerOptions = { 
title: title, 
icon: markerImage, 
shadow: markerShadow, 
position: latlng, 
map: map 
} 
var marker = new google.maps.Marker(markerOptions); 
// Add a Circle overlay to the map. 
var circle = new google.maps.Circle({ 
map: map, 
radius: 50*1609.34,// 50 MI 
visible: false 
}); 
//circle.bindTo('map', marker); 
circle.bindTo('center', marker, 'position'); 

를 만들 수있는 코드 만 그것은 작동하지 않았다.

여기 내 마커 이벤트입니다.

google.maps.event.addListener(marker, "click", function() { 
var infowindowOptions = { 
content: html 
} 
var infowindow = new google.maps.InfoWindow(infowindowOptions); 
cm_setInfowindow(infowindow); 
infowindow.open(map, marker); 
marker.setIcon(markerImageOut); 
marker.circle({visible: true}); 

아이디어가 없습니다. 방금 클릭하거나 마우스를 올려 놓은 바운드 서클과 상호 작용해야합니다.

답변

5

하나의 옵션은 원을 ._myCircle과 같은 마커의 속성으로 만들고 클릭 핸들러에서 marker._myCircle로 참조하는 것입니다.

는 마커의 _myCircle 속성으로 원을 추가

var circle = new google.maps.Circle({ 
    map: map, 
    radius: 50*1609.34,// 50 MI 
    visible: false 
}); 
circle.bindTo('center', marker, 'position'); 
marker._myCircle = circle; 

그것 (안 테스트) 같은 것을 사용 전환하려면 :

if(marker._myCircle.getMap() != null) marker._myCircle.setMap(null); 
else marker._myCircle.setMap(map); 
+0

감사합니다 귀하의 회신. 원을 표시 자의 속성으로 지정하려면 어떻게해야합니까? – Timberline411

+0

내 대답에 예제가 있습니다 (marker._myCircle는 "마커의 속성"입니다). 그것은 당신을 위해 작동하지 않습니다? – geocodezip

+0

용서해주세요.하지만 저는이 API로 시작했고 객체 모델에 익숙하지 않았습니다. market._myCircle을 내가 만든 원과 동등하게 설정하려면 어떻게해야합니까? 센터가 말하고있는 마커에 바인딩되어 있습니다. 즉, 방금 만든 원과 동일한 표식의 속성을 만드는 JS 코드는 무엇입니까? – Timberline411

0
var rad =".$this->conf['radius'] * 1000 ."; //convert km to meter 
var populationOptions = { 
    strokeColor: '#FF0000', 
    strokeOpacity: 0.8, 
    strokeWeight: 1, 
    fillColor: '#FF0000', 
    fillOpacity: 0.35, 
    map: map,//map object 
    center: new google.maps.LatLng($corr_match[0], $corr_match[1]),//center of circle 
    radius: rad 
}; 
var cityCircle = new google.maps.Circle(populationOptions);