[Javascript]从 openlayers 地图获取坐标

发布于 2024-09-06 06:06:59 字数 765 浏览 6 评论 0原文

我将从 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>

多谢。

I would get the coordinate from an openlayers map.
When I open my page I would that when I click on a button, I have received the coordinate of top bottom left and the upper right.

 <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>

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

郁金香雨 2024-09-13 06:06:59

您应该使用 getExtent() Map 对象的功能。

退货

{OpenLayers.Bounds} Bounds 对象
代表经度/纬度范围
当前视口。

它将返回一个 OpenLayers.Bounds 对象,它将具有当前视图的上、左、下、右坐标。

You should use the getExtent() function of the Map object.

Returns

{OpenLayers.Bounds} A Bounds object
which represents the lon/lat bounds of
the current viewPort.

It will return you an OpenLayers.Bounds object, which will have the top, left, bottom and right coordinates of the current view.

那伤。 2024-09-13 06:06:59

我想你想使用 map.getCenter()
(这是为了防止您想要地图的经纬度中心坐标,但并不清楚您想要什么坐标)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文