(转) OpenLayers3基础教程——OL3 介绍control
http://blog.csdn.net/gisshixisheng/article/details/46761535
概述:
本文讲述的是Ol3中的control的介绍和应用。
OL2和OL3 control比较:
相比较Ol2的control,OL3显得特别少,下图分别为Ol2和Ol3的control:

Ol2的control

Ol3的control
相比较Ol2,OL3保留了mouseposition,scaleline,zoom,zoomslider,而将很多东西例如draw等转移到了interaction下面,下图为Ol3的interaction:

OL3中control的常用操作:
Ol3中control的常用操作包括获取control集,添加,删除。
获取control集
- var controls = map.getControls();
添加
- map.addControl(ctrl);
删除
- map.removeControl(ctrl);
OL3添加control示例:
下面是一个比较完成的OL3的Control的示例,
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>control</title>
- <link rel="stylesheet" type="text/css" href="http://localhost/ol3/css/ol.css"/>
- <style type="text/css">
- body, #map {
- border: 0px;
- margin: 0px;
- padding: 0px;
- width: 100%;
- height: 100%;
- font-size: 13px;
- }
- #location{
- position: absolute;
- bottom: 10px;
- left: 45%;
- font-weight: bold;
- z-index: 99;
- }
- #switch{
- position:absolute;
- right:20pt;
- top:40pt;
- z-index:999;
- }
- #rotation{
- position: absolute;
- top: 10px;
- left: 45%;
- font-weight: bold;
- z-index: 99;
- }
- .ol-zoomslider{
- background: #d0e5f5;
- width: 20px;
- }
- .zoom-to-extent{
- position: absolute;
- top: 5pt;
- left: 28pt;
- }
- .map-rotate{
- position: absolute;
- top: 5pt;
- left: 45%;
- }
- </style>
- <script type="text/javascript" src="http://localhost/ol3/build/ol.js"></script>
- <script type="text/javascript" src="http://localhost/jquery/jquery-1.8.3.js"></script>
- <script type="text/javascript">
- function init(){
- var format = 'image/png';
- var bounds = [73.4510046356223, 18.1632471876417,
- 134.976797646506, 53.5319431522236];
- var controls = new Array();
- //鼠标位置
- var mousePositionControl = new ol.control.MousePosition({
- className: 'custom-mouse-position',
- target: document.getElementById('location'),
- coordinateFormat: ol.coordinate.createStringXY(5),//保留5位小数
- undefinedHTML: ' '
- });
- controls.push(mousePositionControl);
- //缩放至范围
- var zoomToExtentControl = new ol.control.ZoomToExtent({
- extent: bounds,
- className: 'zoom-to-extent',
- tipLabel:"全图"
- });
- controls.push(zoomToExtentControl);
- //比例尺
- var scaleLineControl = new ol.control.ScaleLine({});
- controls.push(scaleLineControl);
- //全图
- var fullScreenControl = new ol.control.FullScreen({});
- controls.push(fullScreenControl);
- //缩放控件
- var zoomSliderControl = new ol.control.ZoomSlider({});
- controls.push(zoomSliderControl);
- var rotate = new ol.control.Rotate({
- // label:"↑",
- tipLabel:"重置",
- target:document.getElementById('rotation'),
- autoHide:false
- });
- controls.push(rotate);
- var untiled = new ol.layer.Image({
- source: new ol.source.ImageWMS({
- ratio: 1,
- url: 'http://localhost:8081/geoserver/lzugis/wms',
- params: {'FORMAT': format,
- 'VERSION': '1.1.1',
- LAYERS: 'lzugis:province',
- STYLES: ''
- }
- })
- });
- var projection = new ol.proj.Projection({
- code: 'EPSG:4326',
- units: 'degrees'
- });
- var map = new ol.Map({
- controls: ol.control.defaults({
- attribution: false
- }).extend(controls),
- interactions: ol.interaction.defaults().extend([
- new ol.interaction.DragRotateAndZoom()
- ]),
- target: 'map',
- layers: [
- untiled
- ],
- view: new ol.View({
- projection: projection,
- rotation:-45
- })
- });
- map.getView().fitExtent(bounds, map.getSize());
- $("#setRotate").on("click",function(){
- var angle = $("#rotate").val();
- map.getView().setRotation(angle);
- });
- }
- </script>
- </head>
- <body onLoad="init()">
- <div class="layer-change-switch" id="switch">
- <div id="slider">
- <input id="rotate" type="text" value="-45" maxlength="10" style="width: 50px;" /><button id="setRotate">旋转</button>
- </div>
- </div>
- <div id="map">
- <div id="rotation"></div>
- <div id="location"></div>
- </div>
- </body>
- </html>
上述代码效果如下:

(转) OpenLayers3基础教程——OL3 介绍control的更多相关文章
- OpenLayers3基础教程——OL3 介绍control
概述: 本文讲述的是Ol3中的control的介绍和应用. OL2和OL3 control比較: 相比較Ol2的control,OL3显得特别少,下图分别为Ol2和Ol3的control: Ol2的c ...
- (转)OpenLayers3基础教程——OL3 介绍interaction
http://blog.csdn.net/gisshixisheng/article/details/46808647 概述: 本节主要讲述OL3的交互操作interaction,重点介绍draw,s ...
- OpenLayers3基础教程——OL3之Popup
概述: 本节重点讲述OpenLayers3中Popup的调用时实现,OL3改用Overlay取代OL2的Popup功能. 接口简单介绍: overlay跟ol.control.Control一样,是一 ...
- (转)OpenLayers3基础教程——OL3基本概念
http://blog.csdn.net/gisshixisheng/article/details/46756275 OpenLayers3基础教程——OL3基本概念 从本节开始,我会陆陆续续的更新 ...
- OpenLayers3基础教程——OL3基本概念
从本节開始,我会陆陆续续的更新有关OL3的相关文章--OpenLayers3基础教程,欢迎大家关注我的博客,同一时候也希望我的博客可以给大家带来一点帮助. 概述: OpenLayers 3对OpenL ...
- (转)OpenLayers3基础教程——OL3之Popup
http://blog.csdn.net/gisshixisheng/article/details/46794813 概述: 本节重点讲述OpenLayers3中Popup的调用时实现,OL3改用O ...
- ActiveMQ基础教程----简单介绍与基础使用
概述 ActiveMQ是由Apache出品的,一款最流行的,能力强劲的开源消息总线.ActiveMQ是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,它非常快速,支持多 ...
- Embedded Linux Primer----嵌入式Linux基础教程--章节介绍
章节介绍 第一章,“导引”,简要介绍了Linux被迅速应用在嵌入式环境的驱动因素,介绍了与嵌入式Linux相关的几个重要的标准和组织. 第二章,“第一个嵌入式经历”,介绍了与后几章所构建的嵌入式Lin ...
- (转) OpenLayers3基础教程——加载资源
概述: 本节讲述如何在Ol3中加载wms图层并显示到地图中. Ol3下载: 你可以在OL官网去下载,下载地址为http://openlayers.org/download/,也可以去我的百度云盘下载, ...
随机推荐
- linux修改mysql表结构
增加字段: alter table [tablename] add [字段名] [字段类型] first(首位); alter table [tablename] add [字段名] [字段类型] a ...
- Java 注解之总结
注解是Spring和Mybatis框架所大量使用的技术,要想掌握框架相关技术,注解是必须要掌握的. 掌握注解的优势: 1.能够读懂别人写的代码,特别是框架相关的代码. 2.本来可能需要很多配置文件,需 ...
- hdu_1014_Uniform Generator_201310141958
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Expanding Rods POJ 1905 二分
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17050 Accepted: 4503 Description When ...
- Java设计模式——外观模式
JAVA 设计模式 外观模式 用途 外观模式 (Facade) 为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 外观模式是一种结构型模式. 结构
- Redis 3.0.0 正式版出炉,高性能 K/V 服务
Redis 3.0.0 正式版最终到来了,与 RC6 版本号比較.该版本号改进包含: * 修复了无磁盘的复制问题 (Oran Agra) * 在角色变化后对 BLPOP 复制进行測试 (Salvato ...
- poj 2506 Tiling(大数+规律)
poj2506Tiling 此题规律:A[0]=1;A[1]=1;A[2]=3;--A[n]=A[n-1]+2*A[n-2];用大数来写,AC代码: #include<stdio.h> # ...
- SEO优化之外链的末日来临
告诉大家一个好消息,以后不用再为外链的事情发愁了.难道是有好的外链工具?不是,而是百度已经取消外链了. 今天在百度上看到一篇文章:"SEO春天来了.百度取消外链".点击进去一看,吓 ...
- 数据结构之---C语言实现最短路径之Dijkstra(迪杰斯特拉)算法
此处共同拥有两段代码: 一. 这段代码比較全面,当中參考了github上的相关源代码. 能够说功能强大. //Dijkstra(迪杰斯特拉算法) #include <stdio.h> #i ...
- linux更改gitlab存储位置
更改仓库存储位置默认时GitLab的仓库存储位置在“/var/opt/gitlab/git-data/repositories”,在实际生产环境中显然我们不会存储在这个位置,一般都会划分一个独立的分区 ...