2013-06-23 96 views
1

我試圖根據縮放級別顯示Fusion Table圖層,但只有第一層放在縮放級別1上顯示在地圖上,其他圖層不是全部顯示(無論放大級別1上的縮放級別層始終保持在地圖上)。代碼如下:谷歌地圖 - Diplay Fusion表層基於縮放級別

<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> 

有沒有人有過這樣的問題的經驗?

最佳, 達科

回答

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); 
    } 
}); 
+0

就是這樣,再次感謝geocodezip –

相關問題