[Javascript]从 openlayers 地图获取坐标
我将从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 getExtent() Map 对象的功能。
它将返回一个 OpenLayers.Bounds 对象,它将具有当前视图的上、左、下、右坐标。
You should use the getExtent() function of the Map object.
It will return you an OpenLayers.Bounds object, which will have the top, left, bottom and right coordinates of the current view.
我想你想使用 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)