-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
126 lines (121 loc) · 4.68 KB
/
index.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<title>demo-lunch-spin.tk</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-07I2e+7D8p6he1SIM+1twR5TIrhUQn9+I6yjqD53JQjFiMf8EtC93ty0/5vJTZGF8aAocvHYNEDJajGdNx1IsQ==" crossorigin=""/>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/4.7.2/d3.min.js"></script>
<script src="js/d3pie.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-A7vV8IFfih/D732iSSKi20u/ooOfj/AGehOKq0f4vLT1Zr2Y+RX7C+w8A1gaSasGtRUZpF/NZgzSAu4/Gc41Lg==" crossorigin=""></script>
<script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script>
</head>
<body>
<div><i>demo-lunch-spin.tk - click to spin!</i></div>
<div><img style="position: absolute" id="spoon" src="spoon.png" onclick="spin();"/></div>
<div id="pie"></div><br>
<script src="js/move.js"></script>
<div id="mapid" style="width: 400px; height: 400px;"></div>
<script>
function spin(){
try {move('#spoon').rotate(randomNumber % 360).duration('0s').end();}
catch(err) {}
randomNumber = Math.floor((Math.random() * 5400) + 5040);
console.log(randomNumber)
console.log(randomNumber % 360)
move('#spoon').rotate(randomNumber).duration('8s').end();
window.setTimeout(function(){
//call function to bounce this marker
//change you are here marker
console.log(Math.floor((randomNumber % 360)/(360/window.pieSize)));
}, 8000);
}
function LoadMap(lat,long){
var mymap = L.map('mapid').setView([lat, long], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: '<a href="http://openstreetmap.org">OpenStreetMap</a> | ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | ' +
'<a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(mymap);
//map data
$.ajax({
url:"https://api.foursquare.com/v2/venues/explore?client_id=YLZD300C5QGEOIZFORI02YJJKWDJLF4ZUCPDOSYF240BESTN&client_secret=IVMA01VDM4HGYVTZMILRW5BUMPBWSOA3DFMRTOXABLSZRKOG&ll=" + lat + "," + long + "&v=20140806&m=foursquare&categoryId=4d4b7105d754a06374d81259&openNow=1",
success:function(data){
console.log(data.response.groups[0].items)
var nameArray = [];
var latArray = [];
var lngArray = [];
L.marker([lat,long], {title:'You are here!'}).addTo(mymap).on('click',function(e){alert(lat);});
for (var i=0; i<data.response.groups[0].items.length; i++) {
console.log(data.response.groups[0].items[i].venue.name + ";" + data.response.groups[0].items[i].venue.location.lat + ";" + data.response.groups[0].items[i].venue.location.lng)
nameArray[i] = data.response.groups[0].items[i].venue.name
latArray[i] = data.response.groups[0].items[i].venue.location.lat
lngArray[i] = data.response.groups[0].items[i].venue.location.lng
L.marker([latArray[i], lngArray[i]], {title: nameArray[i]}).addTo(mymap).on('click',function(e){alert((nameArray[i]));});
}
nameArray.sort(function() {return 0.5 - Math.random()});
pieArray = [];
for (i = 0; i < 7; i++) {
if(nameArray[i] == nameArray[-1]){break;}
obj = {label:nameArray[i], value:1}
console.log(obj);
pieArray.push(obj);
}
console.log(pieArray);
var pie = new d3pie("pie", {
size: {
canvasHeight: 400,
canvasWidth: 400
},
labels: {
inner: {
format: "none"
},
outer: {
pieDistance: 0
},
truncation: {
enabled: false
}
},
effects: {
pullOutSegmentOnClick: {
effect: "none"
}
},
data: {
content: pieArray
},
tooltips: {
enabled: true,
type: "placeholder",
string: "{label}"
}
});
console.log(pie['options']['data']['content']);
window.pieSize = pie['options']['data']['content'].length;
}
})
}
//geolocation
function showPosition(position) {
console.log(position);
LoadMap(position.coords.latitude,position.coords.longitude);
}
function errorCallback(error){
if (error.code == error.PERMISSION_DENIED) {
alert("Share location required.");
}
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition,errorCallback);
}
else {
alert("Share location required.");
}
</script>
</body>
</html>