我尝试根据缩放级别显示Fusion Table图层,但只有在Zoom级别1上的第一个图层显示在地图上,而代码中的其他图层根本不显示(无论缩放级别图层是什么)在缩放级别1上始终保持在地图上)。代码如下:
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var center = new google.maps.LatLng(-40.979898,173.305662);
function init() {
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: center,
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var parcel_boundary = new google.maps.FusionTablesLayer({
query: {
select: 'parcel_boundary_1_9999',
from: '1ouLS0fm8tPPQNQRpr-bwE4ct-cBkMB-Ru_XttDQ'
},
styles: [{
polygonOptions: {
strokeColor: "#333333",
strokeOpacity: 0.8,
strokeWeight: 0.7,
fillColor: "#36549C",
fillOpacity: 0.3
}
}]
});
var meshblock_1_24113 = new google.maps.FusionTablesLayer({
query: {
select: 'meshblock_1_24113',
from: '1nLxnoXlipws7PfjBihBBGL2BVd7OKdxThSuLVRs'
}
});
var territorial_authority = new google.maps.FusionTablesLayer({
query: {
select: 'territorial_authority',
from: '1YBAtek3BB_sQsxHPJxDTP6Pa6Fy_N12iQ8bIZQQ'
},
styles: [{
polygonOptions: {
strokeColor: "#333333",
strokeOpacity: 0.8,
strokeWeight: 0.7,
fillColor: "#C42D24",
fillOpacity: 0.3
}
}]
});
var zoom = map.getZoom();
if (zoom >=1 && zoom <=8) {
territorial_authority.setMap(map);
meshblock_1_24113.setMap(null);
parcel_boundary.setMap(null);
}
if (zoom >9 && zoom <=10) {
territorial_authority.setMap(null);
meshblock_1_24113.setMap(map);
parcel_boundary.setMap(null);
}
else if (zoom >11 && zoom <=15) {
territorial_authority.setMap(null);
meshblock_1_24113.setMap(null);
parcel_boundary.setMap(map);
}
;
}
</script>
</head>
<body id="body" onload="init();">
<div id="map_canvas" style="position:absolute; border-style:solid; border-width:1px; border-color:#333333; left:50%; top:20px; width:1000px; height:860px; z-index:1; margin-left: -500px;"></div>
</body>
</html>
有没有人遇到过像这样的问题?
答案 0 :(得分:2)
您的代码不包含地图上“zoom_changed”事件的侦听器,只要地图上的缩放发生变化,该事件就会触发,并让您按照新的缩放级别进行操作。
google.maps.event.addListener(map,"zoom_changed", function() {
var zoom = map.getZoom();
if (zoom >=1 && zoom <=9) {
territorial_authority.setMap(map);
meshblock_1_24113.setMap(null);
parcel_boundary.setMap(null);
}
else if (zoom >9 && zoom <=11) {
territorial_authority.setMap(null);
meshblock_1_24113.setMap(map);
parcel_boundary.setMap(null);
}
else if (zoom >11) {
territorial_authority.setMap(null);
meshblock_1_24113.setMap(null);
parcel_boundary.setMap(map);
}
});