2

我会从 openlayers 地图中获取坐标。当我打开我的页面时,当我单击一个按钮时,我会收到左上角和右上角的坐标。

 <html>
<head>
  <title>OpenLayers Example</title>
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
    </head>
    <body>
      <div style="width:100%; height:100%" id="map"></div>
      <script defer="defer" type="text/javascript">
        var map = new OpenLayers.Map('map');
        var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
        map.addLayer(wms);
        map.zoomToMaxExtent();
      </script>
<input type="button" text="Get Coordinate from map">
</body>
</html>

非常感谢。

4

2 回答 2

4

您应该使用 Map 对象的getExtent()函数。

退货

{OpenLayers.Bounds} 一个 Bounds 对象,表示当前视口的经纬度边界。

它将返回一个OpenLayers.Bounds对象,该对象将具有当前视图的顶部、左侧、底部和右侧坐标。

于 2010-06-23T09:04:35.783 回答
0

I think you want to use map.getCenter() ? (this is in case you want the center coordinates of the map in lat lon, but it's not really clear what coordinate you want)

于 2010-06-22T12:57:35.447 回答