forked from bjornd/jvectormap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bjornd#208 support for Lines between markers added to JVectorMap
- Loading branch information
Dominik Franek
committed
Dec 20, 2017
1 parent
a0e5497
commit 1f1b555
Showing
3 changed files
with
1,549 additions
and
957 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Created by fdominik | ||
*/ | ||
jvm.Line = function(config){ | ||
var text,name,points; | ||
|
||
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 = this.config.sx + this.offsets[0];// / this.map.scale - this.map.transX; | ||
this.labelY = this.config.sy + this.offsets[1];// / 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-line jvectormap-element'); | ||
} | ||
}; | ||
|
||
jvm.inherits(jvm.Line, jvm.MapObject); | ||
|
||
jvm.Line.prototype.createShape = function(){ | ||
var that = this; | ||
|
||
if (this.shape) { | ||
this.shape.remove(); | ||
} | ||
this.shape = this.config.canvas.addPath({ | ||
d: this.config.path, | ||
'data-index':this.config.index | ||
}, this.config.style, this.config.group); | ||
|
||
this.shape.addClass('jvectormap-line jvectormap-element'); | ||
|
||
if (this.isImage) { | ||
jvm.$(this.shape.node).on('imageloaded', function(){ | ||
that.updateLabelPosition(); | ||
}); | ||
} | ||
}; | ||
|
||
jvm.Line.prototype.updateLabelPosition = function(){ | ||
if (this.label) { | ||
this.label.set({ | ||
x: this.labelX * this.map.scale + this.map.transX * this.map.scale, | ||
y: this.labelY * this.map.scale + this.map.transY * this.map.scale | ||
}); | ||
} | ||
}; |
Oops, something went wrong.