mirror of
https://github.com/Ekokumppanit/Bicyclesim.git
synced 2026-01-26 03:04:09 +00:00
Upgrade Meteor. Use keyboard for speed input.
This commit is contained in:
1
.meteor/.gitignore
vendored
1
.meteor/.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
local
|
local
|
||||||
|
meteorite
|
||||||
|
|||||||
@@ -11,3 +11,5 @@ stylus
|
|||||||
accounts-google
|
accounts-google
|
||||||
underscore
|
underscore
|
||||||
accounts-ui
|
accounts-ui
|
||||||
|
jquery-ui
|
||||||
|
jquery-ui-bootstrap
|
||||||
|
|||||||
1
.meteor/release
Normal file
1
.meteor/release
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0.6.2.1
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
var Routes = new Meteor.Collection('routes');
|
Routes = new Meteor.Collection('routes');
|
||||||
var Points = new Meteor.Collection('points');
|
Points = new Meteor.Collection('points');
|
||||||
|
|
||||||
Routes.allow({
|
Routes.allow({
|
||||||
insert: function (userId, doc) {
|
insert: function (userId, doc) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if sim}}
|
{{#if sim}}
|
||||||
{{> sim}}
|
{{> sim}}
|
||||||
|
<div class="speedSliderContainer"><div class="speedSlider"></div></li></div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if frontpage}}
|
{{#if frontpage}}
|
||||||
{{> frontpage}}
|
{{> frontpage}}
|
||||||
@@ -165,20 +166,9 @@
|
|||||||
<ul class="speedometer">
|
<ul class="speedometer">
|
||||||
<li class="distance">{{km distance}} km</li>
|
<li class="distance">{{km distance}} km</li>
|
||||||
<li class="speed">{{kmh speed}} <sup>km</sup>/<sub>h<sub></li>
|
<li class="speed">{{kmh speed}} <sup>km</sup>/<sub>h<sub></li>
|
||||||
<li class="calories"></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="distance">
|
|
||||||
<span>{{distance}}</span> km
|
|
||||||
</template>
|
|
||||||
<template name="speed">
|
|
||||||
<span>{{speed}}</span> <sup>km</sup>/<sub>h</sub>
|
|
||||||
</template>
|
|
||||||
<template name="calories">
|
|
||||||
<span>{{calories}}</span> cal
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template name="points">
|
<template name="points">
|
||||||
<h3>Points
|
<h3>Points
|
||||||
<span><label class="checkbox inline"><input type="checkbox" id="points-autoadd" {{#if autoadd}}checked="checked"{{/if}}/>Auto add points</label></span>
|
<span><label class="checkbox inline"><input type="checkbox" id="points-autoadd" {{#if autoadd}}checked="checked"{{/if}}/>Auto add points</label></span>
|
||||||
|
|||||||
@@ -115,17 +115,16 @@ a.thumbnail
|
|||||||
height 250px
|
height 250px
|
||||||
left 0
|
left 0
|
||||||
top 0
|
top 0
|
||||||
opacity 0.8
|
opacity 0.0
|
||||||
display none
|
|
||||||
|
|
||||||
.street
|
.street
|
||||||
filter(blur(4px))
|
// filter(blur(4px))
|
||||||
|
|
||||||
.show-map
|
.show-map
|
||||||
.street
|
.street
|
||||||
filter(blur(0))
|
// filter(blur(0))
|
||||||
.map
|
.map
|
||||||
display block
|
opacity 0.8
|
||||||
|
|
||||||
.show-sidebar
|
.show-sidebar
|
||||||
.street, .map
|
.street, .map
|
||||||
@@ -138,7 +137,7 @@ a.thumbnail
|
|||||||
bottom 42px
|
bottom 42px
|
||||||
left 0
|
left 0
|
||||||
right 0
|
right 0
|
||||||
background rgba(0, 0, 0, 0.5)
|
// background rgba(0, 0, 0, 0.5)
|
||||||
padding-top 30px
|
padding-top 30px
|
||||||
overflow-y auto
|
overflow-y auto
|
||||||
|
|
||||||
@@ -186,6 +185,13 @@ ol.points
|
|||||||
font-weight bold
|
font-weight bold
|
||||||
line-height 150%
|
line-height 150%
|
||||||
|
|
||||||
|
.speedSliderContainer
|
||||||
|
position absolute
|
||||||
|
bottom 100px
|
||||||
|
right 20px
|
||||||
|
.speedSlider
|
||||||
|
height 200px
|
||||||
|
|
||||||
::-webkit-scrollbar
|
::-webkit-scrollbar
|
||||||
background transparent
|
background transparent
|
||||||
border none
|
border none
|
||||||
|
|||||||
@@ -118,14 +118,14 @@ Template.editing.owner = function () {
|
|||||||
return user.profile.name;
|
return user.profile.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
function init_edit() {
|
init_edit = function init_edit() {
|
||||||
|
|
||||||
Meteor.autorun(function () {
|
Meteor.autorun(function () {
|
||||||
if (Session.equals('page', 'edit') && Session.get('route')) {
|
if (Session.equals('page', 'edit') && Session.get('route')) {
|
||||||
debug('sivu tai route vaihtui, route: ' + Session.get('route'));
|
debug('sivu tai route vaihtui, route: ' + Session.get('route'));
|
||||||
full_clear_required = true;
|
full_clear_required = true;
|
||||||
|
|
||||||
Meteor.deps.isolate(function () {
|
Deps.nonreactive(function () {
|
||||||
var route = Routes.findOne({_id: Session.get('route')});
|
var route = Routes.findOne({_id: Session.get('route')});
|
||||||
if (route) {
|
if (route) {
|
||||||
maps.travel(route.first, {route: true});
|
maps.travel(route.first, {route: true});
|
||||||
@@ -141,7 +141,7 @@ Meteor.autosubscribe(function () {
|
|||||||
|
|
||||||
if (Session.equals('page', 'edit') && Session.get('route')) {
|
if (Session.equals('page', 'edit') && Session.get('route')) {
|
||||||
if (full_clear_required) {
|
if (full_clear_required) {
|
||||||
Meteor.deps.isolate(function () {
|
Deps.nonreactive(function () {
|
||||||
debug('full clear');
|
debug('full clear');
|
||||||
|
|
||||||
maps.lines.route.clear();
|
maps.lines.route.clear();
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ helpers = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var activateInput = function (input) {
|
activateInput = function (input) {
|
||||||
input.focus();
|
input.focus();
|
||||||
input.select();
|
input.select();
|
||||||
};
|
};
|
||||||
|
|
||||||
var okCancelEvents = function (selector, callbacks) {
|
okCancelEvents = function (selector, callbacks) {
|
||||||
var ok = callbacks.ok || function () {};
|
var ok = callbacks.ok || function () {};
|
||||||
var cancel = callbacks.cancel || function () {};
|
var cancel = callbacks.cancel || function () {};
|
||||||
|
|
||||||
@@ -38,9 +38,3 @@ var okCancelEvents = function (selector, callbacks) {
|
|||||||
};
|
};
|
||||||
return events;
|
return events;
|
||||||
};
|
};
|
||||||
|
|
||||||
// From: https://github.com/tmeasday/meteor-deps-extensions
|
|
||||||
Meteor.deps.isolate = function(fn) {
|
|
||||||
var context = new Meteor.deps.Context();
|
|
||||||
return context.run(fn);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
function maps_loaded() {
|
maps_loaded = function maps_loaded() {
|
||||||
|
|
||||||
window.markers = []; // fuu
|
window.markers = []; // fuu
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ var Maps = function () {
|
|||||||
|
|
||||||
var point = Points.findOne({_id: point_id});
|
var point = Points.findOne({_id: point_id});
|
||||||
if (point) {
|
if (point) {
|
||||||
street.setPosition(glatlng(point.latlng));
|
street.setPosition(glatlng(point.latlng));
|
||||||
map.setCenter(glatlng(point.latlng));
|
map.setCenter(glatlng(point.latlng));
|
||||||
|
|
||||||
if (point.heading) street.setPov({zoom: 1, pitch: 0, heading: point.heading});
|
if (point.heading) street.setPov({zoom: 1, pitch: 0, heading: point.heading});
|
||||||
@@ -170,7 +170,7 @@ $(document).ready(function () {
|
|||||||
init_edit();
|
init_edit();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
var script = document.createElement("script");
|
var script = document.createElement("script");
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ Meteor.startup(function () {
|
|||||||
Backbone.history.start({pushState: true});
|
Backbone.history.start({pushState: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
function init_main() {
|
init_main = function init_main() {
|
||||||
Meteor.autosubscribe(function () {
|
Meteor.autosubscribe(function () {
|
||||||
// When changing page
|
// When changing page
|
||||||
|
|
||||||
@@ -182,4 +182,4 @@ function init_main() {
|
|||||||
maps.mode('sim');
|
maps.mode('sim');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,30 +1,11 @@
|
|||||||
window.point = null;
|
window.point = null;
|
||||||
window.traveled = 0;
|
window.traveled = 0;
|
||||||
|
|
||||||
var createRingBuffer = function (length){
|
function move () {
|
||||||
var pointer = 0, buffer = [], sum = 0;
|
if (!window.point) return;
|
||||||
|
|
||||||
return {
|
// var dist = localStorage['multiplier'] * c();
|
||||||
push: function (item) {
|
var dist = localStorage['multiplier'] * 0.1 * Session.get('speed');
|
||||||
if (buffer[pointer] > 0) {
|
|
||||||
sum -= buffer[pointer];
|
|
||||||
if (sum <= 0) sum = 0;
|
|
||||||
}
|
|
||||||
buffer[pointer] = item;
|
|
||||||
sum += item;
|
|
||||||
pointer = (length + pointer + 1) % length;
|
|
||||||
},
|
|
||||||
sum: function () {
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
var revs = 0;
|
|
||||||
$(document).bind('keydown.space', function () {
|
|
||||||
revs += 1;
|
|
||||||
|
|
||||||
var dist = localStorage['multiplier'] * c();
|
|
||||||
Session.set('distance', Session.get('distance') + dist);
|
Session.set('distance', Session.get('distance') + dist);
|
||||||
window.traveled += dist;
|
window.traveled += dist;
|
||||||
|
|
||||||
@@ -39,22 +20,23 @@ $(document).bind('keydown.space', function () {
|
|||||||
window.point = next;
|
window.point = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(move, 100);
|
||||||
|
|
||||||
|
var line = '';
|
||||||
|
$(document).on('keydown', function (e) {
|
||||||
|
if (e.keyCode === 13) { // enter
|
||||||
|
if (line.length >= 1 && line[0] == 'S') {
|
||||||
|
var speed = Number(line.slice(1));
|
||||||
|
Session.set('speed', speed);
|
||||||
|
}
|
||||||
|
line = '';
|
||||||
|
} else {
|
||||||
|
line += String.fromCharCode(e.keyCode);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// function speedo() {
|
|
||||||
// speed_buffer.push(revs * c());
|
|
||||||
// revs = 0;
|
|
||||||
|
|
||||||
// Session.set('speed', speed_buffer.sum() / 5);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// setInterval(speedo, 500);
|
|
||||||
|
|
||||||
// 5sec, 2 values / sec.
|
|
||||||
var speed_buffer = createRingBuffer(5 * 2);
|
|
||||||
var speed_sum = 0;
|
|
||||||
var speed_avg = 0;
|
|
||||||
|
|
||||||
Template.sim.speed = function () {
|
Template.sim.speed = function () {
|
||||||
return Session.get('speed');
|
return Session.get('speed');
|
||||||
};
|
};
|
||||||
@@ -72,47 +54,7 @@ Template.sim.helpers({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var sock = new SockJS("http://localhost:9999/speed");
|
init_sim = function init_sim() {
|
||||||
|
|
||||||
function init_sim() {
|
|
||||||
|
|
||||||
|
|
||||||
sock.onopen = function() {
|
|
||||||
console.log('open');
|
|
||||||
};
|
|
||||||
|
|
||||||
sock.onmessage = function(e) {
|
|
||||||
if (Session.equals('page', 'sim') && window.point) {
|
|
||||||
debug('message', e.data);
|
|
||||||
|
|
||||||
var dist = parseInt(e.data, 10) * c();
|
|
||||||
speed_buffer.push(dist);
|
|
||||||
|
|
||||||
Session.set('speed', speed_buffer.sum() / 5);
|
|
||||||
|
|
||||||
Session.set('distance', Session.get('distance') + 3 * dist);
|
|
||||||
window.traveled += 3 * dist;
|
|
||||||
|
|
||||||
if (window.traveled >= window.point.distance) {
|
|
||||||
var next = Points.findOne({_id: window.point.next});
|
|
||||||
|
|
||||||
// Stay on current point if no next point exists
|
|
||||||
if (next) {
|
|
||||||
window.traveled -= next.distance;
|
|
||||||
|
|
||||||
maps.travel(next._id, {route: true});
|
|
||||||
zoom = 1;
|
|
||||||
zoom_target = 1;
|
|
||||||
window.point = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
sock.onclose = function() {
|
|
||||||
console.log('close');
|
|
||||||
};
|
|
||||||
|
|
||||||
Meteor.autosubscribe(function () {
|
Meteor.autosubscribe(function () {
|
||||||
if (Session.equals('page', 'sim')) {
|
if (Session.equals('page', 'sim')) {
|
||||||
@@ -135,7 +77,18 @@ Meteor.autosubscribe(function () {
|
|||||||
p = Points.findOne({_id: p.next});
|
p = Points.findOne({_id: p.next});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('.speedSlider').slider({
|
||||||
|
orientation: 'vertical',
|
||||||
|
range: 'min',
|
||||||
|
min: 0,
|
||||||
|
max: 22.2, // m/s
|
||||||
|
value: 0,
|
||||||
|
slide: function (event, ui) {
|
||||||
|
Session.set('speed', ui.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ if (typeof Number.prototype.toDeg == 'undefined') {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeDistance(from, to) {
|
computeDistance = function computeDistance(from, to) {
|
||||||
// Equirectangular approximation, should be enough as distances are small
|
// Equirectangular approximation, should be enough as distances are small
|
||||||
var R = 6371000; // km
|
var R = 6371000; // km
|
||||||
var x = (to[1].toRad() - from[1].toRad()) * Math.cos((from[0].toRad() + to[0].toRad()) / 2);
|
var x = (to[1].toRad() - from[1].toRad()) * Math.cos((from[0].toRad() + to[0].toRad()) / 2);
|
||||||
var y = (from[0].toRad() - to[0].toRad());
|
var y = (from[0].toRad() - to[0].toRad());
|
||||||
return Math.sqrt(x * x + y * y) * R;
|
return Math.sqrt(x * x + y * y) * R;
|
||||||
}
|
};
|
||||||
|
|
||||||
function computeInitialBearing(from, to) {
|
function computeInitialBearing(from, to) {
|
||||||
var dLat = (to[0] - from[0]).toRad();
|
var dLat = (to[0] - from[0]).toRad();
|
||||||
@@ -34,12 +34,12 @@ function computeInitialBearing(from, to) {
|
|||||||
return (Math.atan2(y, x).toDeg() + 360) % 360;
|
return (Math.atan2(y, x).toDeg() + 360) % 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeFinalBearing(from, to) {
|
computeFinalBearing = function computeFinalBearing(from, to) {
|
||||||
return (computeInitialBearing(to, from) + 180) % 360;
|
return (computeInitialBearing(to, from) + 180) % 360;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Rest are copied from: https://github.com/moshen/node-googlemaps/blob/master/lib/googlemaps.js
|
// Rest are copied from: https://github.com/moshen/node-googlemaps/blob/master/lib/googlemaps.js
|
||||||
function createEncodedPolyline(points) {
|
createEncodedPolyline = function createEncodedPolyline(points) {
|
||||||
// Dear maintainer:
|
// Dear maintainer:
|
||||||
//
|
//
|
||||||
// Once you are done trying to 'optimize' this routine,
|
// Once you are done trying to 'optimize' this routine,
|
||||||
@@ -70,7 +70,7 @@ function createEncodedPolyline(points) {
|
|||||||
encoded_points += encodeSignedNumber(dlat) + encodeSignedNumber(dlng);
|
encoded_points += encodeSignedNumber(dlat) + encodeSignedNumber(dlng);
|
||||||
}
|
}
|
||||||
return encoded_points;
|
return encoded_points;
|
||||||
}
|
};
|
||||||
|
|
||||||
function encodeNumber(num) {
|
function encodeNumber(num) {
|
||||||
var encodeString = "";
|
var encodeString = "";
|
||||||
|
|||||||
6
smart.json
Normal file
6
smart.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"packages": {
|
||||||
|
"jquery-ui": {},
|
||||||
|
"jquery-ui-bootstrap": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
smart.lock
Normal file
25
smart.lock
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"meteor": {
|
||||||
|
"git": "https://github.com/meteor/meteor.git",
|
||||||
|
"branch": "master",
|
||||||
|
"commit": "bfe4b72ebec4367eaddcdf0887fcf5e649d9dcb8"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"basePackages": {
|
||||||
|
"jquery-ui": {},
|
||||||
|
"jquery-ui-bootstrap": {}
|
||||||
|
},
|
||||||
|
"packages": {
|
||||||
|
"jquery-ui": {
|
||||||
|
"git": "https://github.com/TimHeckel/meteor-jquery-ui.git",
|
||||||
|
"tag": "v1.9.2",
|
||||||
|
"commit": "c437d45edcf1367df8d5ffa8bad2867758030bd2"
|
||||||
|
},
|
||||||
|
"jquery-ui-bootstrap": {
|
||||||
|
"git": "https://github.com/TimHeckel/meteor-jquery-ui-bootstrap.git",
|
||||||
|
"tag": "v0.1.2",
|
||||||
|
"commit": "fa742a85639307003e105898e15b631394b63509"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user