-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
60 lines (53 loc) · 2.04 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
var xhr = require('xhr');
if (window.location.search) {
var overlay = document.getElementById('overlay');
overlay.parentNode.removeChild(overlay);
}
var basePath = window.location.href.split('?')[0].split('#')[0];
// Add the user to the map and get their current
// location
xhr({ uri: basePath + 'first', json: true }, function(err, res, body) {
xhr({ uri: basePath + 'add/' + body.key, json: true }, function(err, res, body) {
L.mapbox.accessToken = 'pk.eyJ1IjoidG1jdyIsImEiOiJIZmRUQjRBIn0.lRARalfaGHnPdRcc-7QZYQ';
// Create a map in the div #map
var map = L.mapbox.map('map', 'tmcw.l12c66f2', {
maxZoom: 6,
scrollWheelZoom: false
});
// Zoom into the current user
var ownpoint = L.geoJson(body.self, {
pointToLayer: function(geojson, latlng) {
return L.circleMarker(latlng, {
radius: 30,
fillColor: '#000',
fillOpacity: 0.1,
color: '#000',
weight: 2
});
}
})
.addTo(map);
// get the triangulated version of the current data
xhr({ uri: basePath + 'tin', json: true }, function(err, res, body) {
L.geoJson(body, {
style: function(feature) {
return {
weight: 2,
opacity: 1,
fillOpacity: 0.3,
color: '#eee',
fillColor: feature.properties.fill
};
}
}).addTo(map);
});
// get the raw data
xhr({ uri: basePath + 'points', json: true }, function(err, res, body) {
var pointLayer = L.mapbox.featureLayer(body).addTo(map);
if (body && body.features && body.features.length > 3) {
map.fitBounds(pointLayer.getBounds());
}
});
if (err) console.error(err);
});
});