2011-03-27 149 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并将其重新发布到您的地图。