OpenLayers3基础教程——OL3 介绍control
来源:互联网 发布:类似redmine的软件 编辑:程序博客网 时间:2024/06/01 08:29
概述:
本文讲述的是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基本概念
OpenLayers3基础教程——加载资源
1 0
- OpenLayers3基础教程——OL3 介绍control
- OpenLayers3基础教程——OL3 介绍interaction
- OpenLayers3基础教程——OL3基本概念
- OpenLayers3基础教程——OL3之Popup
- OpenLayers3基础教程——加载资源
- openlayers3 ol3热力图 json
- OpenLayers3 学习心得(一)——体系结构
- OpenLayers3 学习心得(三)——绘图
- OpenLayers3 学习心得(五)——测量
- openlayers3投影转换——proj4js
- 基础教程介绍——什么是SOA?
- 基础教程介绍——什么是SOA
- unity3d基础教程—组件介绍1
- OpenLayers3
- openlayers3
- OpenLayers3 学习心得(二)——开发配置
- OpenLayers3 学习心得(四)——空间查询
- OpenLayers3 学习心得(六)——WMS服务
- MySQL优化之——视图
- Domino中的读者域和作者域
- HBase集群数据迁移方案
- H5大会之后,未来指向何方?
- 【iOS开发之Objective-C】继承
- OpenLayers3基础教程——OL3 介绍control
- 自定义Stack
- 再议javascript变量作用域
- 使用AutoCompleteExtender实现文本框自动匹配
- IPO 首次公开募股(Initial Public Offerings,简称IPO)
- Python编写算法导论基本算法
- 使用CascadingDropDown实现级联式下拉框
- poj1154解题报告(dfs)
- Asp.Net Ajax的两种基本开发模式