Hiding/showing a kml layer on customized google maps depending of the view

后端 未结 1 690
渐次进展
渐次进展 2021-01-27 06:19

Is there any way to show a kml Layer only on Google Earth view layer? I am using Google API V3

This is the link of what I have: http://www.virtualbc.ca/knoxmountain/inde

相关标签:
1条回答
  • 2021-01-27 06:48

    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);
    

    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).

    0 讨论(0)
提交回复
热议问题