Tuesday, August 25, 2009

Changing the size and colour of placemarks in Google Earth

In follow up to my previous post I have now found out how to change the size and colour of my placemarks. The trick here is to create a "style" of placemark right at the top of the file. Again, this is pretty simple when you get down to it. This time you need to post a little bit of code at the top of the file, just after the <Document> tag:

<Style id="normalPlacemark">
<IconStyle>
<color>ffffff00</color>
<scale>5</scale>
</IconStyle>
</Style>

The id part of the opening <style> tag is important as it gives each style a name that we can then refer to later for each individual placemark. This allows the user to create different styles of placemark that can be used together in the same file (rather like CSS does for HTML). Colour (<color>) and size (<scale>) are then defined as elements of the <IconStyle> tag. Colours are in a hexadecimal format:

The range of values for any one color is 0 to 255 (00 to ff). For alpha, 00 is fully transparent and ff is fully opaque. The order of expression is aabbggrr, where aa=alpha (00 to ff); bb=blue (00 to ff); gg=green (00 to ff); rr=red (00 to ff). For example, if you want to apply a blue color with 50 percent opacity to an overlay, you would specify the following: 7fff0000, where alpha=0x7f, blue=0xff, green=0x00, and red=0x00.

Whereas scale is just a number.

Now we just need to make an addition to our <placemark> tag to state that we want to use this style:

<Placemark>
<name>110_671B</name>
<styleUrl>#normalPlacemark</styleUrl>
<Point>
<coordinates>-58.73,15.52,-1622</coordinates>
</Point>
</Placemark>

So now I am able to plot my holes as giant green pushpins:

Unfortunately it is not easy to modify the colours of the pushpin icon as it has a yellow overlay to it and I have yet to work out if there is an easier way to colour placemarks exactly as I want. This will have to wait until next time.


Update:

OK, this last bit has been solved by someone who asked to be referred to as "my clever volcanologist friend." Basically a white pushpin needs to be called in the <style> tag like this:

<Style id="normalPlacemark">
<IconStyle>
<color>ffffff00</color>
<scale>5</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pushpin/wht-pushpin.png</href>
</Icon>
</IconStyle>
</Style>

1 comment:

Unknown said...

Great work again, thanks! I think I will be checking back frequently.

About Me

My photo
Currently I am founding member, president elect and entire membership of SWEMP (the Society of Wonky-Eyed Macroevolutionary Palaeobiologists). In my spare time I get paid to do research on very dead organisms and think about the really big questions in life, such as: What is the ultimate nature of reality? Why is there no room for free will in science? and What are the implications of having a wardrobe that consists entirely of hotpants?