使用 kml 文件时,Google 地图缩放会被覆盖

编程入门 行业动态 更新时间:2024-10-23 03:16:07
本文介绍了使用 kml 文件时,Google 地图缩放会被覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如何在 kml 文件中指定 google 地图的缩放级别,或者为什么在加载此文件时我的缩放级别被覆盖.我的问题实际上是如何控制以下链接的地图缩放:

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:

http://code.google/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.

您可以使用 google.maps.KmlLayerOptions 对象的 preserveViewport 属性更改默认行为.如果您将其设置为 true,则地图不会居中和缩放.

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/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 图层时地图始终居中(但不缩放),请使用 google.maps.KmlLayer 对象的 defaultviewport_changed 事件.您必须将地图中心设置为 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 文件时,Google 地图缩放会被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 16:30:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/942667.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被覆   缩放   地图   文件   kml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!