Google map javascript API 问题 - 应用 KML 图层后 map 对象重新回到中心位置。我该如何防止这种情况发生?
我创建了一个带有 map 的简单页面。当我应用简单的多边形 KML 时,它会居中并缩放 map 。有什么想法吗?
var myOptions = {
center: new google.maps.LatLng(27, -97),
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var buildings = new google.maps.KmlLayer('https://mysite/site/buildings.xml');
buildings.setMap(map);
//i tried this to recenter and zoom, but no dice.
var posn = new google.maps.LatLng(27, -97);
map.setCenter(posn);
map.setZoom(17);
最佳答案
听起来您需要 preserveViewport option 。来自文档:
By default, the input map is centered and zoomed to the bounding box of the contents of the layer. If this option is set to true, the viewport is left unchanged, unless the map's center and zoom were never set.
关于google-maps - Google map javascript API - 应用 KML 层后 map 对象重新居中。我该如何防止这种情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9385459/