-
Notifications
You must be signed in to change notification settings - Fork 429
/
Copy pathmarker.js
76 lines (62 loc) · 2.02 KB
/
marker.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
74
75
76
jvm.Marker = function(config){
var text,
offsets;
this.config = config;
this.map = this.config.map;
this.isImage = !!this.config.style.initial.image;
this.createShape();
text = this.getLabelText(config.index);
if (this.config.label && text) {
this.offsets = this.getLabelOffsets(config.index);
this.labelX = config.cx / this.map.scale - this.map.transX;
this.labelY = config.cy / this.map.scale - this.map.transY;
this.label = config.canvas.addText({
text: text,
'data-index': config.index,
dy: "0.6ex",
x: this.labelX,
y: this.labelY
}, config.labelStyle, config.labelsGroup);
this.label.addClass('jvectormap-marker jvectormap-element');
}
};
jvm.inherits(jvm.Marker, jvm.MapObject);
jvm.Marker.prototype.createShape = function(){
var that = this;
if (this.shape) {
this.shape.remove();
}
this.shape = this.config.canvas[this.isImage ? 'addImage' : 'addCircle']({
"data-index": this.config.index,
cx: this.config.cx,
cy: this.config.cy
}, this.config.style, this.config.group);
this.shape.addClass('jvectormap-marker jvectormap-element');
if (this.isImage) {
jvm.$(this.shape.node).on('imageloaded', function(){
that.updateLabelPosition();
});
}
};
jvm.Marker.prototype.updateLabelPosition = function(){
if (this.label) {
this.label.set({
x: this.labelX * this.map.scale + this.offsets[0] +
this.map.transX * this.map.scale + 5 + (this.isImage ? (this.shape.width || 0) / 2 : this.shape.properties.r),
y: this.labelY * this.map.scale + this.map.transY * this.map.scale + this.offsets[1]
});
}
};
jvm.Marker.prototype.setStyle = function(property, value){
var isImage;
jvm.Marker.parentClass.prototype.setStyle.apply(this, arguments);
if (property === 'r') {
this.updateLabelPosition();
}
isImage = !!this.shape.get('image');
if (isImage != this.isImage) {
this.isImage = isImage;
this.config.style = jvm.$.extend(true, {}, this.shape.style);
this.createShape();
}
};