使用多个Kml图层时缩放和中心不起作用(Google地图)

时间:2013-05-29 15:55:48

标签: maps kml center layer

当我向地图添加多个kmllayers时,它会忽略我为地图设置的缩放级别和中心,而是以最后添加的图层为中心。

有人能告诉我如何设置缩放级别和地图中心吗?

<script>
    function initialize() 
    {  
        var location = new google.maps.LatLng(52.0,5.1);
        var mapOptions = {
            zoom: 15,
            center: location,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }

        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        //Add MapLayers
        var mapLayer1 = new google.maps.KmlLayer({
            url: 'http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml'
        });
        mapLayer1.setMap(map);

        var mapLayer2 = new google.maps.KmlLayer({
            url: 'http://kml-samples.googlecode.com/svn/trunk/kml/kmz/balloon/balloon-image-rel.kml'
        });
        mapLayer2.setMap(map);

        var mapLayer3 = new google.maps.KmlLayer({
            url: 'http://kml-samples.googlecode.com/svn/trunk/kml/time/time-stamp-point.kml'
        });
        mapLayer3.setMap(map);
    }
    google.maps.event.addDomListener(window, 'load', initialize);    
</script>

1 个答案:

答案 0 :(得分:2)

为所有KmlLayers设置preserveViewport:true