Leaflet自定义一个Control(L.Control)
来源:互联网 发布:vscode 离线插件包 编辑:程序博客网 时间:2024/06/05 20:50
本文转载出处:【Leafletjs】5.L.Control 自定义一个Control
L.Control
所有leaflet控制的基础类。继承自IControl接口。 你可以这样添加控件:
control.addTo(map);// the same asmap.addControl(control);
构造器
L.Control( <Control options> options? )
new L.Control(…)
L.control(…)
通过给定的选项创建一个控制。Options
position
String
'topright'
控制初始的位置(在地图的某一角)。参见 control positions.Methods
setPosition( <String> position )
this
设置控制的位置。参见 control positions.getPosition()
String
返回控制的当前位置。addTo( <Map> map )
this
将控制添加到地图上。removeFrom( <Map> map )
this
将控制从地图上移除。getContainer()
HTMLElement
返回 the HTML container of the control.Control Positions(控制的位置)
Control positions (map corner to put a control to) are set using strings. Margins between controls and the map border are set with CSS, so that you can easily override them.
'topleft'
地图的左上角。'topright'
地图的右上角。'bottomleft'
地图的左下角。'bottomright'
地图的右下角。下面讲下如何创建一个自定义控件
基本模板:
L.Control.XXX= L.Control.extend({ //在此定义参数
options: { },
//在此初始化 initialize: function (options) { L.Util.extend(this.options, options); }, onAdd: function (map) { //可在此添加控件内容 }});
以此模板创建一个简单图例控件
L.Control.Legend = L.Control.extend({ options: { position: 'topright' //初始位置 }, initialize: function (options) { L.Util.extend(this.options, options); }, onAdd: function (map) {
//创建一个class为leaflet-control-clegend的div
this._container = L.DomUtil.create('div', 'leaflet-control-clegend');
//创建一个图片要素 var legendimg = document.createElement('img'); legendimg.id = 'leaflet-control-clegend'; legendimg.type = 'img'; legendimg.src = "../../Content/legend.png"; this._legendimg = legendimg; //创建一个关闭控件的按钮 var closebutton = document.createElement('a'); closebutton.id = 'leaflet-control-geosearch-close'; closebutton.className = 'glyphicon glyphicon-remove'; this._closebutton = closebutton; this._container.appendChild(this._closebutton); this._container.appendChild(this._legendimg); //注册关闭事件 L.DomEvent.addListener(this._closebutton, 'click', this._onCloseControl, this); return this._container; }, _onCloseControl: function () { this._map.options.Legend = false; this.removeFrom(this._map); },});
在定义一些样式后效果如下
高级一点可以定义如下扁平样式的:
阅读全文
0 0
- Leaflet自定义一个Control(L.Control)
- L.Control 自定义一个Control
- 【Leafletjs】L.Control 自定义一个Control
- Control
- Control
- Control
- Control
- leaflet中Layer Groups和Layers Control用法
- control自定义事件指南
- 自定义 Segmented Control
- 自定义asp.net mobile control
- TC(Table Control)自定义F4
- TC(Table Control)自定义F4
- Custom Control控件一个例子
- Tab Control的一个运用
- edit control的一个例子
- Asp.net Web Crop Image Control asp.net控件和jquery 自定义的一个截图控件
- [WPF]如何自定义一个User Control 并在Page.xaml里使用它
- 为什么基类的析构函数为虚函数
- 冒泡排序-C语言
- 财务凭证过账增强 BAPI_ACC_DOCUMENT_POST
- Git------公司常用操作
- 全栈式web开发技术-List
- Leaflet自定义一个Control(L.Control)
- CNN 模型压缩与加速算法综述
- 工作日志:ButterKnife框架的理解与使用
- js实现分页
- 【arduino】蓝牙模块学习(1)更改蓝牙名称密码波特率
- quartz
- Ubuntu 16添加开机启动脚本
- python+selenium控制谷歌页面滚动条导致白页的问题解决
- OC NSSpeechSynthesizer朗读