-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeolocation.js
63 lines (55 loc) · 2.25 KB
/
geolocation.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
var geolatitude, geolongitude;
var map= {};
hub.listen("page loaded", function() {
if (navigator.geolocation) {
var position = navigator.geolocation.getCurrentPosition(function(position) {
// hub.emit("coords recieved", position.coords);
geolatitude = position.coords.latitude;
geolongitude = position.coords.longitude;
hub.emit("load main map");
});
}
});
hub.listen("load main map", function() {
map = L.map(('mapContainer')).setView([geolatitude, geolongitude], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 15,
id: 'msmichellegar.cc37dd7d',
accessToken: 'pk.eyJ1IjoibXNtaWNoZWxsZWdhciIsImEiOiIxZTQyNTY3Y2VmYWIxYzc4NWE2MTk0NGExZGM4MzhmZSJ9.NU0hj0msBW3p9kGKm8Jylw'
}).addTo(map);
hub.emit("main map loaded");
});
hub.listen("new clap", function (tweet) {
var marker = new L.marker([tweet.lat, tweet.lon]).addTo(map).bindPopup(tweet.message).openPopup;
});
hub.listen("coords needed", function () {
hub.emit("coords sent", geolocation.latitude, geolocation.longitude);
});
var addAllMarkers= function(markerCoords) {
// var marker = new L.marker([tweet.lat, tweet.lon]).addTo(geolocation.map).bindPopup(tweet.message).openPopup;
var markerArray = [];
markerCoords.forEach(function(element) {
markerArray.push(L.marker(element).addTo(geolocation.map));
// .bindPopup(tweet.message).openPopup);
});
var group = L.featureGroup(markerArray).addTo(geolocation.map);
geolocation.map.fitBounds(group.getBounds());
};
// removeMarker: function(x,y)
var showError= function(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.");
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.");
break;
case error.UNKNOWN_ERRORkey:
console.log("An unknown error occurred.");
break;
}
};