Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使Google maps标记数组全局中断标记单击事件_Javascript_Jquery_Google Maps - Fatal编程技术网

Javascript 使Google maps标记数组全局中断标记单击事件

Javascript 使Google maps标记数组全局中断标记单击事件,javascript,jquery,google-maps,Javascript,Jquery,Google Maps,在本文中,我使用以下脚本: function initialize() { var mapCanvas = document.getElementById('map'); var mapOptions = {center:new google.maps.LatLng(latitudeMid,longitudeMid),zoom:15,mapTypeId:google.maps.MapTypeId.ROADMAP,streetViewControl:false,mapTypeControl

在本文中,我使用以下脚本:

function initialize() {
  var mapCanvas = document.getElementById('map');
  var mapOptions = {center:new google.maps.LatLng(latitudeMid,longitudeMid),zoom:15,mapTypeId:google.maps.MapTypeId.ROADMAP,streetViewControl:false,mapTypeControl:true,scaleControl:true,scaleControlOptions:{position:google.maps.ControlPosition.TOP_RIGHT}};
  var map = new google.maps.Map(mapCanvas, mapOptions);
  var markers=[]; //<=========================================== inside function initialize()
  var i;
  var insertion;
  var previousMarker;
  for (i = 0; i < fotoCount; i++)  { 
    var myLatLng=new google.maps.LatLng(Latituden[i], Longituden[i]); 
    var marker = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.MARKER,{color:'00ff00',text:Letters[i]}),position:myLatLng,map:map});
    marker.set('zIndex', -i);
    marker.myIndex = i;
    markers.push(marker);
    google.maps.event.addListener(marker, 'click', function() {
      var insertion="";
      insertion='<img src=\"http://www.pdavis.nl/Ams/'.concat(Bestanden[this.myIndex],'.jpg\"></img>'); 
      insertion=insertion.concat('<table class=width100><tr><td>Bestand: ',Bestanden[this.myIndex],'</td><td class=pright>Lokatie: ',Latituden[this.myIndex],' °N., ',Longituden[this.myIndex],' °E. (',Letters[this.myIndex],')</td>');
      insertion=insertion.concat('<td class=pright>Genomen: ',Datums[this.myIndex],'</td></tr><td colspan=3>Object: ',Objecten[this.myIndex],'</td></table>');
      $('#photo').html(insertion);
      if(previousMarker!=null){previousMarker.styleIcon.set('color', '00ff00')};
      this.styleIcon.set('color', 'ff0000');
      thisMarker=this.myIndex;
      previousMarker=this;
      });
    }  
  google.maps.event.trigger(markers[0], 'click');
}
  google.maps.event.addDomListener(window, 'load', initialize);

显而易见的修复方法是将“var markers=[]”移动到函数initialize()外部(第页),使该数组成为全局数组,但现在突出显示的按钮(按钮“A”在启动时变为红色;单击的按钮变为红色)不起作用。我在这里做错了什么?

唯一奇怪的事情不是当你将索引0传递到最大值时,点击事件爆炸,因为他发送了一个负值,然后改变它,想知道它是否是-1,如果真的传递了更大的索引-1(Excepcion:Cannot read属性'\uuuuuuue3ae\uuuu')

对不起,我的英文

可能重复;使用函数闭包将标记与单击侦听器关联。Hello Alimentador:谢谢(我看的方向错了!)
function Next() {
  thisMarker++;
  if (thisMarker>=fotoCount) {thisMarker=0};
  // following line not working
  google.maps.event.trigger(markers[thisMarker], 'click');
}
function Previous() {
  thisMarker--;
  if (thisMarker==0) {thisMarker=fotoCount-1};
  // following line not working
  google.maps.event.trigger(markers[thisMarker], 'click');
}
function Previous() {
thisMarker--;
if (thisMarker==-1) {thisMarker=fotoCount-1};
// following line not working
google.maps.event.trigger(markers[thisMarker], 'click');
}