-
Notifications
You must be signed in to change notification settings - Fork 430
/
map-object.js
73 lines (65 loc) · 1.95 KB
/
map-object.js
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
jvm.MapObject = function(config){};
jvm.MapObject.prototype.getLabelText = function(key){
var text;
if (this.config.label) {
if (typeof this.config.label.render === 'function') {
text = this.config.label.render(key);
} else {
text = key;
}
} else {
text = null;
}
return text;
}
jvm.MapObject.prototype.getLabelOffsets = function(key){
var offsets;
if (this.config.label) {
if (typeof this.config.label.offsets === 'function') {
offsets = this.config.label.offsets(key);
} else if (typeof this.config.label.offsets === 'object') {
offsets = this.config.label.offsets[key];
}
}
return offsets || [0, 0];
}
/**
* Set hovered state to the element. Hovered state means mouse cursor is over element. Styles will be updates respectively.
* @param {Boolean} isHovered <code>true</code> to make element hovered, <code>false</code> otherwise.
*/
jvm.MapObject.prototype.setHovered = function(isHovered){
if (this.isHovered !== isHovered) {
this.isHovered = isHovered;
this.shape.isHovered = isHovered;
this.shape.updateStyle();
if (this.label) {
this.label.isHovered = isHovered;
this.label.updateStyle();
}
}
};
/**
* Set selected state to the element. Styles will be updates respectively.
* @param {Boolean} isSelected <code>true</code> to make element selected, <code>false</code> otherwise.
*/
jvm.MapObject.prototype.setSelected = function(isSelected){
if (this.isSelected !== isSelected) {
this.isSelected = isSelected;
this.shape.isSelected = isSelected;
this.shape.updateStyle();
if (this.label) {
this.label.isSelected = isSelected;
this.label.updateStyle();
}
jvm.$(this.shape).trigger('selected', [isSelected]);
}
};
jvm.MapObject.prototype.setStyle = function(){
this.shape.setStyle.apply(this.shape, arguments);
};
jvm.MapObject.prototype.remove = function(){
this.shape.remove();
if (this.label) {
this.label.remove();
}
};