2012-03-11 22 views
2

我使用這段代碼加載在GoogleMapsAPI KML文件:加載一個KML與有色光碟正確渲染谷歌地圖API標

<script> 
function googleMapInitialize() { 
    var myOptions = { 
    center: new google.maps.LatLng(-34.397, 150.644), 
    zoom: 8, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    var myMap = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
    var ctaLayer = new google.maps.KmlLayer('http://www.freemages.fr/test/session_k.kml'); 
    ctaLayer.setMap(myMap); 
} 
</script> 

雖然它工作正常加載點,風格我已經定義不正確地呈現,因爲它使用在PNG格式的白色圓盤是應該根據顏色參數被重新着色,並且還根據尺度參數的圖像的尺寸調整:

<Style id="sn_style_0"> 
    <IconStyle> 
     <color>FF4ea24a</color> 
     <scale>0.4</scale> 
     <Icon> 
      <href>http://www.freemages.fr/test/disc.png</href> 
     </Icon> 
    </IconStyle> 
    <LabelStyle> 
     <scale>0.5</scale> 
    </LabelStyle> 
</Style> 
<Style id="sh_style_0"> 
    <IconStyle> 
     <color>FF4ea24a</color> 
     <scale>0.5</scale> 
     <Icon> 
      <href>http://www.freemages.fr/test/disc.png</href> 
     </Icon> 
    </IconStyle> 
    <LabelStyle> 
     <scale>0.5</scale> 
    </LabelStyle> 
</Style> 
<StyleMap id="msn_style_0"> 
    <Pair> 
     <key>normal</key> 
     <styleUrl>#sn_style_0</styleUrl> 
    </Pair> 
    <Pair> 
     <key>highlight</key> 
     <styleUrl>#sh_style_0</styleUrl> 
    </Pair> 
</StyleMap> 

谷歌地球可以正確渲染這種風格,它非常有效很好。

在我的項目中,我想讓用戶選擇他想要的顏色,所以我不能使用彩色光盤的集合,而不用重新着色,否則將是一個簡單的選項。

我也嘗試使用下面的代碼使用動態創建PNG透明盤的PHP,但PHP不管理的透明度非常好,並沒有在文件中正確顯示:

<?php 
header('Content-type: image/png'); 

$r = $_GET["r"]; 
$fg = $_GET["fg"]; 

is_numeric($r) or $r = 16; // radius 
strlen($fg)==6 or $fg = '22e822'; // fill color 
$bg = 'ffffff'; 

function hex2rgb($im,$hex) { 
    return imagecolorallocate($im, 
     hexdec(substr($hex,0,2)), 
     hexdec(substr($hex,2,2)), 
     hexdec(substr($hex,4,2)) 
     ); 
} 

$d = $r*2; 
$dm = $d-4; 

$im1 = imagecreatetruecolor($d,$d); 
imagecolortransparent($im1, hex2rgb($im1,$bg)); 
imagefill($im1,0,0,hex2rgb($im1,$bg)); 
imagefilledellipse($im1, $r, $r, $dm, $dm, hex2rgb($im1,$fg)); 
imagepng($im1); 
?> 

理想的情況下,如果它可能只是通過KML文件中的代碼創建一個彩色光盤,這將是最好的,但我沒有找到任何方法在文檔中這樣做。

任何建議如何解決此問題?

謝謝!

回答