我想在同一个标记上打开两个infowindows。在'click'事件中,第一个infowindow应该关闭(我已在地图上显示)并打开第二个infowindow。在关闭第二个infowindow时,我想打开第一个窗口。
这是我的代码:
var infowindow = new google.maps.InfoWindow({
content: content,
marker:marker,
maxWidth: 300,
image:image,
id:vehicleNo
});
var openinfowindow = new google.maps.InfoWindow({
content: contentone,
marker:marker,
maxWidth: 300,
image:image,
id:vehicleNo
});
google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){
return function() {
openinfowindow.close();
infowindow.setContent(content);
infowindow.open(map,marker);
};
})(marker,content,infowindow));
google.maps.event.addListener(infowindow,'closeclick',function(){
openinfowindow.setContent(contentone);
openinfowindow.open(map,marker);
});
答案 0 :(得分:0)
由于infowindows之间的唯一区别是所需的内容,您可以使用单个infowindow并简单地切换内容:
var infowindow = new google.maps.InfoWindow({
contents:[content,contentOne],
marker:marker,
maxWidth: 300,
image:image,
id:vehicleNo
});
google.maps.event.addListener(marker,'click', (function(marker,
contents,
infowindow){
return function() {
infowindow.contents=[contents[0],contents[1]];
infowindow.setContent(contents[0]);
infowindow.open(map,marker);
};
})(marker,infowindow.contents,infowindow));
google.maps.event.addListener(infowindow,'closeclick',function(){
var that=this;
that.contents.reverse();
that.setContent(this.contents[0]);
setTimeout(function(){
that.open(map,marker);},
100);
});