谷歌地图缩放被重写,利用KML文件时 [英] Google Maps zoom gets overriden, when using a kml file

查看:231
本文介绍了谷歌地图缩放被重写,利用KML文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在KML文件中指定缩放级别谷歌地图或那为什么我的缩放级别,当我打开这个文件获得超过缠身。我的问题其实是我怎么控制以下链接地图缩放:

How do I specify zoom level for google maps in a kml file or why is it that my zoom level gets over ridden when I load this file. My question is actually how do I control zoom of a map for the following link:

<一个href=\"http://$c$c.google.com/apis/maps/documentation/javascript/examples/layer-kml-features.html\">http://$c$c.google.com/apis/maps/documentation/javascript/examples/layer-kml-features.html

推荐答案

默认情况下,地图会居中并缩放到的KML图层内容的边框。

By default, the map is centered and zoomed to the bounding box of the contents of the kml layer.

您可以更改与 preserveViewport google.maps.KmlLayerOptions 对象属性的默认行为。如果你把它设置为真正地图未居中和缩放。

You can change the default behaviour with preserveViewport property of google.maps.KmlLayerOptions object. If you set it to true the map isn't centered and zoomed.

在这个例子中,使用:

var nyLayer = new google.maps.KmlLayer(
                  'http://www.searcharoo.net/SearchKml/newyork.kml',
                  {
                      suppressInfoWindows: true,
                      map: map,
                      preserveViewport: true
                  });

如果要居中并放大到KML图层的内容后,可以使用:

If you want to center and zoom to the contents of the kml layer later, use:

var bounds = nyLayer.getDefaultViewport();
map.fitBounds(bounds);

编辑:

如果你想在地图中始终围绕(但不缩放)时加载的KML图层,使用 defaultviewport_changed 谷歌事件。 maps.KmlLayer 对象。你必须设置地图中心的KML图层默认视口的中心。当KML图层的内容载入触发事件和它的默认视口计算的。

If you want the map to be always centered (but not zoomed) when the kml layer is loaded, utilize defaultviewport_changed event of the google.maps.KmlLayer object. You have to set the map center to the center of the kml layer default viewport. The event is triggered when the contents of the kml layer are loaded and its default viewport is computed.

google.maps.event.addListener(nyLayer, 'defaultviewport_changed', function() {
   var bounds = nyLayer.getDefaultViewport();
   map.setCenter(bounds.getCenter());
});

这篇关于谷歌地图缩放被重写,利用KML文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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