For all my life I canβt get only one info indicator, which will be displayed simultaneously in the V3 API. I need to close it before the next opening. Also, looking that the info window closes anywhere on the map. Is this part of the initialization function?
Here is my full script:
var map = null;
var markers = [];
var adUnit;
var center = new google.maps.LatLng(39.676502,-105.162101);
function initialize() {
var mapOptions = {
zoom: 10,
center: center,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
},
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.LEFT_BOTTOM
},
panControl: false,
mapTypeId: google.maps.MapTypeId.TERRAIN
}
map = new google.maps.Map($('#map_canvas')[0], mapOptions);
loadXML();
var adUnitDiv = document.createElement('div');
var adUnitOptions = {
format: google.maps.adsense.AdFormat.BUTTON,
position: google.maps.ControlPosition.RIGHT_BOTTOM,
publisherId: 'ca-google-maps_apidocs',
map: map,
visible: true
};
adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
}
function loadXML() {
$.get('data.xml', function(data) {
$(data).find('marker').each(function() {
var lat = $(this).attr('lat')
var lng = $(this).attr('lng')
var name = $(this).attr('name')
var type = $(this).attr('type')
var LatLng = new google.maps.LatLng(parseFloat($(this).attr('lat')),
parseFloat($(this).attr('lng')));
var myToggleData = {
type : $(this).attr('type'),
skill : $(this).attr('skill'),
eta_whatever_that_means : parseFloat($(this).attr('eta'))
}
var marker = new google.maps.Marker({
position : LatLng,
map : map,
icon : 'images/marker.png',
title : $(this).attr('name'),
data : myToggleData
});
var html ='<div id="winBackground"> <div class="winTitle">' + name + '</div> <div class="winHead">Type: <div class="winData">' + type + '</div></div> </div>';
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
markers.push(marker);
});
});
}
function toggleMarkers(attr,val) {
if (markers){
for (i in markers) {
if(markers[i].data[attr] == val){
var visibility = (markers[i].getVisible() == true) ? false : true;
markers[i].setVisible(visibility);
}
}
}
}
source
share