12 七月 2010 @ 11:09 下午 

筆記一下:最近在研究KML,發現他的color format 有點奇怪,例如

<LineStyle>
<color>d90000ff</color>
    <width>6</width>
</LineStyle>

翻了一下KML的spec, 才發現原來他的color format是ABGR,而不是一般網頁使用的RGB,因此我寫了一個小function來轉換

var transKMLColorToARGB = function(color){
        var abgr = [];
        for(var i=0; i<color.length; i+=2){
                abgr.push(color.substring(i, i+2));
        }
        return [abgr[0], abgr[3], abgr[2], abgr[1]];
};  
//get argb array
var argb = transKMLColorToARGB('5014B4F0');
var color = '#'+argb.slice(1).join('');//#F0B414
var opacity = ((parseInt(argb[0], 16)+1)/256).toFixed(2);//0.32

Posted By: BLACKBING
Last Edit: 14 七月 2010 @ 12:49 上午

EmailPermalink
Tags
Categories: Programing


 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


 Last 50 Posts
 Back
Change Theme...
  • Users » 30
  • Posts/Pages » 64
  • Comments » 35
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About Me



    No Child Pages.

留言板



    No Child Pages.

Album



    No Child Pages.