-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
98 lines (77 loc) · 2.82 KB
/
index.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
95
96
97
98
var mm = com.modestmaps,
timeout = undefined,
mmap = undefined;
function limitAndFix(value, lowest, highest)
{
return (new Number(Math.max(lowest, Math.min(highest, value)))).toFixed(3);
}
function makeUserdata(style, north, south, east, west)
{
console.log([north, south, east, west]);
var req = new XMLHttpRequest(),
userdata = document.getElementById('userdata');
userdata.className = 'loading';
userdata.innerHTML = '\n\n\n';
req.onreadystatechange = function()
{
try {
if(req.status == 200)
{
userdata.className = '';
userdata.innerHTML = req.responseText;
}
} catch(e) {
}
}
req.open('POST', 'check-bounds.cgi');
req.send(['north='+north, 'south='+south, 'east='+east, 'west='+west, 'style='+style].join('&'));
}
function onChanged()
{
var buffer = 33; // extra space around the visible map
var topleft = new mm.Point(-buffer, -buffer);
var bottomright = new mm.Point(mmap.dimensions.x + buffer, mmap.dimensions.y + buffer);
var northwest = mmap.pointLocation(topleft);
var southeast = mmap.pointLocation(bottomright);
var north = limitAndFix(northwest.lat, -85, 85);
var south = limitAndFix(southeast.lat, -85, 85);
var east = limitAndFix(southeast.lon, -180, 180);
var west = limitAndFix(northwest.lon, -180, 180);
var styleform = document.forms.style;
if(styleform)
{
window.clearTimeout(timeout);
timeout = window.setTimeout(makeUserdata, 500, styleform.elements.url.value, north, south, east, west);
}
}
function chooseStyle(url)
{
document.forms.style.elements.url.value = url;
onChanged();
return false;
}
var tileURL = function(coord)
{
return 'http://tile.cloudmade.com/f1fe9c2761a15118800b210c0eda823c/1/256/' + coord.zoom + '/' + coord.column + '/' + coord.row + '.png';
var sub = ['a', 'b', 'c'][(coord.zoom + coord.column + coord.row) % 3];
return 'http://' + sub + '.tile.openstreetmap.org/' + coord.zoom + '/' + coord.column + '/' + coord.row + '.png';
}
window.onload = function(e)
{
mmap = new mm.Map('map', new mm.MapProvider(tileURL), new mm.Point(446, 446));
mmap.addCallback('zoomed', function(m, a) { return onChanged(); });
mmap.addCallback('centered', function(m, a) { return onChanged(); });
mmap.addCallback('extentset', function(m, a) { return onChanged(); });
mmap.addCallback('panned', function(m, a) { return onChanged(); });
mmap.setCenterZoom(new mm.Location(0, 0), 1);
mmap.draw();
/*
var head = document.getElementById('header'),
top = 185;
window.onscroll = function(e)
{
head.className = (document.body.scrollTop > top) ? 'pegged' : '';
}
window.onscroll();
*/
}