1

当我将多个 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>
4

1 回答 1

2

为所有 KmlLayers 设置 preserveViewport: true

于 2013-05-29T17:25:35.777 回答