-
Notifications
You must be signed in to change notification settings - Fork 1
/
canvas_helper.js
55 lines (44 loc) · 1.23 KB
/
canvas_helper.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
var canvasHelper = {
draw: function(context, path){
context.beginPath();
context.lineWidth = 3;
context.moveTo(path[0].x, path[0].y);
for(var i=1;i<path.length;i++){
context.lineTo(path[i].x, path[i].y);
context.fillRect(path[i].x-2, path[i].y-2, 4, 4);
}
var pin = new Image();
pin.src = "pin-target.png";
pin.onload = function() {
context.drawImage(pin, path[path.length-1].x-32, path[path.length-1].y-56);
};
context.strokeStyle = "brown";
context.stroke();
},
getCursorPosition: function(e) {
var x;
var y;
if (e.pageX || e.pageY) {
x = e.pageX;
y = e.pageY;
}
else {
x = e.clientX + document.body.scrollLeft +
document.documentElement.scrollLeft;
y = e.clientY + document.body.scrollTop +
document.documentElement.scrollTop;
}
x -= canvas.offsetLeft;
y -= canvas.offsetTop;
console.log(x,y)
},
drawPoint: function(point){
var context = $("#drawing")[0].getContext("2d");
context.beginPath();
context.arc(point.pageX, point.pageY, 5, 0, 2 * Math.PI, false);
context.closePath();
context.lineWidth = 5;
context.strokeStyle = "black";
context.stroke();
}
};