var blackandwhite, infowindow, map, mapOptions, map_lat, map_lng, map_zoom, markers; $(function() { getRegiones(); agregarTodasOption('comuna'); inicializarMapa(); function inicializarMapa() { if ($("#map-iglesia").length) { markers = new Array(); infowindow = false; blackandwhite = [ { featureType : "all", elementType : "all", stylers : [ { saturation : -100 } ] } ]; switch ($("#codPais").val()) { case 'CL': mapOptions = { mapTypeId : google.maps.MapTypeId.ROADMAP, disableDefaultUI : true, scrollwheel : false, streetViewControl : false, styles : blackandwhite, zoom : 12, center : new google.maps.LatLng(-33.4716446, -70.6332455) }; break; case 'AR': mapOptions = { mapTypeId : google.maps.MapTypeId.ROADMAP, disableDefaultUI : true, scrollwheel : false, streetViewControl : false, styles : blackandwhite, zoom : 12, center : new google.maps.LatLng(-34.6000068, -58.3855147) }; break; case 'CO': mapOptions = { mapTypeId : google.maps.MapTypeId.ROADMAP, disableDefaultUI : true, scrollwheel : false, streetViewControl : false, styles : blackandwhite, zoom : 12, center : new google.maps.LatLng(4.6227476, -74.0932217) }; break; case 'PE': mapOptions = { mapTypeId : google.maps.MapTypeId.ROADMAP, disableDefaultUI : true, scrollwheel : false, streetViewControl : false, styles : blackandwhite, zoom : 12, center : new google.maps.LatLng(-12.0552608, -77.0627323) }; break; } map = new google.maps.Map(document.getElementById("map-iglesia"), mapOptions); google.maps.event.addListener(map, 'click', function() { return infowindow.close(); }); } } $(".map-zoom-in").click(function() { map.setZoom(map.getZoom() + 1); return false; }); $(".map-zoom-out").click(function() { map.setZoom(map.getZoom() - 1); return false; }); $("#comuna").change(function() { DWRActionUtil.execute({ namespace:'/common', action : 'iglesiasDWR', method : 'getIglesias' }, '#request.iglesias', { region : $('#region').val(), comuna : $('#comuna').val() }, function(data) { pintarTblIglesias(data); }); }); function quitarLoadingPragma(){ $(".loadingPragma").addClass("out"); setTimeout(function() { $(".loadingPragma").remove(); }, 500); } function pintarTblIglesias(iglesias) { inicializarMapa(); if (iglesias == 0) { $('#datosIglesia').hide("slow"); $('#datosIglesia').empty(); } else { $('#datosIglesia').empty(); google.maps.event.addListener(map, 'click', function() { return infowindow.close(); }); for (i = 0; i < iglesias.length; i++) { $('#datosIglesia').append("

"); $('#datosIglesia').append( "

" + iglesias[i].descripcion + "

"); $('#datosIglesia').append(""); $('#datosIglesia').append("

"); infowindow = false; var content, marker; if(iglesias[i].telefono != null){ content = "
" + "

" + iglesias[i].descripcion + "

" + "" + "
"; }else{ content = "
" + "

" + iglesias[i].descripcion + "

" + "
"; } marker = new google.maps.Marker({ position : new google.maps.LatLng(iglesias[i].longitud, iglesias[i].latitud), animation : google.maps.Animation.DROP, icon : "../img/marker.png", map : map }); marker['content'] = content; if (!infowindow) { infowindow = new google.maps.InfoWindow({ content : marker['info'] }); } google.maps.event.addListener(marker, "click", function() { for (i = 0; i < markers.length; i++) { if (this.getPosition() == markers[i].getPosition()) { map.setZoom(16) infowindow.close(); infowindow.setContent(markers[i]['content']); infowindow.open(map, markers[i]); return map.setCenter(markers[i].getPosition()); } } }); markers.push(marker); if (iglesias[i].longitud) { map.setCenter(marker.getPosition()); map.setZoom(14) quitarLoadingPragma(); } } $('#datosIglesia').show("slow"); } } }); function centrar(indice) { $("html,body,.secretmenu-container-front").animate({ scrollTop: $('#map-container-iglesia').position().top - 50 }); infowindow.close(); infowindow.setContent(markers[indice]['content']); infowindow.open(map, markers[indice]); return map.setCenter(markers[indice].getPosition()); } function agregarTodasOption(id) { if (id == "region") { $('#region').append(new Option("Seleccionar", -1)); } else if (id == "comuna") { $('#comuna').append(new Option("Seleccionar", -1)); } } function getRegiones() { DWRActionUtil.execute({ namespace:'/common', action : 'iglesiasDWR', method : 'getRegiones' }, '#request.regiones', {}, function(data) { dwr.util.removeAllOptions('region'); agregarTodasOption('region'); dwr.util.addOptions('region', data, "id", "descripcion"); }); // $("#region").addClass("selectpicker"); // $("#comuna").addClass("selectpicker"); // $("#region").show(); // $("#comuna").show(); } function getComunas() { DWRActionUtil.execute({ namespace:'/common', action : 'iglesiasDWR', method : 'getComunas' }, '#request.comunas', { region : $('#region').val() }, function(data) { dwr.util.removeAllOptions('comuna'); agregarTodasOption('comuna'); dwr.util.addOptions('comuna', data, "id", "descripcion"); $('#datosIglesia').hide("slow"); $('#datosIglesia').empty(); }); }