-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwkmap.js
94 lines (90 loc) · 2.3 KB
/
wkmap.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function uncollect (buf, canvas) {
var fullLength = buf.byteLength,
drawn = 0,
ctx = canvas.getContext('2d'),
ukbtype, nsubgeoms, view, x, y, px, py,
dv = new DataView ( buf, 0, fullLength );
while (drawn < fullLength) {
ukbtype = dv.getUint32(drawn, true);
if (ukbtype === 2) {
nsubgeoms = dv.getUint32(drawn + 4, true);
if (nsubgeoms > 0) {
drawn = line( dv, (drawn+4), ctx );
} else {
drawn += 12;
}
}
else if (ukbtype === 3) {
drawn = polygon ( dv, drawn+4, ctx );
}
else if (ukbtype === 1) {
drawn = point ( dv, drawn+4, ctx );
}
else {
ukbtype = 0;
drawn += 12;
}
}
return canvas
}
function polygon (dv, idx, ctx) {
var drawn = 0,
idx = idx,
npts = dv.getUint32(idx, true)
osmstyle = dv.getUint32(idx + 4, true);
idx += 8;
if (npts === 0) {
return idx;
}
ctx.moveTo(dv.getInt16(idx, true)/10, (-1)*dv.getInt16( idx + 2, true)/10);
ctx.beginPath();
idx += 4;
if (npts === 2) {
ctx.lineTo(dv.getInt16(idx, true)/10, (-1)*dv.getInt16( idx + 2, true)/10);
ctx.closePath()
ctx.stroke()
return idx + 4;
}
for (var i = 4; i < 4*(npts-1); i += 4) {
ctx.lineTo(dv.getInt16(idx + i, true)/10, (-1)*dv.getInt16( idx + i + 2, true)/10);
}
ctx.stroke();
ctx.closePath()
ctx.fill()
return idx + 4*(npts - 1);
}
function line (dv, idx, ctx) {
var drawn = 0,
idx = idx,
npts = dv.getUint32(idx, true),
osmstyle = dv.getUint32(idx + 4, true);
streetrender(osmstyle, ctx);
idx += 8;
ctx.beginPath();
ctx.moveTo(dv.getInt16(idx, true)/10, (-1)*dv.getInt16( idx + 2, true)/10);
idx += 4;
if (npts === 2) {
ctx.lineTo(dv.getInt16(idx, true)/10, (-1)*dv.getInt16( idx + 2, true)/10);
ctx.closePath()
ctx.stroke()
return idx + 4;
}
for (var i = 4; i < 4*(npts-1); i += 4) {
ctx.lineTo(dv.getInt16(idx + i, true)/10, (-1)*dv.getInt16( idx + i + 2, true)/10);
}
ctx.stroke();
return idx + 4*(npts - 1);
}
function point (dv, idx, ctx) {
var idx = idx,
osmstyle = dv.getUint32(idx + 4, true);
idx += 8;
ctx.beginPath();
ctx.arc(dv.getInt16(idx, true)/10,
(-1)*dv.getInt16( idx + 2, true)/10,
1, 0, Math.PI*2);
ctx.fill();
ctx.stroke();
ctx.closePath();
return idx+4;
}