forked from huiyan-fe/mapv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapMask.js
More file actions
67 lines (57 loc) · 1.76 KB
/
Copy pathMapMask.js
File metadata and controls
67 lines (57 loc) · 1.76 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
/**
* 一直覆盖在当前地图视野的覆盖物
*
* @author nikai (@胖嘟嘟的骨头, nikai@baidu.com)
*
* @param
* {
* map 地图实例对象
* elementTag 覆盖物容器的标签类型,默认是div,我们这canvas用的多
* }
*/
function MapMask(options){
this.options = options || {};
this.initElement();
this._map = options.map;
this.show();
}
MapMask.prototype = new BMap.Overlay();
MapMask.prototype.initialize = function(map){
this._map = map;
var elementTag = this.options.elementTag || "div";
var element = this.element = document.createElement(elementTag);
var size = map.getSize();
element.width = size.width;
element.height = size.height;
element.style.cssText = "position:absolute;"
+ "left:0;"
+ "top:0;"
+ "width:" + size.width + "px;"
+ "height:" + size.height + "px";
if (this.options.zIndex !== undefined) {
element.style.zIndex = this.options.zIndex;
}
map.getPanes().labelPane.appendChild(this.element);
return this.element;
}
MapMask.prototype.initElement = function(map){
}
MapMask.prototype.draw = function(){
var map = this._map;
var bounds = map.getBounds();
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var pixel = map.pointToOverlayPixel(new BMap.Point(sw.lng, ne.lat));
this.element.style.left = pixel.x + "px";
this.element.style.top = pixel.y + "px";
this.dispatchEvent('draw');
}
MapMask.prototype.getContainer = function(){
return this.element;
}
MapMask.prototype.show = function(){
this._map.addOverlay(this);
}
MapMask.prototype.hide = function(){
this._map.removeOverlay(this);
}