forked from huiyan-fe/mapv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawTypeControl.js
More file actions
77 lines (63 loc) · 2.23 KB
/
Copy pathDrawTypeControl.js
File metadata and controls
77 lines (63 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @file 选址绘制类型控件
* @author nikai (@胖嘟嘟的骨头, [email protected])
*/
/* globals util BMap BMAP_ANCHOR_TOP_LEFT BMAP_ANCHOR_TOP_RIGHT*/
util.addCssByStyle(
[
'#MapvDrawTypeControl { list-style:none; position:absolute; right:0px; top:0px; bottom:0px; padding:0; margin:0; }',
'#MapvDrawTypeControl li{ padding:0; margin:0; cursor:pointer; margin:1px 0;',
'color:#fff; padding:5px; background:rgba(0, 0, 0, 0.5); }',
'#MapvDrawTypeControl li.current{ background:rgba(0, 0, 255, 0.5); }'
].join('\n')
);
function DrawTypeControl(options) {
options = options || {};
// console.log('@@@@@@', options)
this.mapv = options.mapv;
// 默认停靠位置和偏移量
this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
this.defaultOffset = new BMap.Size(10, 10);
}
DrawTypeControl.prototype = new BMap.Control();
DrawTypeControl.prototype.initialize = function (map) {
var ul = this.ul = document.createElement('ul');
ul.setAttribute('id', 'MapvDrawTypeControl');
var me = this;
ul.addEventListener('click', function (e) {
var target = e.target;
if (target.nodeName === 'LI') {
var parentNode = target.parentNode;
var children = parentNode.getElementsByTagName('li');
for (var i = 0; i < children.length; i++) {
children[i].className = '';
}
var drawType = target.getAttribute('drawType');
target.className = 'current';
me._layer.setDrawType(drawType);
}
});
// 添加DOM元素到地图中
map.getContainer().appendChild(ul);
// 将DOM元素返回
return ul;
};
DrawTypeControl.prototype.getContainer = function () {
return this.ul;
};
DrawTypeControl.prototype.showLayer = function (layer) {
this._layer = layer;
// get the drawTypes from options by Mofei
var ul = this.ul;
ul.innerHTML = "";
var drawTypes = layer.getDrawOptions();
for (var key in drawTypes) {
var li = document.createElement('li');
if (layer.getDrawType() === key) {
li.className = 'current';
}
li.setAttribute('drawType', key);
li.innerHTML = key;
ul.appendChild(li);
}
}