是的,确实如此!您只需为地图对象 zoom_changed 事件设置一个事件侦听器并检查地图缩放级别。然后使用图层的 setOptions() 方法重新设置图层的热图启用属性。因此,将您的代码更改为以下内容:
layer = new google.maps.FusionTablesLayer({
query: {
select: 'Lat',
from: FT_TableID
},
map: map,
// suppressInfoWindows: true
heatmap: {
enabled: true
},
options: {
styleId: 2,
templateId: 2
}
});
var heatMapIsOn = true;
google.maps.event.addListener(map, 'zoom_changed', function () {
var zoom = map.getZoom();
//we could just reset the layers options at every zoom change, but that would be
//a bit redundant, so we will only reset layers options at zoom level 13
if (heatMapIsOn && zoom >= 13) {
layer.setOptions({heatmap: {enabled:false}});
heatMapIsOn = false;
} else if (!heatMapIsOn && zoom < 13) {
layer.setOptions({heatmap: {enabled:true}});
heatMapIsOn = true;
}
});