Openlayers学习笔记——Controls类

Controls affect the display or behavior of the map. They allow everything from panning and zooming to displaying a scale indicator. Controls by default are added to the map they are contained within however it is possible to add a control to an external div by passing the div in the options parameter. API中的描述
Controls是用来控制地图的,主要功能如下:
1.用户与地图交互,如pan、Panto、zoomIn、ZoomOut;
2.在地图map上添加修饰,如Navigation、ToolBar、scaleLine;

一 如何应用Controls?
首先我们看看Controls的类型分类,在Openlayers中多数Controls直接可以在地图上添加,比如Navigation(导航栏),第二类是需要放在Div元素中才能用,这点与地图map很相似,第三类需要放置在panel(面板)中的操作类似于网页HTML中button按钮,需要点击或绑定才能起作用,最后一类就是自定义类型的。
如何在地图中添加Controls? 步骤如下:
1.添加Controls相关的javascript包,实例化地图对象map和Controls对象;
2.利用map对象的addControl()或addControls()方法在地图上添加Controls对象;

在地图map实例化时,四中Controls会自动添加到地图map中去,分别为Openlayers.Control.Navigation(导航栏)、Openlayers.Control.PanZoom(向左向右,放大缩小等),Openlayers.Control.ArgParser(允许用户缩放到指定位置,根据Url打开/关闭地图),Openlayers.Control.Attribution(在地图上相应图层添加属性)

二 实例
创建不含Controls的地图对象
1.需要创建一个包含空数组control对象的地图对象
map=new Openlayers.Map('map_element',{control:[]});

2.地图对象中添加layer

var wms_layer = new OpenLayers.Layer.WMS(
'WMS Layer Title',
'http://vmap0.tiles.osgeo.org/wms/vmap0',
{layers: 'basic'},
{}
);
map.addLayer(wms_layer);

3.创建Control对象填充Controls数组

var navigation_control = new OpenLayers.Control.Navigation({});
var controls_array = [
navigation_control,
new OpenLayers.Control.PanZoomBar({}),
new OpenLayers.Control.LayerSwitcher({}),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.MousePosition({})
];

4.在地图map对象上添加Controls

map = new OpenLayers.Map('map_element', {
controls: controls_array
});
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

未来AI编程

共鸣===鼓励 打赏您随意

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值