有没有办法只在 Google Earth View 图层上显示 kml 图层?我正在使用 Google API V3
这是我所拥有的链接:http://www.virtualbc.ca/knoxmountain/index2.php
在 Google 地球 View 中,如果我选择卫星 View ,我想删除或隐藏 kml 图层。实际上,我在除地球 View 之外的所有 Google View 上使用了一组图 block 。
最佳答案
您可以在 Google.Map 对象上使用 maptypeid_changed 事件。当它发生变化时,您可以使用 setMap() 将 kml 图层设置为显示或隐藏。 示例:
function initialize() {
var map = new google.maps.Map(document.getElementById('map-div'), {
center: new google.maps.LatLng(40.3,-111.65),
zoom: 13
});
var kmlLayer = new google.maps.KmlLayer('http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml');
kmlLayer.setMap(map);
google.maps.event.addListener(map, 'maptypeid_changed', function() {
if(map.mapTypeId == 'hybrid') {
kmlLayer.setMap(null);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
只需确保当您将 map 类型设置回其他类型时,您将 kml 图层重新设置为 map 。当你想隐藏某些东西时,你只需调用setMap(null)即可。
关于javascript - 根据 View 在自定义谷歌地图上隐藏/显示 KML 图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22085308/