急,请教openlayers的问题!!!

tangjr 2009-06-09 05:30:53
我要做在地图上画个矩形,画完之后取得矩形的范围的功能,对openlayers了解不深不知道如何下手,请教各位大侠,谢了!
...全文
234 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
laowei206 2009-06-17
  • 打赏
  • 举报
回复
参见examples目录下的custom-control.html
按shift键拉框

代码如下:
function init(){
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );

var control = new OpenLayers.Control();

OpenLayers.Util.extend(control, {
draw: function () {
// this Handler.Box will intercept the shift-mousedown
// before Control.MouseDefault gets to see it
this.box = new OpenLayers.Handler.Box( control,
{"done": this.notice},
{keyMask: OpenLayers.Handler.MOD_SHIFT});
this.box.activate();
},

notice: function (bounds) {
var ll = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.left, bounds.bottom));
var ur = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.right, bounds.top));
alert(ll.lon.toFixed(4) + ", " +
ll.lat.toFixed(4) + ", " +
ur.lon.toFixed(4) + ", " +
ur.lat.toFixed(4));
}
});

map.addLayer(layer);
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
}
传说中的堕落 2009-06-12
  • 打赏
  • 举报
回复
同楼上.
metaboy 2009-06-10
  • 打赏
  • 举报
回复
看openlayer的demo,不知道现在版本是多少,我记得我用2.6的时候里面有类似的demo程序!你可以参考研究下!

2,142

社区成员

发帖
与我相关
我的任务
社区描述
它是一种特定的十分重要的空间信息系统。它是在计算机硬、软件系统支持下,对整个或部分地球表层(包括大气层)空间中的有关地理分布数据进行采集、储存、管理、运算、分析、显示和描述的技术系统。
社区管理员
  • 地理信息系统
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧