-
Notifications
You must be signed in to change notification settings - Fork 0
/
quizmap.html
executable file
·260 lines (236 loc) · 7.12 KB
/
quizmap.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<html>
<head>
<title> Quiz Geo Map </title>
<meta charset="utf-8">
<style>
header {font-family:Georgia,"Arial",serif;
font-size: 20px;
display:block;
}
video {display: none; position:absolute;
top: 60px; right: 20px;
}
audio {display:none; position:absolute;
top:60px; right:20px;
}
canvas { position: relative;top:60px
right: 20px; }
#answer {position: relative;
font-family: Georgia,"Arial",Times,serif;
font-size: 16px;}
</style>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap"
type="text/javasript"></script>
<script type="text/javascript"
src="mediacontentquiz.js">
</script>
<script type="text/javascript"
charset="utf-8">
var listener;
var map;
var myOptions;
var ctx;
var content = [];
var answer;
var audioel;
var v;
var blatlng;
vart videotext1 = "<video id=\"XXXX\"
preload=\"auto\" controls=\"controls\"
width=\"400\"><source src=\"XXXX.mp4\"
type=\'video/mp4; codecs=\"avc1.42E01E,mp4a.40.2\"\'>";
var videotext2="<source src="XXXX.theora.ogv\"
type=\'video/ogg; codecs=\"theora,vorbis\"\'> \
<source src=\"XXXX.webmvp8.webm\" type=\'video/webm; codec=\"vp8,vorbis\"\'>";
var videotext3 = "browser does not accept the video tag.</video>";
var audiotext1= "<audio id=\"XXXX\" controls=\"controls\"
preload=\"preload\"><source src=\"XXXX.ogg\" type=\"audio/ogg\" />";
var audiotext2 = "<source src=\"XXXX.mp3\" type=\"audio/mpeg\" /> \
<source src=\"XXXX.wav\" type=\"audio/wav\" /></audio>";
var nextquestion = -1;
function init()
{
ctx = document.getElementById("canvas").getContext('2d');
answer = document.getElementById("answer");
header = document.getElementById("header");
loadcontent();
asknewquestion();
}
function asknewquestion()
{
nextquestion++;
if(nextquestion<questions.length) {
header.innerHTML = questions[nextquestion];
}
else {
header.innerHTML = "no more questions";
}
}
function loadcontent() {
var divelement;
makemap(base[0],base[1]);
var videomarkup;
var videoreference;
var audiomarkup;
var audioreference;
var imageobj;
var name;
var savedimagefilename;
for (var i = 0;i<precontent.length;i++) {
content.push(precontent[i]);
name = precontent[i][4];
switch(precontent[i][3]) {
case "video":
divelement = document.createElement("div");
divelement.style = "float:right;width:30%;";
videomarkup = videotext1+videotext2+videotext3;
videomarkup = videomarkup.replace(/XXXX/g,name);
divelement.innerHTML = videomarkup;
document.body.appendChild(divelement);
videoreference = document.getElementById(name);
content[i][4] = videoreference;
break;
case "pictureaudio":
divelement = document.createElement("div");
divelement.style = "float; \
right;width:30%;";
audiomarkup = audiotext1 + audiotext2;
audiomarkup = audiomarkup.replace(/XXXX/g,name);
divelement.innerHTML = audiomarkup;
document.body.appendChild(divelement);
audioreference = document.getElementById(name);
savedimagefilename = content[i][5];
content[i][5] = audioreference;
imageobj = new Image();
imageobj.src = savedimagefilename;
content[i][4] = imageobj;
break;
case "picture":
imageobj = new Image();
imageobj.src = precontent[i][4];
content[i][4] = imageobj;
break;
}
}
}
var rxmarker = "rx1.png";
var bxmarker = "bx2.png";
function makemap(mylat, mylong) {
var marker;
blatlng = new google.maps.LatLng(mylat, mylong);
myOptions = { zoom: zoomlevel, center:blatlng, mapTypeId:google.maps.MapTypeId.ROADMAP };
map = new google.maps.Map(document.getElementById("place"),myOptions);
marker = new google.maps.Marker({ position: blatlng, title:"center", icon:
rxmarker, map: map});
listener = google.maps.event.addListener(map, 'click', function(event) {
checkit(event.latlng);
});
}
function eraseold() {
if (v != undefined) {
v.pause();
v.style.display = "none";
}
if (audioel != undefined ) {
audioel.pause();
audioel.style.display = "none";
}
ctx.clearRect(0,0,300,300);
}
function checkit(clatlng) {
var marker;
var latlng = new google.maps.LatLng(content[nextquestion][0], \
content[nextquestion][1]);
var distance = dist(clatlng, latlnga);
eraseold();
var marker = new google.maps.Marker({position: clatlng, \
titile:"your answer", icon:bxmarker, map:map});
if (distance < maxdistance) {
switch(content[nextquestion][3]) {
case "video":
answer.innerHTML = content[nextquestion][2];
ctx.clearRect(0,0,400,400);
v = content[nextquestion][4];
v.style.display = "block";
v.currentTime = 0;
v.play();
break;
case "picture":
case "pictureaudio":
answer.innerHTML = content[nextquestion][2];
ctx.clearRect(0,0,400,400);
var img1 = content[nextquestion][4];
var iw = img1.width;
var ih = img1.height;
var aspect = iw/ih;
if (iw >= ih) {
if (iw > 400) {
tw = 400;
th = 400/aspect;
}
else {
tw = iw;
th = ih;
}
}
else {
if (ih>400) {
th = 400;
tw = 400 * aspect;
}
else {
th = ih;
tw = iw;
}
}
ctx.drawImage(img1, 0,0, iw, ih, 0, 0, tw, th);
if (content[nextquestion][3] == "picture") {
break;
}
else {
audioel = content[nextquestion[5]];
audioel.style.display = "block";
audioel.currentTime = 0;
audioel.play();
break;
}
}
asknewquestion();
}
else {
answer.innerHTML = "not close enough to answer";
}
}
function dist(point1, point2){
var R = 6371; //in km
// var R = 3959; //in miles
var lat1 = point1.lat()*Math.PI/180;
var lat2 = point2.lat()*Math.PI/180;
var lon1 = point1.lng()*Math.PI/180;
var lon2 = point2.lng()*Math.PI/180;
var d = Math.acos(Math.sin(lat1)*Math.sin(lat2) + Math.cos(lat1)*Math.cos(lat2) \
* Math.cos(lon2-lon1)) * R;
return d;
}
function giveup() {
makemap(content[nextquestion][0], content[nextquestion][1]);
//will erase questions
eraseold();
answer.innerHTML = "click at red x to finish this question";
}
</script>
</head>
<body onload="init();">
<header id="header">Click</header>
<div id="place" style="float: left; width:50%; heigh:400px"></div>
<button onclick="giveup();">Hint???</button>
<div style="float: right;width:30%;height:400px">
<div id="answer">starting location</div>
<p> </p>
<canvas id="canvas" width="400" height="400" >
">>> browser doesnt recognize <<<"
</canvas>
</div>
</body>
</html>