-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsite.js
72 lines (66 loc) · 2.78 KB
/
site.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
(function() {
var layerids = getLayerIds();
if (!layerids) {
document.getElementById('map1').style.display = 'none';
document.getElementById('map2').style.display = 'none';
document.getElementById('toggle').style.display = 'none';
document.getElementById('help').style.display = 'block';
document.getElementById('compare').onclick = function(e) {
document.getElementById('compare').className = 'bold';
document.getElementById('swipe').className = '';
var elements = document.getElementsByTagName('dd');
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = elements[i].innerHTML.replace(
/http:\/\/lxbarth.com\/compare\/swipe\//g,
'http:\/\/lxbarth.com\/compare\/');
}
return false;
};
document.getElementById('swipe').onclick = function() {
document.getElementById('swipe').className = 'bold';
document.getElementById('compare').className = '';
var elements = document.getElementsByTagName('dd');
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = elements[i].innerHTML.replace(
/http:\/\/lxbarth.com\/compare\//g,
'http:\/\/lxbarth.com\/compare\/swipe\/');
}
return false;
};
return;
}
var map1 = L.mapbox.map('map1', null)
.setView([40, -74.50], 9);
var map2 = L.mapbox.map('map2', null)
.setView([40, -74.50], 9);
addLayer(layerids[0], map1);
addLayer(layerids[1], map2);
L.hash(map1);
// when either map finishes moving, trigger an update on the other one.
map1.on('moveend', follow).on('zoomend', follow);
map2.on('moveend', follow).on('zoomend', follow);
// quiet is a cheap and dirty way of avoiding a problem in which one map
// syncing to another leads to the other map syncing to it, and so on
// ad infinitum. this says that while we are calling sync, do not try to
// loop again and sync other maps
var quiet = false;
function follow(e) {
if (quiet) return;
quiet = true;
if (e.target === map1) sync(map2, e);
if (e.target === map2) sync(map1, e);
quiet = false;
}
// sync simply steals the settings from the moved map (e.target)
// and applies them to the other map.
function sync(map, e) {
map.setView(e.target.getCenter(), e.target.getZoom(), {
animate: false,
reset: true
});
}
// Toggle to swipe.
document.getElementById('toggle').onclick = function() {
location.href = location.origin + location.pathname + "swipe/" + location.search + location.hash;
};
})();