2011-03-27 151 views
1

我一直在尋找一個簡單的方法來使用Google Map API版本3製作KML/KMZ圖層透明/不透明。有很多示例,但似乎沒有一個使KML圖層不透明的簡單示例。我在下面提供了一個例子,有人可以幫我解決這個問題嗎?使KML/KMZ圖層透明/不透明

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<title>Example 2</title> 
<style type="text/css"> 
    html { height: 100% } 
    body { height: 100%; margin: 0px; padding: 0px } 
    #map_canvas { height: 100% } 
</style> 
<script type="text/javascript" 
    src="http://maps.google.com/maps/api/js?sensor=false"> 
</script> 
<script type="text/javascript"> 

// ***Initialize the Map Function *** 
function initialize() { 
var latlng = new google.maps.LatLng(0,0); 
var myOptions = { 
    zoom: 10, 
    center: latlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
}; 
var map = new google.maps.Map(document.getElementById("map_canvas"), 
    myOptions); 

var polyLayerOptions = { 
    supressInfoWindows: true, 
    Opacity: 0.15 
}; 
var polyLayer = new google.maps.KmlLayer 
('http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml', polyLayerOptions); 
polyLayer.setMap(map); 
} 

</script> 
</head> 
<body onload="initialize()"> 
<div id="map_canvas" style="width:100%; height:100%"></div> 
</body> 
</html> 

回答

4

KML選項中沒有不透明標誌,但可以將KML中的對象的顏色設置爲透明。 Google使用ABGR格式的32位顏色,其中第一個字節是alpha通道或透明度,接下來的三個字節是常規顏色(儘管沒有其他人使用的標準RGB順序!)。例如,#80FF0000的顏色將是50%透明的藍色。似乎沒有辦法像在Google地球中一樣在代碼中隨時修改透明度,但您必須更新KML並將其重新發布到您的地圖。