简体   繁体   English

如何在地图上叠加div

[英]How to overlay a div on a map

I am currently undergoing a mini web development project of mine and I have ran into a speed bump. 我目前正在接受我的迷你网络开发项目,我遇到了一个减速带。 At the moment I am using the Google maps API to create a full screen map background to my page. 目前我正在使用Google maps API为我的网页创建全屏地图背景。 (Refer to code) I am trying to add a div on the top of the map but every time I create a div, when i load the page, i see it for a moment the it disappears? (参考代码)我试图在地图的顶部添加一个div,但每次我创建一个div,当我加载页面时,我看到它消失了一会儿? (Im just after an overlaid div with a solid background and a height of 80% and width of 100%) (我刚刚在一个叠加的div后面,背景为实心,高度为80%,宽度为100%)

  <style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0; background-color:#f6f6f6; }
 #map-canvas { 
  height: 100%;
  width:100%;
  position:absolute;
  top:0;
  bottom:0;
  left:0;
  right:0;
  margin:auto;
      }

</style>
<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=***********&sensor=false">
</script>
<script type="text/javascript">
  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(-37.8136, 144.9631),
      zoom: 16,
      mapTypeControl: false,
  draggable: false,
  scaleControl: false,
  scrollwheel: false,
      disableDefaultUI: true
    };
    var map = new google.maps.Map(document.getElementById("map-canvas"),
        mapOptions);
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

您是否尝试将div的z-index属性调整为非常高的值?

尝试操作map和div的z-index ...或者更好的尝试jquery ui对话框插件

z-index would do it, but you could take advantage of the builtin functionality designed for exactly this, instead of reinventing the wheel. z-index会这样做,但你可以利用为此设计的内置功能,而不是重新发明轮子。 Take a look at Map Controls . 看看地图控件

To achieve what you want (" Im just after an overlaid div with a solid background and a height of 80% and width of 100% ") : 为了达到你想要的目标(“ 我只是在一个具有坚实背景和高度为80%,宽度为100%的重叠div之后 ”):

css : css:

  #overlay {
      background-color: white;
      height: 80%;
      width: 100%;   
    }

markup : 加价:

<div id="overlay"><h2>I am an overlay-div</h2></div>

add the overlay to the map 将叠加层添加到地图中

map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(
   document.getElementById('overlay')
);

see fiddle -> http://jsfiddle.net/M6a7q/ 看小提琴 - > http://jsfiddle.net/M6a7q/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM