Google Maps API v3隐藏并显示绑定到标记的圆圈

Tim*_*411 3 javascript google-maps google-maps-api-3 google-maps-markers

我已成功使用google map api v3将圆圈绑定到我的标记.我知道这一点,因为如果我将标记拖动,圆圈也会移动.

如果单击标记,如何引用圆圈.如果不可见,我需要显示圆圈,反之亦然.

以下是创建标记和圆的代码

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');
Run Code Online (Sandbox Code Playgroud)

我在stackoverflow上找到了一个答案,这让我觉得我需要做一个rem'd out map binding以及中心绑定,但这不起作用.

这是我的标记点击事件.

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});
Run Code Online (Sandbox Code Playgroud)

有任何想法吗.我需要与刚刚点击或鼠标悬停的标记的边界圆相互作用.

geo*_*zip 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;
Run Code Online (Sandbox Code Playgroud)

要切换它使用类似(未测试)的东西:

if(marker._myCircle.getMap() != null) marker._myCircle.setMap(null);
else marker._myCircle.setMap(map);
Run Code Online (Sandbox Code Playgroud)