Changing KML Polygon Color in Google Maps

12,830 views
Skip to first unread message

ltaylor99

unread,
Feb 18, 2012, 8:05:19 AM2/18/12
to KML Developer Support - Getting Started with KML
Hi Group,

I am trying to change the polygon color rendered in KML in Google
Maps. Code is posted below. I am new at this, so the error might not
be where I would expect. I can post more code if it would help:


<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style Id="style32312">
<PolyStyle>
<color>7f0000ff</color>
</PolyStyle>
</Style>
<!--This Style reference did not work apparently-->
<Placemark>
<name>32312</name>
<description>This is the 32312 Zip Code</description>
<styleUrl>#style32312</styleUrl>
<Polygon><outerBoundaryIs><LinearRing><coordinates>
***
</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
</Document>
</kml>

The color rendered on the map (I am using Google Maps Javascript API
v3) is the standard semi-transparent blue that seems to be rendered in
any basic polygon. I am going for semi-transparent red, which is what
I thought the above would output.

Any suggestions would be very much appreciated.

Thanks

Rossko

unread,
Feb 18, 2012, 8:53:22 AM2/18/12
to KML Developer Support - Getting Started with KML
> I am going for semi-transparent red, which is what
> I thought the above would output.

Did you mean to specify fill or outline, or both?
http://code.google.com/apis/kml/documentation/kmlreference.html#fill

ltaylor99

unread,
Feb 18, 2012, 8:59:57 AM2/18/12
to KML Developer Support - Getting Started with KML
Both would be fine, but I really want fill. When I include the
<fill>1</fill> element within the <PolyStyle> element, there is still
no difference, i.e. still renders blue.
Thanks

ltaylor99

unread,
Feb 19, 2012, 8:25:19 AM2/19/12
to KML Developer Support - Getting Started with KML
Hi Rossko,

The problem seems to have been resolved when I made the <Style>
elements a child of the <Placemark> element like so . . .

<Placemark>
<name>32312</name>
<description>This is the 32312 Zip Code</description>
<Style>
<PolyStyle>
<color>7f0000ff</color>
<outline>1</outline>
</PolyStyle>
</Style>
<Polygon><outerBoundaryIs><LinearRing><coordinates>

But even this didn't immediately work. I apparently had to close out
of my browser (Safari) and come back to it later. Now, however, if I
change the color codes in the kml file on my host account, the change
in the brewer seems to work fine (without having to completely close
out and re-open). I don't understand what the problem was. Perhaps
it was a combination of the refresh rate at google, my host server,
and my browser. I guess I will just have to keep playing with
changes to see where the delay is.

Thanks, though, for the suggestion. Of course, if any of this makes
sense to you, please share your insight.

Thanks

ltaylor99

unread,
Feb 19, 2012, 8:42:49 AM2/19/12
to KML Developer Support - Getting Started with KML
Also, I forgot to mention that I added a lot of additional namespace
info I copied from a file that seemed to be processing color just
fine. The <kml> header now reads:

<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://
www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/kml/2.2
http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://www.google.com/kml/ext/2.2
http://code.google.com/apis/kml/schema/kml22gx.xsd">

before it simply read:

<kml xmlns="http://www.opengis.net/kml/2.2">

I don't know if that made a difference or not. None of the <Style> or
<PolyStyle> elements seemed to be processed with prefixes, so I don't
understand why adding the namespaces would have made a difference. At
any rate, just wanted to pass along in case this helps solve the
mystery.

Thanks

Rossko

unread,
Feb 19, 2012, 12:54:07 PM2/19/12
to KML Developer Support - Getting Started with KML
> But even this didn't immediately work.

No, it wouldn't. When you display KML in maps.google.com, your KML is
cached at Google's servers for some time. Any changes you make "won't
work" immediately unless you take steps to circumvent the caching,
like dummy url parameters.

I don't think that namespace stuff is relevant.

Note that XML attribute names are case sensitive
<Style Id="style32312">
is not the same as the required
<Style id="style32312">
I missed that on first reading

ltaylor99

unread,
Feb 19, 2012, 6:15:47 PM2/19/12
to KML Developer Support - Getting Started with KML
Ahh. Google's caching is very good information and will impact a
project I am working on. I will need to change color and visualize
data dynamically, so I guess I will refocus on using the Javascript
API instead.

Thanks also for the reminder on case-sensitivity.

lt

kamgut

unread,
Mar 6, 2012, 12:16:41 PM3/6/12
to kml-support-g...@googlegroups.com


hi!

i have been working to change dynamically the color of the polygons but i get the same bug..i have blue RGB but i get a complementary color (orange)..i don't understand why change the color.. i need some help!! Please!!..this is my code:


var placemarks = ge.getElementsByType('KmlPlacemark');

               for (var j = 0; j < placemarks.getLength(); ++j) {

                var placemark = placemarks.item(j);

                  placemark.setStyleSelector(ge.createStyle(''));

                    var placemarkS = placemark.getStyleSelector().getPolyStyle();

                    placemark.setDescription('Hi');

                    placemarkS.getColor().set('9974a6fc');

          }

pajevsky

unread,
Jul 24, 2012, 4:18:34 AM7/24/12
to kml-support-g...@googlegroups.com
hi!

color for placemark isn't in RGB format but in ABGR.
example:
rgb color: 11ffcc
placemark color: (ff)ccff11

regards

Dne torek, 06. marec 2012 18:16:41 UTC+1 je oseba kamgut napisala:
Reply all
Reply to author
Forward
0 new messages