0
votes

I'm trying to emulate this functionality

https://maps.google.com/maps?q=http://en.wikipedia.org/w/index.php%3Ftitle%3DTemplate:Attached_KML/N_postcode_area%26action%3Draw

I want to be able to add and remove a postcode region from an external link / checkbox. I have the KML file loading correctly using this code but I have no idea how to attach the external event listener / handler.

function initialize() {
  var london = new google.maps.LatLng(51.522416,-0.11673);
  var mapOptions = {
    zoom: 11,
    center: london,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }

  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var ctaLayer = new google.maps.KmlLayer({
    url: 'path/to/kml',
    suppressInfoWindows: true
  });
  ctaLayer.setMap(map);

}

google.maps.event.addDomListener(window, 'load', initialize);

I've tried looking in the ctaLayer object to get the individual nodes from the KML file but they dont seem to be there.

Not the same question. Duplicate suggested removes entire overlay. This questions needs to get at one area at a time. - 32423hjh32423
You can't do that with KmlLayer. You might be able to import the KML into FusionTables and use a FusionTablesLayer and control the displayed regions with the query. - geocodezip
Is that how the example does it? I'm having difficulty understanding whats going on, on the example page. - 32423hjh32423
I don't know, that is Google Maps, not an API based map. It probably uses tiled rendering like KmlLayer, but KmlLayer doesn't expose anything (at least presently) to allow you to control the polygons separately from outside the map, you can only retrieve information based on click events. - geocodezip