简体   繁体   English

如何在Google地图中加载KML,而无需更改地图中心

[英]How can I load a KML in google map, without changing the map center

How would I add the KML as a layer in google maps (javascript v3) without changing the map extent/zoom? 如何在不更改地图范围/缩放的情况下将KML添加为Google地图(javascript v3)中的图层?

I am adding a KML which has several events all over the world, because of this google maps javascript v3 changes the map extent to a very large zoomed out view. 我正在添加一个KML,它在全世界有几个事件,因为这个谷歌地图javascript v3将地图范围更改为一个非常大的缩小视图。

Here is some example code: 这是一些示例代码:

function loadOverlay(inc) 
{
    var overlay = new google.maps.KmlLayer(inc);
    overlay.setMap(map);
    overlayArray.push(overlay);
}

function initialize_gmap()
{
    var Rochester = new google.maps.LatLng(43.1561, -77.607); 
    var myOptions = {
    zoom: 11,
    center: Rochester,
    mapTypeId: google.maps.MapTypeId.TERRAIN
    }

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

//Then i initialize the map here, and load the kml
initialize_gmap();
loadOverlay("linktokml.kml");

After the kml is loaded it goes to a very large zoom to show all the locations in the kml. 加载kml后,它将进行非常大的缩放以显示kml中的所有位置。 How would I either prevent this, or go back to my initial extent/zoom? 我怎么能阻止这个,或者回到我的初始范围/缩放?

Thanks in advance. 提前致谢。

只需将google.maps.KmlLayerOptions的 preserveViewport选项设置为true

var overlay = new google.maps.KmlLayer(inc,{preserveViewport:true});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM