我有一个徽标,显示在控件附近地图的右下角。问题是,当选择全屏选项时,徽标会消失。当我在firebug中看到div但是图像/徽标不可见时,div(aggdata-info)似乎就在那里。有什么想法吗?
initMap : function() {
var me = this;
me.map.mapOptions = {
zoom : 4,
center : {
lat: 37.6,
lng: -95.665
},
mapTypeControlOptions : {
mapTypeIds : [
//'map_style',
google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.SATELLITE,
google.maps.MapTypeId.HYBRID
]
},
//mapTypeId : 'map_style',
zoomControl : true,
mapTypeControl : true,
scaleControl : false,
streetViewControl : true,
rotateControl : true,
fullscreenControl : true,
fullscreenControlOptions : {
position : google.maps.ControlPosition.RIGHT_BOTTOM
}
};
div.aggdata-info {
height: 38px;
width: 170px;
text-align: center;
line-height: 28px;
background: #fff url(../cmnimages/reit_common/data_by_aggdata.png) center center no-repeat;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.5);
font-size: 12px;
position: absolute;
margin-top: 493px;
margin-left: 832px;
padding: 0px 5px 0px 5px;
}
Standard size with logo included Full screen logo disappears
以下是该div的css。
答案 0 :(得分:0)
请关注我的代码并抱歉我从未使用过你的代码!我在代码中做了所有更改。
注意:我在该文件中包含了js文件,您需要添加谷歌API密钥,否则谷歌地图显示错误。:
Google Maps API错误:InvalidKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key-map-error。
使用此disableDefaultUI: true
我只是隐藏谷歌地图中的对象,也可以隐藏谷歌地图中的特定对象。
如果您想使用编辑代码,请使用以下代码。
var customControlDiv = document.createElement('div');
var customControl = new CustomControl(customControlDiv, map);
customControlDiv.index = 1;
和功能
function CustomControl(controlDiv, map) {
var tempBackgroundImage = "http://www.clker.com/cliparts/W/0/g/a/W/E/map-pin-red-md.png";
controlDiv.style.padding = '5px';
controlDiv.style.right = '5px';
var myLocationControlDiv = document.createElement('DIV');
var controlUI = document.createElement('DIV');
controlUI.style.cursor = 'pointer';
controlUI.style.background = "url(" + tempBackgroundImage + ") 68px 78px";
controlUI.style.height = '68px';
controlUI.style.width = '68px';
controlUI.style.right = '15px';
controlUI.style.bottom = '50px';
controlUI.style.backgroundSize= '68px 78px';
controlUI.title = 'Current location';
myLocationControlDiv.appendChild(controlUI);
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlUI);
}
那就是!!!“
如果您不使用代码,则可以使用以下整个代码。
Html
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8,
disableDefaultUI: true
});
var customControlDiv = document.createElement('div');
var customControl = new CustomControl(customControlDiv, map);
customControlDiv.index = 1;
}
function CustomControl(controlDiv, map) {
var tempBackgroundImage = "http://www.clker.com/cliparts/W/0/g/a/W/E/map-pin-red-md.png";
controlDiv.style.padding = '5px';
controlDiv.style.right = '5px';
var myLocationControlDiv = document.createElement('DIV');
var controlUI = document.createElement('DIV');
controlUI.style.cursor = 'pointer';
controlUI.style.background = "url(" + tempBackgroundImage + ") 68px 78px";
controlUI.style.height = '68px';
controlUI.style.width = '68px';
controlUI.style.right = '15px';
controlUI.style.bottom = '50px';
controlUI.style.backgroundSize= '68px 78px';
controlUI.title = 'Current location';
myLocationControlDiv.appendChild(controlUI);
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlUI);
}

/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}

<script src="https://maps.googleapis.com/maps/api/js?key={YOUR_API_KEY}&callback=initMap"
async defer></script>
<div id="map"></div>
&#13;
重要的是:
请根据图片大小更新以下值。
controlUI.style.height = '68px';
controlUI.style.width = '68px';
controlUI.style.backgroundSize= '68px 78px';