打开infowindow后,我设置:
map.setOptions({draggable: false, zoomControl: false, scrollwheel: false, disableDoubleClickZoom: true});
这允许用户不再能够与地图交互,但是当用户点击infowindow上的“关闭”时...如何将其设置回默认值?
答案 0 :(得分:2)
观察infowindow的map_changed
- 事件,每次打开或关闭infowindow时都会触发此事件(无论如何触发)。
根据信息窗的地图属性设置值(当它关闭时为null
,否则为地图实例)
function initialize() {
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 14,
center: new google.maps.LatLng(52.549878, 13.425209),
mapTypeId: google.maps.MapTypeId.ROADMAP
}),
marker = new google.maps.Marker({
map: map,
position: map.getCenter()
}),
win = new google.maps.InfoWindow({
content: 'hello world'
});
google.maps.event.addListener(win, 'map_changed', function() {
//will be true when infowindow is open
var boo = !!this.getMap();
map.setOptions({
draggable: !boo,
disableDefaultUI: boo,
scrollwheel: !boo,
disableDoubleClickZoom: boo
});
});
google.maps.event.addListener(marker, 'click', function() {
win.open(map, this);
});
}
google.maps.event.addDomListener(window, 'load', initialize);

html,
body,
#map_canvas {
height: 100%;
margin: 0;
padding: 0
}

<script src="https://maps.googleapis.com/maps/api/js?v=3&.js"></script>
<div id="map_canvas"></div>
&#13;
答案 1 :(得分:0)
关闭地理编码评论
您可以检查用户关闭信息窗时是否调用close()。如果为真,那么map.setOptions({draggable: true...
。