css - Adding overlay over google maps, leaves bottom part of map showing -
i trying use google maps location background page. however, overlay not cover entire map, bottom of map showing.
even when try set height of map-canvas
, overlay
100vh
map still exceeds overlay.
function initialize() { var mapoptions = { zoom: 15, center: new google.maps.latlng(0, 0) }; var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); } function loadscript() { var script = document.createelement('script'); script.type = 'text/javascript'; script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' + '&signed_in=true&callback=initialize'; document.body.appendchild(script); } window.onload = loadscript;
html, body { height: 100%; } #map-canvas { height: 100%; width: 100%; z-index: 0; } .overlay { height: 100%; width: 100%; position: absolute; top: 0; left: 0; background: rgba(0,0,0,0.5); z-index: 1; }
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=aizasyd1izgpwuoiz6hxudt6hscusa0oaxdggj4"> </script> <div id="map-canvas"></div> <div class="overlay"></div>
the #map-canvas
have different position .overlay
, because it's position affected padding/margin of page.
you have these options(there may more):
remove padding/margin:
html, body { height: 100%; margin:0; padding:0; }
when want preserve padding/margin , want overlay cover map regardless of map-size/position, use
.overlay
child of#map-canvas
:<div id="map-canvas"><div class="overlay"></div></div>
to make work must set
noclear
-option of maptrue
(otherwise api remove.overlay
)
function initialize() { var mapoptions = { zoom: 15, noclear: true, center: new google.maps.latlng(0, 0) }; var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); } function loadscript() { var script = document.createelement('script'); script.type = 'text/javascript'; script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' + '&signed_in=true&callback=initialize'; document.body.appendchild(script); } window.onload = loadscript;
html, body { height: 100%; } #map-canvas { height: 80%; width: 70%; z-index: 0; } .overlay { height: 100%; width: 100%; position: absolute; top: 0; left: 0; background: rgba(0, 0, 0, 0.5); z-index: 1; }
<div id="map-canvas"> <div class="overlay"></div> </div>
Comments
Post a Comment