Add and Remove KML overlay to a Google Map from external link

独自空忆成欢 提交于 2019-12-13 04:22:57

问题


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.

来源:https://stackoverflow.com/questions/16446118/add-and-remove-kml-overlay-to-a-google-map-from-external-link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!