根据视图在定制的Google地图上隐藏/显示kml图层 [英] Hiding/showing a kml layer on customized google maps depending of the view
问题描述
有没有什么方法可以在Google Earth视图图层上显示kml图层?我正在使用Google API V3
Is there any way to show a kml Layer only on Google Earth view layer? I am using Google API V3
这是我拥有的链接: http://www.virtualbc.ca/knoxmountain/index2.php
在Google地球视图中,如果我选择卫星视图,我想删除或隐藏kml层。我实际上是在所有Google视图中使用了一组图块,但地球视图除外。
Being on Google Earth View, if I select the Satellite View, I want to remove or hide the kml layer. I am actually using a set of tiles over all the Google views except the Earth view.
推荐答案
您可以使用maptypeid_changed事件Google.Map对象。当它改变时,你可以通过使用setMap()来设置kml图层来显示或者隐藏。
示例:
You can use the maptypeid_changed event on the Google.Map object. When it changes, you can either set the kml layer to show or hide by using setMap(). Example:
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);
只要确保在将地图类型设置为不同的地图类型时,您可以重新设置kml层到地图。当你想隐藏某些东西时,你只需调用setMap(null)。
Just make sure that when you set the map type back to a different one you re-set the kml layer to the map. When you want to hide something, you just call setMap(null).
这篇关于根据视图在定制的Google地图上隐藏/显示kml图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!