Tuesday, 29 April 2008

Drawing regular polygons in KML

The second hack for making proportional symbols in KML, is to use regular polygons (see the first hack here and here). Unfortunately, KML has no build-in support for regular polygons so you have to do it the hard way: by calculating the longitude/latitude for each vertex or corner point of the polygon. Since I'm not a math genius, I was happy do find this PHP function by TJ which I could modify for this purpose. This is the result:

By changing the bearing or angle 30 times from 0 to 360, the function returns a circle (KMZ).

Reduce the number of iterations to 4, and you'll get a square (KMZ). Not the easiest way to draw a square, but it works.