简体   繁体   English

从 Google 地图中删除 KML 叠加层

[英]Removing KML overlay from Google Maps

I have a reset button that I want to reset the map (including removing overlays) when clicked.我有一个重置按钮,我想在单击时重置地图(包括删除叠加层)。

I've been reading around and apparently the way you remove KML overlays is by;我一直在阅读,显然您删除 KML 叠加层的方式是;

  1. Declaring your kml variable as a global variable将您的 kml 变量声明为全局变量

    var ctaLayer = new google.maps.KmlLayer(null);

  2. These are the lines that cause the kml file to overlay on google maps这些是导致 kml 文件覆盖在谷歌地图上的行

   var ctaLayer = new google.maps.KmlLayer(kmlFile);
   ctaLayer.setMap(map);
  1. And then call setMap(null) to remove the overlay.然后调用 setMap(null) 来移除叠加层。

    ctaLayer.setMap(null);

However, this does not seem to be working.但是,这似乎不起作用。 I don't get any errors so I'm guessing I'm missing something?我没有收到任何错误,所以我猜我遗漏了什么? I'd appreciate any advice on getting this to work.我将不胜感激有关使其正常工作的任何建议。

Remove the var from in front of the second var ctaLayer (the one that makes it local to the function).从第二个 var ctaLayer(使其成为函数本地的那个)前面删除 var。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM