-
Notifications
You must be signed in to change notification settings - Fork 3
/
display.html
89 lines (88 loc) · 2.8 KB
/
display.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>San Francisco</title>
<script src="jquery-2.0.3.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css" media="all">
* {margin: 0; padding: 0;}
body {background: black;}
#display {display: block; margin: 0 0; border: 1px solid black;
background:url(disc/map_med.png)}
</style>
<script type="text/javascript" charset="utf-8">
var first = true;
var sx = 0;
var sy = 0;
function relMouseCoords(event) {
var totalOffsetX = 0;
var totalOffsetY = 0;
var canvasX = 0;
var canvasY = 0;
var elem = this;
var w = elem.width;
var h = elem.height;
var grid_size = 200;
do {
totalOffsetX += elem.offsetLeft - elem.scrollLeft;
totalOffsetY += elem.offsetTop - elem.scrollTop;
}
while (elem = elem.offsetParent) {
canvasX = event.pageX - totalOffsetX;
canvasY = event.pageY - totalOffsetY;
}
if (first) {
sx = canvasX;
sy = canvasY;
first = false;
}
else {
rect = {'coords': [grid_size*sx/w, grid_size*(h-sy)/h,
grid_size*canvasX/w, grid_size*(h-canvasY)/h]};
var mx = (sx + canvasX)/2;
var my = (sy + canvasY)/2;
var wr = Math.abs(sx - canvasX);
var hr = Math.abs(sy - canvasY);
var LWIDTH = 320;
var FONT_SIZE = 18;
if (mx + wr/2 + LWIDTH < w) { var lx = mx + wr/2 + 10; }
else { var lx = mx - wr/2 - LWIDTH - 10; }
var ly = my - hr/2 - 10;
var wl = Math.min(w - lx, 320);
var canvas = document.getElementById('display');
var ctx = canvas.getContext('2d');
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.clearRect(0, 0, w, h);
ctx.font = FONT_SIZE+'pt OpenSans';
ctx.strokeStyle="#FF0000";
ctx.lineWidth = 4;
ctx.strokeRect(Math.min(sx, canvasX), Math.min(sy, canvasY), wr, hr);
var jqxhr = $.post("click", rect, function(data) {
var tags = data.split("\n");
var NUM_RES = tags.length;
if (NUM_RES < 2) {return;}
var hl = Math.min(h - ly, FONT_SIZE*1.25*(NUM_RES+1));
ctx.fillStyle = 'rgba(55, 55, 55, 0.75)';
ctx.fillRect(lx, ly, wl, hl);
ctx.fillStyle = 'white';
multilines_text(ctx, tags, lx, ly, FONT_SIZE*1.25);
console.log(data); });
first = true;
}
};
function multilines_text(ctx, lines, x, y, line_height) {
var num_line = lines.length;
var current_y = y + line_height/2;
for (var i=0; i<num_line; i++) {
current_y += line_height;
ctx.fillText(lines[i], x+line_height/2, current_y);
}
}
HTMLCanvasElement.prototype.relMouseCoords = relMouseCoords;
</script>
</head>
<body>
<canvas id="display" width="2000" height="1786" onclick="relMouseCoords(event);"
alt="San Francisco" title="San Francisco"></canvas>
</body>
</html>