Zoom and Center not working when using multiple KmlLayers (Google maps)

偶尔善良 提交于 2020-01-07 06:24:09

问题


When I add multiple kmllayers to a map it ignores the zoom level and center that I've set for the map and instead centers on the last added layer.

Can someone tell me how I'm suppose to set the zoom level and center of the map?

<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:


Set preserveViewport: true for all your KmlLayers



来源:https://stackoverflow.com/questions/16818638/zoom-and-center-not-working-when-using-multiple-kmllayers-google-maps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!