cdiego

_mapas_infowindow

Feb 4th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.35 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <head>
  3.     <style>
  4.         #mapa{
  5.             width: 400px;
  6.             height: 400px;
  7.             float:left;
  8.             background: green;
  9.         }
  10.         #infor{
  11.             width: 400px;
  12.             height: 400px;
  13.             float:left;
  14.         }
  15.     </style>
  16. <!--IMPORTANTE RESPETAR EL ORDEN -->
  17. <!--ESTILOS DE BOOSTRAP -->
  18. <link href="css/bootstrap.min.css" rel="stylesheet" />
  19. <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
  20. <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js" ></script>
  21. <!--ARCHIVOS JAVASCRIPT DE BOOTSTRAP -->
  22. <script type="text/javascript" src="js/bootstrap.min.js" ></script>
  23. <script>
  24.     //VARIABLES GENERALES
  25.         //declaras fuera del ready de jquery
  26.     var nuevos_marcadores = [];
  27.     var marcadores_bd= [];
  28.     var mapa = null; //VARIABLE GENERAL PARA EL MAPA
  29.     //FUNCION PARA QUITAR MARCADORES DE MAPA
  30.     function limpiar_marcadores(lista)
  31.     {
  32.         for(i in lista)
  33.         {
  34.             //QUITAR MARCADOR DEL MAPA
  35.             lista[i].setMap(null);
  36.         }
  37.     }
  38.     $(document).on("ready", function(){
  39.        
  40.         //VARIABLE DE FORMULARIO
  41.         var formulario = $("#formulario");
  42.        
  43.         var punto = new google.maps.LatLng(19.339027,-98.948541);
  44.         var config = {
  45.             zoom:8,
  46.             center:punto,
  47.             mapTypeId: google.maps.MapTypeId.ROADMAP
  48.         };
  49.         mapa = new google.maps.Map( $("#mapa")[0], config );
  50.        
  51.         var combo_asesorias = $("#combo_asesorias");
  52.         $.ajax({
  53.             type:"POST",
  54.             url:"iajax.php",
  55.             data:"&tipo=listar_asesorias",
  56.            dataType:"JSON",
  57.            success:function(d){
  58.                combo_asesorias.html("");
  59.                 $.each(d.mensaje, function(i, item){
  60.                     var campo = "<option value='"+item.Id_ase+"' >"+item.Nombre_ase+"</option>";
  61.                     combo_asesorias.append(campo);
  62.                 })
  63.             },
  64.             beforeSend:function(){
  65.                
  66.             }
  67.            
  68.         });
  69.        
  70.        
  71.         combo_asesorias.on("change", function(){
  72.             var id = $(this).val();
  73.             listar(id);
  74.         })
  75.        
  76.     });
  77.     function listar(id)
  78.     {
  79.        limpiar_marcadores(marcadores_bd);
  80.        $.ajax({
  81.                type:"POST",
  82.                url:"iajax.php",
  83.                dataType:"JSON",
  84.                data:"&tipo=listar_puntos&id="+id,
  85.               success:function(data){
  86.                   if(data.estado=="ok")
  87.                    {
  88.                        $.each(data.mensaje, function(i, item){
  89.                        
  90.                             //DECLARAR EL INFOWINDOW, Y DARLE EL CONTENIDO DEL
  91.                             //CAMPO Direccion_AE DE LA BASE DE DATOS
  92.                             var infowindow = new google.maps.InfoWindow({
  93.                               content: item.Direccion_AE
  94.                             });
  95.                        
  96.                             var posi = new google.maps.LatLng(item.latitud, item.longitud);//bien
  97.                             var marca = new google.maps.Marker({
  98.                                 position:posi,
  99.                                 infoWindow:infowindow
  100.                             });
  101.                            
  102.                             //AGREGAR EVENTO PARA ABRIR INFOWINDOW
  103.                             //CADA VEZ QUE SE HACE CLIC EN EL MARCADOR
  104.                           google.maps.event.addListener(marca, 'click', function() {
  105.                             infowindow.open(mapa,marca);
  106.                             mapa.panTo(marca.getPosition());
  107.                           });
  108.                          
  109.                           //COMENTAR LA LINEA DE ABAJO PARA QUE NO SALGAN
  110.                           //LO INFOWINDOW ABIERTOS POR DEFECTO!
  111.                           infowindow.open(mapa, marca);
  112.  
  113.  
  114.                             marcadores_bd.push(marca);
  115.                             marca.setMap(mapa);
  116.                         });
  117.                     }
  118.                 else
  119.                     {
  120.                         alert("NO hay puntos en la BD");
  121.                     }
  122.                },
  123.                beforeSend:function(){
  124.                    
  125.                },
  126.                complete:function(){
  127.                    
  128.                }
  129.            });
  130.     }
  131.     //PLANTILLA AJAX
  132.    
  133. </script>
  134. </head>
  135. <body>
  136.     <div id="mapa">
  137.         <h2>Aquí irá el mapa!</h2>
  138.     </div>
  139.     <div id="infor">
  140.         <select id="combo_asesorias">
  141.             <option value="1" >Cargando...</option>
  142.         </select>
  143.     </div>
  144. </body>
  145. </html>
Advertisement
Add Comment
Please, Sign In to add comment