Permalink
Browse files

added god view

  • Loading branch information...
1 parent a535f75 commit 149e8378c36ac21c1cdde98097cc16f4a9116b1b @edhiley edhiley committed Oct 27, 2013
Showing with 112 additions and 4 deletions.
  1. +1 −0 app.js
  2. +1 −0 app/controllers/home.js
  3. +29 −0 app/controllers/location.js
  4. +78 −3 app/views/home/index.jade
  5. +3 −1 config/routes.js
View
1 app.js
@@ -21,5 +21,6 @@ var app = express();
require('./config/express')(app, config);
require('./config/routes')(app);
+
app.listen(config.port);
View
@@ -1,4 +1,5 @@
var mongoose = require('mongoose');
exports.index = function(req, res){
+ res.render('home', {title: 'express'});
};
@@ -48,6 +48,35 @@ var nearTo = function(lon1, lat1, lon2, lat2) {
return d/1000; // distance in m
};
+exports.god = function(req, res) {
+
+ var gameId = "526ca9fdc039fa2521000007";
+
+ Game.find({}, function(err, games){
+
+ Location.aggregate(
+ { $group: { _id: '$userId' , maxDate: { $max: '$date' },
+ locations: { $push: '$loc' } }}
+ //, { $sort : { name : 1 } }
+ ,
+ function(err, locations){
+ res.json({
+ games: games,
+ players: locations,
+ })
+ });
+ /*console.log(err);
+ if (err) return handleError(err);
+ console.log(res); // [ { maxAge: 98 } ]*/
+ });
+
+ /*Location.find ({ gameId: gameId },
+
+ });*/
+
+
+};
+
exports.track = function(req, res) {
var gameId = req.body.gameId;
View
@@ -1,4 +1,79 @@
-extends ../layout
+!!! 5
+html
+ head
+ title Appsassin - God View
+ meta(name='viewport', content='initial-scale=1.0, user-scalable=no')
+ meta(charset='utf-8')
+ style
+ html, body, #map-canvas {
+ height: 100%;
+ margin: 0px;
+ padding: 0px
+ }
+ script(src='https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false')
+ script(src='http://codeorigin.jquery.com/jquery-2.0.3.min.js')
+ script.
+ var map;
+ var gameCentre = new google.maps.LatLng(53.47740162040098, -2.255028915204226);
-block content
- h1 I'm using generator-express MVC!
+ function initialize() {
+ var mapOptions = {
+ zoom: 8,
+ center: gameCentre,
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ };
+ map = new google.maps.Map(document.getElementById('map-canvas'),
+ mapOptions);
+ }
+ google.maps.event.addDomListener(window, 'load', initialize);
+
+ var udpate = function(){
+ // remove all points
+
+ // draw
+
+ $.get("http://localhost:3000/god", function( gameDetails ) {
+
+ console.log(gameDetails);
+
+ gameDetails.players.forEach(
+
+ function(player) {
+ console.log(player);
+
+
+ playerLocation = player.locations[0];
+ console.log(playerLocation);
+
+ var position = new google.maps.LatLng(playerLocation[1],
+ playerLocation[0]);
+
+ var marker = new google.maps.Marker({
+ position: position,
+ map: map,
+ title: "Player"
+ });
+
+
+
+ }
+ );
+
+ });
+
+ };
+
+ setTimeout(udpate, 5000);
+
+ body
+
+ header
+
+ h1 Appsassin - God View
+
+ div.games
+ ul
+ li Game one
+ li Game two
+
+ #map-canvas
View
@@ -19,5 +19,7 @@ module.exports = function(app){
app.post('/api/v1/eliminate/:id',game.eliminate);
var location = require('../app/controllers/location');
- app.post('/api/v1/location/track', location.track)
+ app.post('/api/v1/location/track', location.track);
+
+ app.get('/god', location.god);
};

0 comments on commit 149e837

Please sign in to comment.