我通过为我的地图 创建自定义缩放按钮解决了这个问题。
这是我的项目中的代码:
编辑:删除了不必要且不言自明的通用代码
你的 zoomControl 函数:
function zoomControl(map, div) {
var controlDiv = div,
control = this;
// Set styles to your own pa DIV
controlDiv.style.padding = '5px';
// Set CSS for the zoom in div.
var zoomIncrease = document.createElement('div');
zoomIncrease.title = 'Click to zoom in';
// etc.
// Set CSS for the zoom in interior.
var zoomIncreaseText = document.createElement('div');
// Use custom image
zoomIncreaseText.innerHTML = '<strong><img src="./images/plusBut.png" width="30px" height="30px"/></strong>';
zoomIncrease.appendChild(zoomIncreaseText);
// Set CSS for the zoom out div, in asimilar way
var zoomDecreaseText = document.createElement('div');
// .. Code .. Similar to above
// Set CSS for the zoom out interior.
// .. Code ..
// Setup the click event listener for Zoom Increase:
google.maps.event.addDomListener(zoomIncrease, 'click', function() {
zoom = MainMap.getZoom();
MainMap.setZoom(zoom+1);
// Other Code parts
});
// Setup the click event listener for Zoom decrease:
google.maps.event.addDomListener(zoomDecrease, 'click', function() {
zoom = MainMap.getZoom();
MainMap.setZoom(zoom-1);
});
}
你的初始化函数:
function initializeMap() {
var latlng = new google.maps.LatLng(38.6, -98);
var options = {
zoom : 5,
center : latlng,
mapTypeId : google.maps.MapTypeId.ROADMAP,
// Other Options
};
MainMap = new google.maps.Map(document.getElementById("google-map-canvas"),
options);
// The main part - Create your own Custom Zoom Buttons
// Create the DIV to hold the control and call the zoomControl()
var zoomControlDiv = document.createElement('div'),
zoomLevelControl = new zoomControl(MainMap, zoomControlDiv);
zoomControlDiv.index = 1;
MainMap.controls[google.maps.ControlPosition.RIGHT_TOP].push(zoomControlDiv);
}
希望能帮助到你