如果我在 Google Maps 地图上添加带有标签的标记,然后将 fitBounds 调用到另一个区域,除非我缩小,否则我仍然会继续看到没有标记的标签。它是一个错误吗?
这是一个工作小提琴,尝试单击米兰按钮: JSFiddle
html:
<div id="map-canvas"></div>
CSS:
#map-canvas {
width:100%;
height:500px;
position:"absolute";
top: 0px;
left: 0px;
overflow:"hidden";
background-color:#000;
}
.map-button{
margin-top: 10px;
height: 30px;
cursor: pointer;
color: #565656;
border:0px;
border-radius: 3px;
background-color:#fff;
box-shadow: rgba(0, 0, 0, 0.3) 1px 1px 4px -1px;
}
.map-button:hover {
background-color: #ebebeb;
color: #000;
}
Javascript:
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(41.29085, 12.71216),
zoom: 6,
gestureHandling: 'greedy'
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
label: {
text:'Roma',
fontSize: '28px'
}
});
var control = document.createElement('button');
control.innerHTML = 'Milano';
control.className = 'map-button';
map.controls[google.maps.ControlPosition.TOP_LEFT].push(control);
google.maps.event.addDomListener(control, 'click', function (event) {
var milanBounds = new google.maps.LatLngBounds(
{lat: 45.462818, lng: 9.184145},
{lat: 45.466806, lng: 9.190239});
map.fitBounds(milanBounds);
});
}
google.maps.event.addDomListener(window, 'load', initialize);