-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (40 loc) · 1.25 KB
/
app.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
var L = require('leaflet');
L.Icon.Default.imagePath = 'leaflet/images'
var map = L.map('map') //
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',
{
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
map.locate({
setView: true,
maxZoom: 16,
watch: true,
enableHighAccuracy: true
});
function debug(obj) {
var div = document.createElement("div");
var content = document.createTextNode(
JSON.stringify(JSON.decycle(obj)));
div.appendChild(content); //add the text node to the newly created div.
document.body.appendChild(div);
}
function onLocationFound(e) {
var radius = e.accuracy / 2;
L.marker(e.latlng).addTo(map)
.bindPopup("You are within " + radius + " meters from this point").openPopup();
L.circle(e.latlng, radius).addTo(map);
sendPost(e);
}
function onLocationError(e) {
map.setView([-31.6333, -60.7], 12);
}
function sendPost(e){
var position = new XMLHttpRequest();
var formData = new FormData();
formData.append('Lat', e.latlng.lat);
formData.append('Lng', e.latlng.lng);
position.open('post', 'https://escolares.herokuapp.com/');
position.send(formData);
}