var id_asso = document.getElementById ( "id_asso" ).innerText; var map; var idInfoBoxAberto; var infoBox = []; var markers = []; function initialize() { var latlng = new google.maps.LatLng(-23.548278590288923, -51.44871832180041); var options = { zoom: 1, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("mapa"), options); } initialize(); function abrirInfoBox(id, marker) { if (typeof(idInfoBoxAberto) == 'number' && typeof(infoBox[idInfoBoxAberto]) == 'object') { infoBox[idInfoBoxAberto].close(); } infoBox[id].open(map, marker); idInfoBoxAberto = id; } function carregarPontos() { $.getJSON('js_mapa/pontos.php', { id_asso: id_asso }, function(pontos) { var latlngbounds = new google.maps.LatLngBounds(); $.each(pontos, function(index, ponto) { var marker = new google.maps.Marker({ position: new google.maps.LatLng(ponto.Latitude, ponto.Longitude), title: ponto.consultorio, icon: 'img/pino.png' }); var myOptions = { content: "

" + ponto.consultorio + "

", pixelOffset: new google.maps.Size(-150, 0) }; infoBox[ponto.idagenda] = new InfoBox(myOptions); infoBox[ponto.idagenda].marker = marker; infoBox[ponto.idagenda].listener = google.maps.event.addListener(marker, 'click', function (e) { abrirInfoBox(ponto.idagenda, marker); }); markers.push(marker); latlngbounds.extend(marker.position); }); var markerCluster = new MarkerClusterer(map, markers); map.fitBounds(latlngbounds); }); } carregarPontos();