【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方法执行时机. 自定义一个拦截器 ...
随机推荐
- 漫谈可视化Prefuse(四)---被玩坏的Prefuse API
这个双12,别人都在抢红包.逛淘宝.上京东,我选择再续我的“漫谈可视化”系列(好了,不装了,其实是郎中羞涩...) 上篇<漫谈可视化Prefuse(三)---Prefuse API数据结构阅读有 ...
- SQLServer学习笔记系列4
一.写在前面的话 好多天没有记录sql学习笔记了,要坚持下去,坚信每一点的进步都是为在积蓄力量.今天看到一幅图,特此分享出来. 通过这幅图,我看到的是每人站在自己的角度看问题,感受是不一样的,就如同学 ...
- Azure ARM (4) 开始创建ARM Resource Group并创建存储账户
<Windows Azure Platform 系列文章目录> 好了,接下来我们开始创建Azure Resource Group. 1.我们先登录Azure New Portal,地址是: ...
- js无法对远程图片进行Base64转码
web端图片转成Base64码报错 Image from origin 'http://114.215.87.123:8900' has been blocked from loading by Cr ...
- NetworkError: 404 Not Found - http://www.companyName.com/Content/fonts/ubuntu-regular-webfont.woff2
网站是使用BootStrap框架实现,当站点发布至服务器(Windows Server 2008 R2)IIS之后,显示下面的异常: Insus.NET跑至相关目录之下检查,这些字体的文件是确实存在的 ...
- 基于C#的MongoDB数据库开发应用(3)--MongoDB数据库的C#开发之异步接口
在前面的系列博客中,我曾经介绍过,MongoDB数据库的C#驱动已经全面支持异步的处理接口,并且接口的定义几乎是重写了.本篇主要介绍MongoDB数据库的C#驱动的最新接口使用,介绍基于新接口如何实现 ...
- C# Graphics绘图 picBox
需求: Bitmap bm = new Bitmap(picboxPreview.Width, picboxPreview.Height); using (Graphics g = Graphics. ...
- C#自定义特性实例
元数据,就是C#中封装的一些类,无法修改.类成员的特性被称为元数据中的注释. 1.什么是特性 (1)属性与特性的区别 属性(Property):属性是面向对象思想里所说的封装在类里面的数据字段, ...
- Firemonkey TComboBox 下拉菜单字型修改方法 (D10)
在 FMX 下的 TComboBox 下拉菜单字型修改有二种方法: uses FMX.Pickers; 使用 Style,需先设定好 Style 后,再指定预设项的 Style,方法如下: proce ...
- Oracle 表分组 group by和模糊查询like
分组group by写法 select 字段名 from 表名 group by 字段名 查询这个字段名里的种类分组后可以加聚合函数select 字段名,聚合函数 from 表名 group by 字 ...