【Leafletjs】5.L.Control 自定义一个Control
L.Control
所有leaflet控制的基础类。继承自IControl接口。 你可以这样添加控件:
control.addTo(map);
// the same as
map.addControl(control);
构造器
构造器 | 使用 | 描述 |
---|---|---|
L.Control( <Control options> options? ) |
new L.Control(…) L.control(…)
|
通过给定的选项创建一个控制。 |
Options
选项 | 类型 | 默认值 | 描述 |
---|---|---|---|
position |
String |
'topright' |
控制初始的位置(在地图的某一角)。参见 control positions. |
Methods
方法 | 返回值 | 描述 |
---|---|---|
setPosition( |
this |
设置控制的位置。参见 control positions. |
getPosition() |
String |
返回控制的当前位置。 |
addTo( |
this |
将控制添加到地图上。 |
removeFrom( |
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.
Position | 描述 |
---|---|
'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); },
});
在定义一些样式后效果如下
高级一点可以定义如下扁平样式的:
【Leafletjs】5.L.Control 自定义一个Control的更多相关文章
- [WPF 自定义控件]自定义一个“传统”的 Validation.ErrorTemplate
1. 什么是Validaion.ErrorTemplate 数据绑定模型允许您将与您Binding的对象相关联ValidationRules. 如果用户输入的值无效,你可能希望在应用程序 用户界面 ( ...
- 自定义View(7)官方教程:自定义View(含onMeasure),自定义一个Layout(混合组件),重写一个现有组件
Custom Components In this document The Basic Approach Fully Customized Components Compound Controls ...
- Control.Invoke和Control.BeginInvoke
问题的引入 下面有个简单的demo,大家一看代码就知道效果如何示例.我新建一个winform的程序,然后写入了如下代码: using System; using System.Windows.Form ...
- Control.Refresh Control.Invalidate 和 Control.OnPaint之间的联系和区别
1.Control.Invalidate会放一个WM_PAINT消息到消息队列,当Control处理到该消息的时候,就调用OnPaint. 2.Control.Refresh相当于以下两行:Contr ...
- 在String()构造器不存在的情况下自定义一个MyString()函数,实现如下内建String()方法和属性:
在String()构造器不存在的情况下自定义一个MyString()函数,实现如下内建String()方法和属性: var s = new MyString("hello"); s ...
- 千万别在UI线程上调用Control.Invoke和Control.BeginInvoke,因为这些是依然阻塞UI线程的,造成界面的假死
原文地址:https://www.cnblogs.com/wangchuang/archive/2013/02/20/2918858.html .c# Invoke和BeginInvoke 区别 Co ...
- SpringMVC 自定义一个拦截器
自定义一个拦截器方法,实现HandlerInterceptor方法 public class FirstInterceptor implements HandlerInterceptor{ /** * ...
- jQuery Validate 表单验证插件----自定义一个验证方法
一.下载依赖包 网盘下载:https://yunpan.cn/cryvgGGAQ3DSW 访问密码 f224 二.引入依赖包 <script src="../../scripts/j ...
- Spring自定义一个拦截器类SomeInterceptor,实现HandlerInterceptor接口及其方法的实例
利用Spring的拦截器可以在处理器Controller方法执行前和后增加逻辑代码,了解拦截器中preHandle.postHandle和afterCompletion方法执行时机. 自定义一个拦截器 ...
随机推荐
- [git]撤销的相关命令:reset、revert、checkout
基本概念 工作区 暂存区 本地版本仓库 远程版本仓库 如果不清晰上面的四个概念,请查看廖老师的git教程 这里我多说几句:最开始我使用git的时候,我并不明白我为什么写完代码要用git的一些列指令把我 ...
- adb shell 查看系统属性(用来判断特殊的操作系统)
一般来讲,在android程序开发中进行需要判断设备类型和系统版本 1.设备类型判断(android.os.Build.MODEL) 比如判断属于Google Nexus 5,Nexus 7,MIUI ...
- Mina工作原理分析
Mina是Apache社区维护的一个开源的高性能IO框架,在业界内久经考验,广为使用.Mina与后来兴起的高性能IO新贵Netty一样,都是韩国人Trustin Lee的大作,二者的设计理念是极为相似 ...
- finetuning caffe
还没解决,以下是解释fine-tune 比如说,先设计出一个CNN结构.然后用一个大的数据集A,训练该CNN网络,得到网络a.可是在数据集B上,a网络预测效果并不理想(可能的原因是数据集A和B存在一些 ...
- char导致的验证异常
表的一个字段: Moblie char(15) 对应的mvc代码: @Html.EditorFor(c => c.Mobile) [RegularExpression("^1[3|4 ...
- 在Winform开发中使用日程控件XtraScheduler
在一些应用场景中,我们可能需要记录某一天,某个时段的日程安排,那么这个时候就需要引入了DevExpress的日程控件XtraScheduler了,这个控件功能非常强大,提供了很好的界面展现方式,以及很 ...
- Swift 3 迁移工作总结
写在前面 Swift 3.0 正式版发布了差不多快一个月了,断断续续的把手上和 Swift 相关的迁移到了Swift 3.0.所以写点小总结. 背景 代码量(4万行) 首先,我是今年年初才开始入手 S ...
- 理清那么多个OO(面向对象)
OOA - Object-Oriented Analysis(面向对象分析) OOT - Object-Oriented Testing (面向对象测试) OOP - Object-Oriented ...
- 使用MySQL Workbench导出MySQL数据库关系图
1. 点击MySQL Workbench中间Data Modeling下的Create EER Model From Existing Database: 2. 在Stored Connection中 ...
- UML类图画法及其之间关系
1.泛化又名继承(Generalization),带空心箭头的实线表示,箭头指向父类 2.实现(Realization),带空心的虚线表示 3.关联(Association),类与类之间的关联,它使一 ...