【问题标题】:How can i calculate the center of the map from KML data?如何根据 KML 数据计算地图中心?
【发布时间】:2012-09-06 12:48:41
【问题描述】:

所以,我使用带有几个基本地图图层(google、bing、osm)的 openlayers,并且我有一个 KML 图层,到处都有地标。计算地图中心和最佳缩放级别的最佳方法是什么?

谢谢!

kml sn-p:

<Placemark>
    <name>foo</name>
    <description>
       foobar
    </description>
    <Point>
        <coordinates>lat,lon</coordinates>
    </Point>
</Placemark>

【问题讨论】:

  • 如果您的 KML 图层遍布全球,那么地图的中心是……嗯,是在炽热的地球中心吗? :) 假设一个小区域,你不能从 OpenLayers 获取边界框并放大到那个区域吗?

标签: openlayers kml center


【解决方案1】:

如果您指的是包含 KML 图层中所有数据的范围:

map.zoomToExtent(KMLLayer.getDataExtent());

见:http://dev.openlayers.org/docs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.getDataExtent

【讨论】:

  • 非常感谢,您拯救了我的一天! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-22
  • 1970-01-01
  • 2021-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多