Martin Moore
Martin Moore

Reputation: 733

Making some placemarks visible with Google Maps API V3

I have a KML file with multiple placemarks, example below:

   <Placemark>
   <name>00550M</name>
   <description></description>
   <styleUrl>#550M</styleUrl>
   <Polygon>
     <outerBoundaryIs>
       <LinearRing>
         <tessellate>1</tessellate>
         <coordinates>
          -019.2041,63.4130
          -013.2722,57.0138
          004.2309,52.4405
           001.1318,49.5607
          -021.0657,55.3650
          -019.2041,63.4130
          </coordinates>
        </LinearRing>
     </outerBoundaryIs>
   </Polygon>
</Placemark>

Using the Earth plugin I can turn populate an array with the placemarks :

if ('getFeatures' in top.mykml) {  
var firstChild = top.mykml.getFeatures().getFirstChild();
while(firstChild !== null){                                      
    top.myObjects.push(firstChild);
    firstChild = firstChild.getNextSibling();        
  }    
} 

and make them visible or not :

for (var i = 0; i <  aLen; i++){
  aName = top.myObjects[i].getName();          
  aFL = (aName.substring(2, 5));    
  if (aFL == '200'){
    top.myObjects[i].setVisibility(true);               
  } 
}

However, getFeatures isn't available in Maps, and

if ('featureData' in top.mykml) 

returns false.

Is it possible to achive what I want to do, if so how. If not I guess each placemark will have to go in a single file.

Thanks.

Upvotes: 0

Views: 587

Answers (1)

geocodezip
geocodezip

Reputation: 161404

KmlLayer doesn't give you access to the objects on the map.

You have two options that I can think of:

  1. import your KML into FusionTables and use queries to display or hide the Placemarks
  2. use a third party KML parser like geoxml3 or geoxml-v3 that render the KML using native Google Maps Javascript API v3 objects and expose those so you can control them

example using geoxml3

Upvotes: 1

Related Questions