admin管理员组文章数量:1356515
How would I add the KML as a layer in google maps (javascript v3) without changing the map extent/zoom?
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.
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. How would I either prevent this, or go back to my initial extent/zoom?
Thanks in advance.
How would I add the KML as a layer in google maps (javascript v3) without changing the map extent/zoom?
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.
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. How would I either prevent this, or go back to my initial extent/zoom?
Thanks in advance.
Share Improve this question asked Jul 14, 2012 at 20:07 Beau BouchardBeau Bouchard 82711 silver badges28 bronze badges1 Answer
Reset to default 11Just set preserveViewport
option of google.maps.KmlLayerOptions to true
:
var overlay = new google.maps.KmlLayer(inc,{preserveViewport:true});
本文标签: javascriptHow can I load a KML in google mapwithout changing the map centerStack Overflow
版权声明:本文标题:javascript - How can I load a KML in google map, without changing the map center - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743978826a2570988.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论