Display only certain KML features by attributes

180 views
Skip to first unread message

Gareth Mann

unread,
Sep 1, 2011, 3:18:43 PM9/1/11
to google-map...@googlegroups.com
Is there a way to display only certain features of a KML by attributes in Google Maps?

I know this is possible using Fusion Tables, but I would rather not use Fusion tables because: 
a) I would have to make my KML data public so that anybody could use it.
b) Because my KML data has description balloons loaded with HTML and I am not sure that Fusion tables allow the display of HTML balloons.
c) I want to be able to dynamically update KML files stored on my website when users input information and I am not sure if there is a way to dynamically upload a KML file as a Fusion table.

So is there any other way to do this in the Google Maps API without Fusion tables? 

What I want to do is mimic the "time aware" functionality of Google Earth so that I can display KML data by time.

Andres Ferrate

unread,
Sep 2, 2011, 12:48:09 PM9/2/11
to google-map...@googlegroups.com
Gareth,

You'll need to parse your own KML if you do not wish to make it public.  Try searching the forum for this topic (shortcut link below):


There are various techniques and some developers have created some libraries that parse KML as well.

Cheers,

-Andres


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/6Nhkg9IvxbsJ.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Gareth Mann

unread,
Sep 2, 2011, 1:06:27 PM9/2/11
to google-map...@googlegroups.com
Parsing the KML is to do with trying to hide the data in the KML right? Not to do with Fusion Tables or only showing certain KML features by attributes.

I am not too worried about hiding the KMLs, if somebody wants to go through all my cryptic code and find the location and file name of my KMLs and download them then fair play to them, it won't be so easy and they will not get the updates automatically, besides the HTML in all of my balloons links back to my site anyway.

My main issue is whether or not there is a way to display only certain KML features by attributes, aside from the fusion table method. If i have to go the Fusion table route then it is an option, as long as there is a way to write custom HTML balloons into the Fusion table like there is with KMLs.

But thanks for the link on parsing the KML, I will definitely look into that as an option in the long run.

Rossko

unread,
Sep 2, 2011, 2:57:18 PM9/2/11
to Google Maps JavaScript API v3
> Parsing the KML is to do with trying to hide the data in the KML right? Not
> to do with Fusion Tables or only showing certain KML features by attributes.

Semantics perhaps ; hiding some features in KML is effectively the
same thing as only showing some features in KML.
If you want to select some features from a KML file, then you'll need
to parse it yourself.

webbirder

unread,
Sep 2, 2011, 4:30:13 PM9/2/11
to Google Maps JavaScript API v3
I use PHP to parse KML files
http://www.birdtheme.org/useful/sub/kmlwithv3.php
My page has also links to other solutions

Gareth Mann

unread,
Oct 12, 2011, 9:52:16 AM10/12/11
to google-map...@googlegroups.com
Hi webrider,

Your site is an excellent resource, you are really pushing Google Maps as far as it can be pushed. Congratulations!

I am particularly interested in this page:

It has the info windows, which is exactly what I need. What do you mean by this:

"When KML files are read with the Google maps API GGeoXml, polygons and polylines are clickable and will show infowindow when clicked on...."

What is the GGeoXML, do you have an example that uses that? 

Also, i note that this particular example is made with v2 of the Maps API. Why did you use v2? Is it much harder to accomplish this in v3? I am reluctant to use v2 because I think I remember that v2 is much much slower at rendering large KML polygons. Is this true? Or is v3 just as slow as v2?

Rossko

unread,
Oct 12, 2011, 12:49:47 PM10/12/11
to Google Maps JavaScript API v3
> What is the GGeoXML, do you have an example that uses that?
>
> Also, i note that this particular example is made with v2

These statements are linked ; GGeoXml is the v2 equivalent of kmlLayer
in v3

Gareth Mann

unread,
Oct 14, 2011, 10:31:48 AM10/14/11
to google-map...@googlegroups.com
Webrider, I am adapting and playing with your excellent code for parsing kmls with very large polygons. I have a couple of questions for you:

1) I have noticed that for large polygons (i.e. ones with over 700 co-ordinate pairs) Mozilla FF cannot plot them correctly using your code. It is as if the array that holds the co-ordinates just stops filling once you get beyond 700 or so points, consequently those large polygons appear cut short on the map. This problem does not occur in IE or Chrome.

2) The great thing about your code is that the only slow part is the line "xml = GXml.parse(xmlcontent);", which can take up to 20 seconds with 8 mgb KMLs. But once this has been called once, everything else is instantaneous, so you can traverse the stored XML document and show and hide different placemarks based on attributes within a split second. However I was trying to use it with multiple KML files, one storing polygon data and one storing point data. For some reason when I call the GXml.parse method a second time on a different KML file i.e.

xml = GXml.parse(xmlcontent);
xml2 = GXml.parse(xmlcontent2);

The first xml file gets wiped out of memory, even though the second one has a different name (i.e. xml2). I get the error "xml is undefined". Any idea why this is and how to get around it? One workaround is to simply store everything one needs in a single KML file, which is the solution I am working on now. Just wondering if there was another way.....



Reply all
Reply to author
Forward
0 new messages