Причина, по которой для каждого маркера появляется одно окно, заключается в том, что вы создаете один ящик для каждого маркера.Если вам нужен только один блок, просто создайте его один раз и повторно используйте для каждого маркера.В вашем случае это просто включило бы помещение кода реализации вне функции addMarker:
<script type="text/javascript">
function initialize() {
// Creating the map
var map = new google.maps.Map(document.getElementById("map_canvas"), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
});
// Styling the map
var styledMap = [{
featureType: "all",
stylers: [{
saturation: -80
}]
}, {
featureType: "road.arterial",
elementType: "geometry",
stylers: [{
hue: "#00ffee"
}, {
saturation: 50
}]
}, {
featureType: "poi.business",
elementType: "labels",
stylers: [{
visibility: "off"
}]
}
];
//Calling the map styles
map.setOptions({
styles: styledMap
});
// List of images
var images = [ 'images/icon1.png', 'images/icon2.png','images/icon3.png'];
loadMarkers();
// Zoom and center the map to fit the markers
var bounds = new google.maps.LatLngBounds();
// Move the InfoBox creation here
var myOptions = {
content: boxTitle
, boxStyle: {
color: "#fff"
, textAlign: "left"
, fontSize: "12pt"
, width: "250px"
, height: "230px"
, padding: "10px"
, fontFamily: "Arial"
, fontStyle: "bold"
, background : "transparent url( 'images/sampleback.png' ) no-repeat 0 0",
}
, disableAutoPan: true
, pixelOffset: new google.maps.Size(-90,-280)
, position: new google.maps.LatLng(data.lat, data.long)
, closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
, isHidden: false
, pane: "floatPane"
};
var ib = new InfoBox(myOptions);
// Create the markers
function addMarker(data, images) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.lat, data.long),
map: map,
title: data.name,
icon: images[--data["dot-type"]]
});
var boxTitle = document.createElement("div");
var boxNum = data.id;
var boxTitle= data.name;
var boxAddress = data.street;
var boxCity = data.city;
var boxSt = data.st;
var boxZip = data.zip;
var boxText = document.createElement("div");
boxText.content = "<p class='sitenumber'>" + "Site #" + boxNum + "</p>" +"<h2>"+boxTitle+"</h2>" + "<p>" + boxAddress + "</p>"+ "<p>" + boxCity + ", " + boxSt + " " + boxZip +"</p>" + "<b>" + "<a href='#'>" + "<div class= 'siteButton'>" + "VIEW THIS SITE DETAIL" + "</div>" + "</a>";
google.maps.event.addListener(marker, "click", function (event) {
ib.setContent(boxText.content);
ib.open(map, marker);
});
bounds.extend(new google.maps.LatLng(data.lat, data.long));
map.fitBounds(bounds);
}
function loadMarkers() {
var siteUrl = "data/main.js";
$.ajax({
dataType: "json",
url: siteUrl,
success: load
});
function load(data) {
for (index in data) addMarker(data[index], images);
}
};
}
</script>