2020-05-21 23:43:17 +02:00
|
|
|
'use strict';
|
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
(function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
var Game = {
|
2020-05-21 23:43:17 +02:00
|
|
|
NUMBER_OF_ROUNDS: 5,
|
2020-05-20 03:19:53 +02:00
|
|
|
MAX_SCORE: 1000,
|
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
rounds: [],
|
|
|
|
scoreSum: 0,
|
2020-05-25 19:51:02 +02:00
|
|
|
panoId: null,
|
2020-05-20 03:19:53 +02:00
|
|
|
panorama: null,
|
2020-05-22 23:23:54 +02:00
|
|
|
map: null,
|
2020-05-20 03:19:53 +02:00
|
|
|
guessMarker: null,
|
2020-05-21 23:43:17 +02:00
|
|
|
adaptGuess: false,
|
2020-05-20 03:19:53 +02:00
|
|
|
googleLink: null,
|
|
|
|
|
2020-05-22 01:31:32 +02:00
|
|
|
initialize: function () {
|
2020-05-26 23:23:49 +02:00
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
2020-05-30 20:13:00 +02:00
|
|
|
document.getElementById('cover').style.visibility = 'visible';
|
2020-06-05 00:23:07 +02:00
|
|
|
document.getElementById('currentRound').innerHTML = '1/' + String(Game.NUMBER_OF_ROUNDS);
|
2020-05-25 19:51:02 +02:00
|
|
|
document.getElementById('currentScoreSum').innerHTML = '0/0';
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.setOptions({
|
2020-05-26 23:23:49 +02:00
|
|
|
draggableCursor: 'crosshair'
|
|
|
|
});
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.fitBounds(mapBounds);
|
2020-05-26 23:23:49 +02:00
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'json';
|
|
|
|
xhr.onload = function () {
|
|
|
|
if (this.response.error) {
|
|
|
|
//TODO: handle this error
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
2020-05-30 20:13:00 +02:00
|
|
|
document.getElementById('cover').style.visibility = 'hidden';
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panoId = this.response.panoId;
|
2020-05-26 23:23:49 +02:00
|
|
|
|
|
|
|
if (this.response.history) {
|
|
|
|
for (var i = 0; i < this.response.history.length; ++i) {
|
|
|
|
var round = this.response.history[i];
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.rounds.push({ position: round.position, guessPosition: round.guessPosition, realMarker: null, guessMarker: null, line: null });
|
|
|
|
Game.addRealGuessPair(round.position, round.guessPosition, true);
|
|
|
|
Game.scoreSum += round.score;
|
2020-05-22 01:31:32 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
|
|
|
|
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
|
2020-05-25 19:51:02 +02:00
|
|
|
}
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.startNewRound();
|
2020-05-26 23:23:49 +02:00
|
|
|
};
|
|
|
|
|
2020-06-05 00:59:23 +02:00
|
|
|
xhr.open('GET', '/game/' + mapId + '/newPlace.json', true);
|
2020-05-26 23:23:49 +02:00
|
|
|
xhr.send();
|
2020-05-22 01:31:32 +02:00
|
|
|
},
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
reset: function () {
|
|
|
|
if (Game.guessMarker) {
|
|
|
|
Game.guessMarker.setMap(null);
|
|
|
|
Game.guessMarker = null;
|
2020-05-30 18:05:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
for (var i = 0; i < Game.rounds.length; ++i) {
|
|
|
|
var round = Game.rounds[i];
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
if (round.realMarker && round.guessMarker && round.line) {
|
|
|
|
round.realMarker.setMap(null);
|
|
|
|
round.guessMarker.setMap(null);
|
|
|
|
round.line.setMap(null);
|
|
|
|
}
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.rounds = [];
|
|
|
|
Game.scoreSum = 0;
|
2020-05-21 23:43:17 +02:00
|
|
|
|
|
|
|
var distanceInfo = document.getElementById('distanceInfo');
|
|
|
|
distanceInfo.children[0].style.display = null;
|
|
|
|
distanceInfo.children[1].style.display = null;
|
|
|
|
var scoreInfo = document.getElementById('scoreInfo');
|
|
|
|
scoreInfo.children[0].style.display = null;
|
|
|
|
scoreInfo.children[1].style.display = null;
|
|
|
|
document.getElementById('continueButton').style.display = null;
|
|
|
|
document.getElementById('startNewGameButton').style.display = null;
|
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
document.getElementById('showGuessButton').style.visibility = null;
|
|
|
|
document.getElementById('guess').style.visibility = null;
|
|
|
|
document.getElementById('guess').classList.remove('result');
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.initialize();
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
resetRound: function () {
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('scoreBar').style.width = null;
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.rounds.length > 0) {
|
|
|
|
var lastRound = Game.rounds[Game.rounds.length - 1];
|
2020-05-22 23:22:11 +02:00
|
|
|
|
|
|
|
lastRound.realMarker.setVisible(false);
|
|
|
|
lastRound.guessMarker.setVisible(false);
|
|
|
|
lastRound.line.setVisible(false);
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 20:13:00 +02:00
|
|
|
document.getElementById('cover').style.visibility = 'hidden';
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('showGuessButton').style.visibility = null;
|
|
|
|
document.getElementById('guess').style.visibility = null;
|
2020-05-22 23:22:11 +02:00
|
|
|
document.getElementById('guess').classList.remove('result')
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.setOptions({
|
2020-05-22 23:22:11 +02:00
|
|
|
draggableCursor: 'crosshair'
|
|
|
|
});
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.fitBounds(mapBounds);
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.startNewRound();
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
startNewRound: function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.rounds.push({ position: null, guessPosition: null, realMarker: null, guessMarker: null, line: null });
|
2020-05-20 15:54:09 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.loadPano(Game.panoId);
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
handleErrorResponse: function (error) {
|
|
|
|
// for the time being we only handle the "no_session_found" error and reset the game
|
2020-05-25 19:51:02 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'json';
|
2020-05-26 23:23:49 +02:00
|
|
|
xhr.onload = function () {
|
|
|
|
mapBounds = this.response.bounds;
|
2020-05-25 19:51:02 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.reset();
|
2020-05-20 03:19:53 +02:00
|
|
|
};
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2020-06-04 00:13:32 +02:00
|
|
|
xhr.open('GET', '/game/' + mapId + '/json', true);
|
2020-05-20 03:19:53 +02:00
|
|
|
xhr.send();
|
|
|
|
},
|
|
|
|
|
2020-05-25 19:51:02 +02:00
|
|
|
loadPano: function (panoId) {
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.adaptGuess) {
|
2020-05-21 03:24:09 +02:00
|
|
|
document.getElementById('guess').classList.add('adapt');
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panorama.setPov({ heading: 0, pitch: 0 });
|
|
|
|
Game.panorama.setZoom(0);
|
|
|
|
Game.panorama.setPano(panoId);
|
2020-05-20 03:19:53 +02:00
|
|
|
},
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
evaluateGuess: function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
if (!Game.guessMarker) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var guessPosition = Game.guessMarker.getPosition().toJSON();
|
|
|
|
Game.rounds[Game.rounds.length - 1].guessPosition = guessPosition;
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
document.getElementById('guessButton').disabled = true;
|
|
|
|
if (Game.adaptGuess) {
|
2020-05-25 19:51:02 +02:00
|
|
|
document.getElementById('guess').classList.remove('adapt');
|
|
|
|
}
|
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
2020-05-30 20:13:00 +02:00
|
|
|
document.getElementById('cover').style.visibility = 'visible';
|
2020-05-22 01:31:32 +02:00
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
var data = new FormData();
|
|
|
|
data.append('lat', String(guessPosition.lat));
|
|
|
|
data.append('lng', String(guessPosition.lng));
|
|
|
|
|
2020-05-25 19:51:02 +02:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'json';
|
2020-05-26 23:23:49 +02:00
|
|
|
xhr.onload = function () {
|
|
|
|
if (this.response.error) {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.handleErrorResponse(this.response.error);
|
2020-05-26 23:23:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.guessMarker.setMap(null);
|
|
|
|
Game.guessMarker = null;
|
2020-05-22 01:31:32 +02:00
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
|
|
|
document.getElementById('guess').classList.add('result');
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.scoreSum += this.response.result.score;
|
|
|
|
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.rounds[Game.rounds.length - 1].position = this.response.result.position;
|
|
|
|
Game.addRealGuessPair(this.response.result.position, guessPosition);
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
var resultBounds = new google.maps.LatLngBounds();
|
|
|
|
resultBounds.extend(this.response.result.position);
|
|
|
|
resultBounds.extend(guessPosition);
|
2020-05-22 23:22:11 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.setOptions({
|
2020-05-26 23:23:49 +02:00
|
|
|
draggableCursor: 'grab'
|
|
|
|
});
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.fitBounds(resultBounds);
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
document.getElementById('distance').innerHTML = Util.printDistanceForHuman(this.response.result.distance);
|
|
|
|
document.getElementById('score').innerHTML = this.response.result.score;
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
var scoreBarProperties = Game.calculateScoreBarProperties(this.response.result.score, Game.MAX_SCORE);
|
2020-05-26 23:23:49 +02:00
|
|
|
var scoreBar = document.getElementById('scoreBar');
|
|
|
|
scoreBar.style.backgroundColor = scoreBarProperties.backgroundColor;
|
|
|
|
scoreBar.style.width = scoreBarProperties.width;
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.rounds.length === Game.NUMBER_OF_ROUNDS) {
|
2020-05-26 23:23:49 +02:00
|
|
|
document.getElementById('continueButton').style.display = 'none';
|
|
|
|
document.getElementById('showSummaryButton').style.display = 'block';
|
2020-05-25 19:51:02 +02:00
|
|
|
}
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panoId = this.response.panoId;
|
2020-05-25 19:51:02 +02:00
|
|
|
};
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2020-05-31 20:45:57 +02:00
|
|
|
xhr.open('POST', '/game/' + mapId + '/guess.json', true);
|
2020-05-26 23:23:49 +02:00
|
|
|
xhr.send(data);
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
2020-05-25 19:51:02 +02:00
|
|
|
addRealGuessPair: function (position, guessPosition, hidden) {
|
2020-06-05 00:23:07 +02:00
|
|
|
var round = Game.rounds[Game.rounds.length - 1];
|
2020-05-21 23:43:17 +02:00
|
|
|
|
|
|
|
round.realMarker = new google.maps.Marker({
|
2020-06-05 00:23:07 +02:00
|
|
|
map: Game.map,
|
2020-05-22 23:22:11 +02:00
|
|
|
visible: !hidden,
|
2020-05-25 19:51:02 +02:00
|
|
|
position: position,
|
2020-05-22 23:55:09 +02:00
|
|
|
title: 'Open in Google Maps',
|
2020-06-05 00:23:07 +02:00
|
|
|
zIndex: Game.rounds.length * 2,
|
2020-05-21 23:43:17 +02:00
|
|
|
clickable: true,
|
2020-06-01 20:41:46 +02:00
|
|
|
draggable: false,
|
|
|
|
icon: {
|
|
|
|
url: '/static/img/markers/marker-green.svg',
|
|
|
|
size: new google.maps.Size(24, 32),
|
|
|
|
scaledSize: new google.maps.Size(24, 32),
|
|
|
|
anchor: new google.maps.Point(12, 32)
|
|
|
|
},
|
2020-05-21 23:43:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
round.realMarker.addListener('click', function () {
|
|
|
|
window.open('https://www.google.com/maps/search/?api=1&query=' + this.getPosition().toUrlValue(), '_blank');
|
|
|
|
});
|
|
|
|
|
|
|
|
round.guessMarker = new google.maps.Marker({
|
2020-06-05 00:23:07 +02:00
|
|
|
map: Game.map,
|
2020-05-22 23:22:11 +02:00
|
|
|
visible: !hidden,
|
2020-05-21 23:43:17 +02:00
|
|
|
position: guessPosition,
|
2020-06-05 00:23:07 +02:00
|
|
|
zIndex: Game.rounds.length,
|
2020-05-21 23:43:17 +02:00
|
|
|
clickable: false,
|
|
|
|
draggable: false,
|
2020-06-01 20:41:46 +02:00
|
|
|
icon: {
|
|
|
|
url: '/static/img/markers/marker-gray-empty.svg',
|
|
|
|
size: new google.maps.Size(24, 32),
|
|
|
|
scaledSize: new google.maps.Size(24, 32),
|
|
|
|
anchor: new google.maps.Point(12, 32),
|
|
|
|
labelOrigin: new google.maps.Point(12, 14)
|
|
|
|
},
|
2020-05-21 23:43:17 +02:00
|
|
|
label: {
|
|
|
|
color: '#ffffff',
|
|
|
|
fontFamily: 'Roboto',
|
2020-06-01 20:41:46 +02:00
|
|
|
fontSize: '16px',
|
2020-05-21 23:43:17 +02:00
|
|
|
fontWeight: '500',
|
|
|
|
text: '?'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
round.line = new google.maps.Polyline({
|
2020-06-05 00:23:07 +02:00
|
|
|
map: Game.map,
|
2020-05-22 23:22:11 +02:00
|
|
|
visible: !hidden,
|
2020-05-21 23:43:17 +02:00
|
|
|
path: [
|
2020-05-25 19:51:02 +02:00
|
|
|
position,
|
2020-05-21 23:43:17 +02:00
|
|
|
guessPosition
|
|
|
|
],
|
|
|
|
geodesic: true,
|
|
|
|
strokeOpacity: 0,
|
|
|
|
icons: [{
|
|
|
|
icon: {
|
|
|
|
path: 'M 0,-1 0,1',
|
|
|
|
strokeOpacity: 1,
|
|
|
|
strokeWeight: 2,
|
|
|
|
scale: 2
|
|
|
|
},
|
|
|
|
offset: '0',
|
|
|
|
repeat: '10px'
|
|
|
|
}],
|
|
|
|
clickable: false,
|
|
|
|
draggable: false,
|
|
|
|
editable: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
calculateScoreBarProperties: function (score, maxScore) {
|
|
|
|
var percent = Math.floor((score / maxScore) * 100);
|
2020-05-20 03:19:53 +02:00
|
|
|
|
|
|
|
var color;
|
|
|
|
if (percent >= 90) {
|
|
|
|
color = '#11ca00';
|
|
|
|
} else if (percent >= 10) {
|
|
|
|
color = '#ea9000';
|
|
|
|
} else {
|
|
|
|
color = '#ca1100';
|
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
return { width: percent + '%', backgroundColor: color };
|
|
|
|
},
|
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
showSummary: function () {
|
|
|
|
var distanceInfo = document.getElementById('distanceInfo');
|
|
|
|
distanceInfo.children[0].style.display = 'none';
|
|
|
|
distanceInfo.children[1].style.display = 'block';
|
|
|
|
var scoreInfo = document.getElementById('scoreInfo');
|
|
|
|
scoreInfo.children[0].style.display = 'none';
|
|
|
|
scoreInfo.children[1].style.display = 'block';
|
|
|
|
document.getElementById('showSummaryButton').style.display = null;
|
|
|
|
document.getElementById('startNewGameButton').style.display = 'block';
|
|
|
|
|
|
|
|
var resultBounds = new google.maps.LatLngBounds();
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
for (var i = 0; i < Game.rounds.length; ++i) {
|
|
|
|
var round = Game.rounds[i];
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-01 20:41:46 +02:00
|
|
|
round.realMarker.setIcon({
|
|
|
|
url: '/static/img/markers/marker-green-empty.svg',
|
|
|
|
size: new google.maps.Size(24, 32),
|
|
|
|
scaledSize: new google.maps.Size(24, 32),
|
|
|
|
anchor: new google.maps.Point(12, 32),
|
|
|
|
labelOrigin: new google.maps.Point(12, 14)
|
|
|
|
});
|
2020-05-22 21:08:36 +02:00
|
|
|
round.realMarker.setLabel({
|
2020-06-01 20:41:46 +02:00
|
|
|
color: '#285624',
|
2020-05-22 21:08:36 +02:00
|
|
|
fontFamily: 'Roboto',
|
|
|
|
fontSize: '16px',
|
|
|
|
fontWeight: '500',
|
2020-05-24 14:47:15 +02:00
|
|
|
text: String(i + 1)
|
2020-05-22 21:08:36 +02:00
|
|
|
});
|
2020-05-21 23:43:17 +02:00
|
|
|
round.realMarker.setVisible(true);
|
|
|
|
round.guessMarker.setVisible(true);
|
|
|
|
round.line.setVisible(true);
|
|
|
|
|
2020-05-25 19:51:02 +02:00
|
|
|
resultBounds.extend(round.position);
|
2020-05-21 23:43:17 +02:00
|
|
|
resultBounds.extend(round.guessPosition);
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.fitBounds(resultBounds);
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
document.getElementById('scoreSum').innerHTML = String(Game.scoreSum);
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
var scoreBarProperties = Game.calculateScoreBarProperties(Game.scoreSum, Game.NUMBER_OF_ROUNDS * Game.MAX_SCORE);
|
2020-05-21 23:43:17 +02:00
|
|
|
var scoreBar = document.getElementById('scoreBar');
|
|
|
|
scoreBar.style.backgroundColor = scoreBarProperties.backgroundColor;
|
|
|
|
scoreBar.style.width = scoreBarProperties.width;
|
|
|
|
},
|
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
rewriteGoogleLink: function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
if (!Game.googleLink) {
|
2020-05-20 03:19:53 +02:00
|
|
|
var anchors = document.getElementById('panorama').getElementsByTagName('a');
|
|
|
|
for (var i = 0; i < anchors.length; i++) {
|
|
|
|
var a = anchors[i];
|
|
|
|
if (a.href.indexOf('maps.google.com/maps') !== -1) {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.googleLink = a;
|
2020-05-20 03:19:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
setTimeout(function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.googleLink) {
|
|
|
|
Game.googleLink.title = 'Google Maps';
|
|
|
|
Game.googleLink.href = 'https://maps.google.com/maps';
|
2020-05-22 23:32:17 +02:00
|
|
|
}
|
2020-05-20 03:19:53 +02:00
|
|
|
}, 1);
|
2020-05-19 19:01:35 +02:00
|
|
|
}
|
2020-05-20 03:19:53 +02:00
|
|
|
};
|
2020-05-19 19:01:35 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
var Util = {
|
|
|
|
printDistanceForHuman: function (distance) {
|
|
|
|
if (distance < 1000) {
|
|
|
|
return Number.parseFloat(distance).toFixed(0) + ' m';
|
|
|
|
} else if (distance < 10000) {
|
|
|
|
return Number.parseFloat(distance / 1000).toFixed(2) + ' km';
|
|
|
|
} else if (distance < 100000) {
|
|
|
|
return Number.parseFloat(distance / 1000).toFixed(1) + ' km';
|
|
|
|
} else {
|
|
|
|
return Number.parseFloat(distance / 1000).toFixed(0) + ' km';
|
2020-05-17 19:29:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-20 03:19:53 +02:00
|
|
|
};
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-21 03:24:09 +02:00
|
|
|
if (!('ontouchstart' in document.documentElement)) {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.adaptGuess = true;
|
2020-05-21 03:24:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map = new google.maps.Map(document.getElementById('map'), {
|
2020-05-17 19:29:06 +02:00
|
|
|
disableDefaultUI: true,
|
|
|
|
clickableIcons: false,
|
2020-05-22 23:22:11 +02:00
|
|
|
draggingCursor: 'grabbing'
|
2020-05-17 19:29:06 +02:00
|
|
|
});
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.addListener('click', function (e) {
|
|
|
|
if (Game.rounds[Game.rounds.length - 1].guessPosition) {
|
2020-05-22 23:22:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.guessMarker) {
|
|
|
|
Game.guessMarker.setPosition(e.latLng);
|
2020-05-17 19:29:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.guessMarker = new google.maps.Marker({
|
|
|
|
map: Game.map,
|
2020-05-17 19:29:06 +02:00
|
|
|
position: e.latLng,
|
2020-05-19 16:18:12 +02:00
|
|
|
clickable: false,
|
|
|
|
draggable: true,
|
2020-06-01 20:41:46 +02:00
|
|
|
icon: {
|
|
|
|
url: '/static/img/markers/marker-gray-empty.svg',
|
|
|
|
size: new google.maps.Size(24, 32),
|
|
|
|
scaledSize: new google.maps.Size(24, 32),
|
|
|
|
anchor: new google.maps.Point(12, 32),
|
|
|
|
labelOrigin: new google.maps.Point(12, 14)
|
|
|
|
},
|
2020-05-19 16:18:12 +02:00
|
|
|
label: {
|
|
|
|
color: '#ffffff',
|
|
|
|
fontFamily: 'Roboto',
|
2020-06-01 20:41:46 +02:00
|
|
|
fontSize: '16px',
|
2020-05-19 16:18:12 +02:00
|
|
|
fontWeight: '500',
|
|
|
|
text: '?'
|
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('guessButton').disabled = false;
|
|
|
|
});
|
2020-05-19 16:18:12 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panorama = new google.maps.StreetViewPanorama(document.getElementById('panorama'), {
|
2020-05-19 16:18:12 +02:00
|
|
|
disableDefaultUI: true,
|
|
|
|
linksControl: true,
|
2020-05-21 12:17:53 +02:00
|
|
|
showRoadLabels: false,
|
|
|
|
motionTracking: false
|
2020-05-19 16:18:12 +02:00
|
|
|
});
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panorama.addListener('position_changed', function () {
|
|
|
|
Game.rewriteGoogleLink();
|
2020-05-19 16:18:12 +02:00
|
|
|
});
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panorama.addListener('pov_changed', function () {
|
|
|
|
Game.rewriteGoogleLink();
|
2020-05-19 16:18:12 +02:00
|
|
|
});
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.initialize();
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-21 01:59:31 +02:00
|
|
|
document.getElementById('showGuessButton').onclick = function () {
|
|
|
|
this.style.visibility = 'hidden';
|
|
|
|
document.getElementById('guess').style.visibility = 'visible';
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('closeGuessButton').onclick = function () {
|
|
|
|
document.getElementById('showGuessButton').style.visibility = null;
|
|
|
|
document.getElementById('guess').style.visibility = null;
|
|
|
|
}
|
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
document.getElementById('guessButton').onclick = function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.evaluateGuess();
|
2020-05-20 03:19:53 +02:00
|
|
|
}
|
2020-05-19 16:18:12 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
document.getElementById('continueButton').onclick = function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.resetRound();
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
2020-05-19 16:18:12 +02:00
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('showSummaryButton').onclick = function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.showSummary();
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('startNewGameButton').onclick = function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.reset();
|
2020-05-20 03:19:53 +02:00
|
|
|
}
|
|
|
|
})();
|