Javascript 在标记上切换圆单击

Javascript 在标记上切换圆单击,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我有一些标记是通过一系列的电线放置的。在这些标记周围有半径圆。我试图仅在单击相关标记时显示圆圈,然后在关闭信息框时隐藏。现在,无论是否单击标记,圆圈都会显示。我不确定我做错了什么。有人能告诉我我忽略了什么吗 -谢谢 function initialize() { var locations = [ ['Siren 1', 32.832, -96.629, 1], ['Siren 2', 32.827, -96.644, 2], ['Siren 3', 3

我有一些标记是通过一系列的电线放置的。在这些标记周围有半径圆。我试图仅在单击相关标记时显示圆圈,然后在关闭信息框时隐藏。现在,无论是否单击标记,圆圈都会显示。我不确定我做错了什么。有人能告诉我我忽略了什么吗

-谢谢

function initialize() {
   var locations = [
      ['Siren 1', 32.832, -96.629, 1],
      ['Siren 2', 32.827, -96.644, 2],
      ['Siren 3', 32.824, -96.612, 3],
      ['Siren 4', 32.809, -96.658, 4],
      ['Siren 5', 32.805, -96.634, 5],
      ['Siren 6', 32.809, -96.614, 6],
      ['Siren 7', 0, -0, 7],
      ['Siren 8', 0, -0, 8],
      ['Siren 9',  32.794, -96.613, 9],
      ['Siren 10', 32.776, -96.61, 10],
      ['Siren 11', 32.761, -96.633, 11],
      ['Siren 12', 32.764, -96.598, 12],
      ['Siren 13', 32.773, -96.581, 13],
      ['Siren 14', 32.748, -96.614, 14],
      ['Siren 15', 0, -0, 15],
      ['Siren 16', 32.751, -96.576, 16],
      ['Siren 17', 32.75,  -96.55, 17],
      ['Siren 18', 0, -0, 18],
      ['Siren 19', 32.728, -96.583, 19],
      ['Siren 20', 32.741, -96.566, 20],
      ['Siren 21', 32.738, -96.545, 21],
      ['Siren 22', 32.722, -96.537, 22],
      ['Siren 23', 32.708, -96.558, 23],
      ['Siren 24', 32.696, -96.499, 24],
      ['Siren 25', 32.694, -96.564, 25]
    ];

    var mapOptions = {
          center: new google.maps.LatLng(32.782878, -96.609862),

          panControl: false,
          zoom: 11,
          mapTypeControl: true,
    mapTypeControlOptions: {
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    },
    zoomControl: true,
    zoomControlOptions: {
      style: google.maps.ZoomControlStyle.SMALL,
      position: google.maps.ControlPosition.RIGHT_TOP
    },
          mapTypeId: google.maps.MapTypeId.HYBRID
        };

        var map = new google.maps.Map(document.getElementById("map"),
    mapOptions);

    function MyLogoControl(controlDiv) {
    controlDiv.style.padding = '5px';
    var logo = document.createElement('IMG');
    logo.src = 'images/watermark_MW_GMap.png';
    logo.style.cursor = 'pointer';
    controlDiv.appendChild(logo);

    google.maps.event.addDomListener(logo, 'click', function() {
        window.location = 'http://www.mesquiteweather.net';
    });
  }

   var logoControlDiv = document.createElement('DIV');
   var logoControl = new MyLogoControl(logoControlDiv);
   logoControlDiv.index = 0; // used for ordering
   map.controls[google.maps.ControlPosition.TOP_LEFT].push(logoControlDiv);

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    var image = 'http://maps.google.com/intl/en_us/mapfiles/ms/micons/green.png';

    for (i = 0; i < locations.length; i++) {
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        icon: image
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));

// Add circle overlay and bind to marker
    var circle = new google.maps.Circle({
        map: map,
        radius: 4828,    // metres
        strokeColor: '#FF0000',
        strokeOpacity: 0.8,
        strokeWeight: 2,
        fillColor: '#FF0000',
        fillOpacity: 0.35,
      });
         circle.bindTo('center', marker, 'position');

    }
  }
函数初始化(){
变量位置=[
[Siren 1',32.832,-96.629,1],
[siren2',32.827,-96.644,2],
[siren3',32.824,-96.612,3],
[siren4',32.809,-96.658,4],
[Siren 5',32.805,-96.634,5],
[siren6',32.809,-96.614,6],
[siren7',0,-0,7],
[siren8',0,-0,8],
[siren9',32.794,-96.613,9],
[Siren 10',32.776,-96.61,10],
[Siren 11',32.761,-96.633,11],
[Siren 12',32.764,-96.598,12],
[siren13',32.773,-96.581,13],
[Siren 14',32.748,-96.614,14],
[siren15',0,-0,15],
[Siren 16',32.751,-96.576,16],
[siren17',32.75,-96.55,17],
[Siren 18',0,-0,18],
[siren19',32.728,-96.583,19],
[Siren 20',32.741,-96.566,20],
[siren21',32.738,-96.545,21],
[siren22',32.722,-96.537,22],
[siren23',32.708,-96.558,23],
[siren24',32.696,-96.499,24],
[siren25',32.694,-96.564,25]
];
变量映射选项={
中心:新google.maps.LatLng(32.782878,-96.609862),
泛控制:错误,
缩放:11,
mapTypeControl:true,
mapTypeControlOptions:{
样式:google.maps.MapTypeControlStyle.DROPDOWN_菜单
},
动物控制:对,
ZoomControl选项:{
样式:google.maps.ZoomControlStyle.SMALL,
位置:google.maps.ControlPosition.RIGHT\u顶部
},
mapTypeId:google.maps.mapTypeId.HYBRID
};
var map=new google.maps.map(document.getElementById(“map”),
地图选项);
函数MyLogoControl(controlDiv){
controlDiv.style.padding='5px';
var logo=document.createElement('IMG');
logo.src='images/watermark_MW_GMap.png';
logo.style.cursor='pointer';
controlDiv.appendChild(徽标);
google.maps.event.addDomListener(logo,'click',function(){
window.location=http://www.mesquiteweather.net';
});
}
var logoControlDiv=document.createElement('DIV');
var logoControl=新的MyLogoControl(logoControlDiv);
logoControlDiv.index=0;//用于排序
map.controls[google.maps.ControlPosition.TOP_LEFT].push(logoControlDiv);
var infowindow=new google.maps.infowindow();
var标记,i;
var图像处理http://maps.google.com/intl/en_us/mapfiles/ms/micons/green.png';
对于(i=0;i
以下内容与您描述的内容相同:我知道您在任何给定时间只希望显示一个圆圈。如果不是这样的话,请评论,我会尽力纠正

for (i = 0; i < locations.length; i++) {
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map,
    icon: image
  });

  var openCircle;  // declare the circle

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);

      if (openCircle !== undefined) {
        openCircle.setMap(null);
      }

      openCircle = new google.maps.Circle({
        map: map,
        radius: 4828,    // metres
        strokeColor: '#FF0000',
        strokeOpacity: 0.8,
        strokeWeight: 2,
        fillColor: '#FF0000',
        fillOpacity: 0.35,
      });

      openCircle.bindTo('center', marker, 'position');

      google.maps.event.addListener(infowindow,'closeclick',function(){
        openCircle.setMap(null);
      }); 
    }
  })(marker, i));

  // remove what's below

  /*
  var circle = new google.maps.Circle({
    map: map,
    radius: 4828,    // metres
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35,
  });

     circle.bindTo('center', marker, 'position');
     */

}
for(i=0;i
单击标记时,我看不到任何显示圆圈的代码。发布的代码创建了标记和圆,并在创建时显示圆({map:map}这样做)。单击标记时,您看不到任何显示圆的代码,因为这是我遇到的问题。我尝试了很多不同的方法。我已经做了很多搜索,列出了很多。我需要将一个点击事件分配给点击标记时将显示的圆圈,但我没有任何成功。因此我请求帮助。我不确定还能补充什么信息。