2012-09-07 33 views
13

¿Es posible que una ventana de información emergente sobre un elemento que tiene un índice Z más alto que el mapa de google?Google Maps InfoWindow Z-Index

Digamos que el mapa de Google tiene un índice Z de Zero. El elemento tiene un índice z de 100. Al hacer clic en un marcador, se visualiza una ventana de información en la misma región que el elemento. ¿Cómo hacemos para que InfoWindow pase el cursor sobre el elemento y no debajo de él?

He intentado establecer InfoWindow's z-Index a un valor más alto, pero parece que no hace nada.

He creado una demostración a continuación para demostrar el problema. ¡Cualquier ayuda sería apreciada!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<head> 
    <title>Infowindow Z-Index Test</title> 

    <script language="Javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>     
    <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>   

    <script language="Javascript" type="text/javascript"> 
     var coords = [[35.50733, 35.12768, 3]]; //, [-23.806549, 133.96059, 13], [68.169002, -134.425964, 10], [69.529715, -132.109222, 10], [80.231047, -22.730713, 7], [35.108675, -117.961578, 12]]; 
     var map;    

     function mapChoose(coords) { 
      var current = coords[Math.floor(Math.random() * (coords.length))]; 
      //mapShow(current[0], current[1], current[2], document.getElementById('map')); 
      mapShow(current[0], current[1], current[2], document.getElementById('map_canvas')); 
     }; 

     function initialize() { 

      mapChoose(coords); 
     } 

     function mapShow(lat, lng, zoom, div) { 
      var myOptions = { 
       'zoom': zoom, 
       'center': new google.maps.LatLng(lat, lng), 
       'mapTypeId': google.maps.MapTypeId.SATELLITE, 
       'disableDefaultUI': true, 
       'scrollwheel' : false, 
       'draggable': false 
      } 
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

      // markers 
      // load markers - us 
      var marker3 = new google.maps.Marker({ 
       position: new google.maps.LatLng(40.71435, -74.00597), 
       map: map, 
       icon: 'http://google-maps-icons.googlecode.com/files/kitesurfing.png', 
       draggable: true 
      }); 
      marker3.setTitle("New York");     


      // info windows     
      var contentString = $("#divContentForInfoWindow").html(); 
      $("#divContentForInfoWindow").html(''); 


      infowindow3 = new google.maps.InfoWindow({ 
       content: contentString, zIndex: 5000 // this ZIndex property doesnt appear to do anything. 
      }); 

      google.maps.event.addListener(marker3, 'click', function() { 
       infowindow3.open(map, marker3); 

      }); 

     }; 

    </script> 

</head> 


<body onload="initialize()" onunload="GUnload()"> 

    <!-- Google canvas element | Z-Index of 0 --> 
    <div id="map_canvas" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; z-index: 0;"></div>   


    <!-- Floating block of text | Z-Index of 100 --> 
    <div id="FloatingBlock" style='z-index: 100;position: absolute;left: 50px;top:75px;font-size: 16px;width: 525px;text-align: left;color: #111;background-color:#fff;opacity:.80;filter:alpha(opacity=80);'> 

     <b>This layer is floating above the google map because the Z-Index has been set higher. <br /></b> 

     Hello world hello world hello world hello world hello world hello world hello world<br /> 
     hello world hello world hello world hello world hello world hello world hello world<br /> 
     Hello world hello world hello world hello world hello world hello world hello world<br /> 
     hello world hello world hello world hello world hello world hello world hello world<br /> 
     Hello world hello world hello world hello world hello world hello world hello world<br /> 
     hello world hello world hello world hello world hello world hello world hello world<br /> 

     <div class="text"> 

      <!-- <input type="button" id="btntest" value="Open Info Window" onclick="showInfoWindow2();" /><input type="button" id="btntest2" value="hide Info Window" onclick="hideInfoWindow2();" />--> 
    </div> 

    <div style="clear:both;"></div> 

    </div>  
    <!--/can delete this, not used --> 

    <!-- everything IN here will appear in the google maps info window --> 
    <div id="divContentForInfoWindow">  

     This is popup content. <br />This is popup content. <br /> 
     This is popup content. <br />This is popup content. <br /> 
     This is popup content. <br />This is popup content. <br /> 
     This is popup content. <br />This is popup content. <br /> 
     This is popup content. <br />This is popup content. <br /> 
     This is popup content. <br />This is popup content. <br /> 

    </div> 
    <br /><br /><br />   
    <!--/everything in here will appear in the google maps info window --> 
</body> 

+3

En realidad no podrá ajustar el índice Z de la manera en que lo intenta. Las relaciones CSS de padres y niños no te permitirán. Básicamente, siempre y cuando el mapa sea un índice z más bajo que el bloque flotante, las ventanas de información nunca podrán estar encima con esta configuración. Su mejor opción sería probar [CustomOverlays] (https://developers.google.com/maps/documentation/javascript/examples/overlay-simple) o intentar agregar su div flotante en el mapa a través del DOM – jassok

Respuesta

5

uso infowindow.setZIndex (Número);

+0

No estoy seguro de por qué esto no se votó. Funciona para mi. Documentos completos aquí: https://developers.google.com/maps/documentation/javascript/reference#InfoWindow – CHawk

+0

¡Alguien acepta esta respuesta! – skwidbreth

+0

En mi humilde opinión, esto no funcionará cuando trabaje con elementos fuera del mapa. Cada elemento posicionado establece un nuevo contexto de apilamiento, por lo que 'z-index' no lo llevará muy lejos en un entorno con docenas de elementos posicionados. Es mejor que te apegues a la respuesta de Lexie. – wortwart

1

Puede usar un custom control en lugar del elemento exterior para colocar en el mapa. El control personalizado se coloca sobre el mapa y cuando se abre una Ventana de información, Google Maps detecta la posición del control y se mueve automáticamente y abre InfoWindow debajo del control, por lo que ambos no se superponen. En este caso, es mejor usarlo en lugar del custom overlay, porque la superposición se mueve cuando arrastra o acerca el mapa y el control siempre permanece en la misma posición.

Por lo tanto, primero hay que añadir el mapa y el control como div-s en su html, a continuación, para inicializar el mapa y después de eso para agregar el control al mapa de esa manera:

var control = document.getElementById('control'); 
map.controls[google.maps.ControlPosition.TOP_LEFT].push(control); 

Cómo simple es que;)

Cuestiones relacionadas