使用多个KmlLayers(Google地图)时,缩放和居中功能不起作用 [英] Zoom and Center not working when using multiple KmlLayers (Google maps)

查看:133
本文介绍了使用多个KmlLayers(Google地图)时,缩放和居中功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

推荐答案

为所有KmlLayers设置prepareViewport:true

Set preserveViewport: true for all your KmlLayers

这篇关于使用多个KmlLayers(Google地图)时,缩放和居中功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆