google 个地图上的点击和关闭点击事件
click and closeclick event on google maps
我想在同一个标记上打开两个信息window。在 'click' 事件中,第一个信息 window 应该关闭(我已经在地图上显示)并打开第二个信息 window。关于关闭第二个信息window,我想打开第一个window。
这是我的代码:
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);
});
由于信息窗口之间的唯一区别是所需的内容,您可以使用单个信息窗口并简单地切换内容:
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);
});
我想在同一个标记上打开两个信息window。在 'click' 事件中,第一个信息 window 应该关闭(我已经在地图上显示)并打开第二个信息 window。关于关闭第二个信息window,我想打开第一个window。
这是我的代码:
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);
});
由于信息窗口之间的唯一区别是所需的内容,您可以使用单个信息窗口并简单地切换内容:
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);
});