我已经使用InfoWindow获得了Google地图。 在infowindow里面,我有一个文本,最后是一个链接" Open"在地图上方打开一个div。 现在,我想点击链接"打开"关闭infowindow。
这是我用来打开div的代码
// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
var map = null;
function initialize() {
// create the map
var myOptions = {
zoom: 11,
center: new google.maps.LatLng(51.519243, -0.126661),
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map-canvas-big"),
myOptions);
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
var point = new google.maps.LatLng(51.5608308012934, -0.0540925428914196);
var marker = createMarker(point, " Clapton ", "<div class='scrittafumetto' id='proprieta_4940'><strong><div class='titolo'> Title</div></strong><br /><a class='mostra_vedi'>Vedi</a></span></div>");
}
var infowindow = new google.maps.InfoWindow({
size: new google.maps.Size(150, 50)
});
google.maps.event.addListener(marker, 'click', function(marker, i) {
var marker_id = marker.id;
if ($('#new-overview-main_' + marker_id).css('display') == 'block') {
$('#new-overview-main_' + marker_id).css('display', 'none');
} else {
$('#new-overview-main_' + marker_id).css('display', 'block');
}
});
function createMarker(latlng, name, html) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
zIndex: Math.round(latlng.lat() * -100000) << 5
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map, marker);
});
// save the info we need to use later for the side_bar
gmarkers.push(marker);
// add a line to the side_bar html
}
然后,当我点击&#34; Vedi&#34;我使用以下代码在地图上方打开一个div:
jQuery(document).on('click', '.scrittafumetto', function(event){
var marker_id = $(this).attr('id');
infoWindowClosed = true;
marker_id = marker_id.replace("proprieta_", "");
$('.new-overview-main').css('display', 'none');
if ($('#new-overview-main_'+marker_id).css('display') == 'block') {
$('#new-overview-main_'+marker_id).css('display', 'none');
} else {
$('#new-overview-main_'+marker_id).css('display', 'block');
}
});
我以为
infoWindowClosed = true;
会做到这一点,但它不起作用。
任何提示?
谢谢,Dean。
答案 0 :(得分:0)
infowindow
作为全局变量。你应该能够在你点击“打开”的事件监听器内部调用close()
方法。
jQuery(document).on('click', '.scrittafumetto', function(event){
infowindow.close();
...
}