Finished implementation of webpack

master
Keith Irwin 2017-06-23 14:33:17 -04:00
parent 802b63d479
commit ea72e857f3
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
11 changed files with 477 additions and 652 deletions

View File

@ -14,6 +14,7 @@
"express-validator": "^3.1.3",
"jquery": "^3.2.1",
"kerberos": "0.0.17",
"load-google-maps-api": "^1.0.0",
"mellt": "^1.0.0",
"minifier": "^0.8.1",
"moment": "^2.12.0",
@ -55,7 +56,7 @@
"nodemon": "nodemon --ignore 'static/**/*.min.*' server.js",
"minify": "minify --template .{{filename}}.min.{{ext}} --clean static/css",
"update": "sudo n stable && sudo npm update --save && sudo npm prune",
"pack": "./node_modules/.bin/webpack --config webpack.config.js"
"build": "./node_modules/.bin/webpack --config webpack.config.js"
},
"repository": "Tracman-org/Server",
"keywords": [

File diff suppressed because one or more lines are too long

517
static/js/dist/map.js vendored
View File

@ -60,7 +60,7 @@
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 21);
/******/ return __webpack_require__(__webpack_require__.s = 23);
/******/ })
/************************************************************************/
/******/ ([
@ -100,7 +100,7 @@ module.exports = g;
* Expose `debug()` as the module.
*/
exports = module.exports = __webpack_require__(25);
exports = module.exports = __webpack_require__(27);
exports.log = log;
exports.formatArgs = formatArgs;
exports.save = save;
@ -280,7 +280,7 @@ function localstorage() {
} catch (e) {}
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(24)))
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(26)))
/***/ }),
/* 2 */
@ -290,15 +290,15 @@ function localstorage() {
* Module dependencies.
*/
var keys = __webpack_require__(35);
var keys = __webpack_require__(37);
var hasBinary = __webpack_require__(11);
var sliceBuffer = __webpack_require__(36);
var after = __webpack_require__(37);
var utf8 = __webpack_require__(38);
var sliceBuffer = __webpack_require__(38);
var after = __webpack_require__(39);
var utf8 = __webpack_require__(40);
var base64encoder;
if (global && global.ArrayBuffer) {
base64encoder = __webpack_require__(40);
base64encoder = __webpack_require__(42);
}
/**
@ -356,7 +356,7 @@ var err = { type: 'error', data: 'parser error' };
* Create a blob api even for blob builder when vendor prefixes exist
*/
var Blob = __webpack_require__(41);
var Blob = __webpack_require__(43);
/**
* Encodes a packet.
@ -962,7 +962,7 @@ module.exports = function(a, b){
var debug = __webpack_require__(1)('socket.io-parser');
var Emitter = __webpack_require__(6);
var hasBin = __webpack_require__(11);
var binary = __webpack_require__(28);
var binary = __webpack_require__(30);
var isBuf = __webpack_require__(12);
/**
@ -1531,7 +1531,7 @@ Emitter.prototype.hasListeners = function(event){
/* WEBPACK VAR INJECTION */(function(global) {// browser shim for xmlhttprequest module
var hasCORS = __webpack_require__(33);
var hasCORS = __webpack_require__(35);
module.exports = function (opts) {
var xdomain = opts.xdomain;
@ -1956,7 +1956,7 @@ module.exports = function parseuri(str) {
* Module requirements.
*/
var isArray = __webpack_require__(27);
var isArray = __webpack_require__(29);
var toString = Object.prototype.toString;
var withNativeBlob = typeof global.Blob === 'function' || toString.call(global.Blob) === '[object BlobConstructor]';
@ -2044,7 +2044,7 @@ function isBuf(obj) {
* Module dependencies.
*/
var eio = __webpack_require__(30);
var eio = __webpack_require__(32);
var Socket = __webpack_require__(18);
var Emitter = __webpack_require__(6);
var parser = __webpack_require__(5);
@ -2052,7 +2052,7 @@ var on = __webpack_require__(19);
var bind = __webpack_require__(20);
var debug = __webpack_require__(1)('socket.io-client:manager');
var indexOf = __webpack_require__(17);
var Backoff = __webpack_require__(47);
var Backoff = __webpack_require__(49);
/**
* IE6+ hasOwnProperty
@ -2623,9 +2623,9 @@ Manager.prototype.onreconnect = function () {
*/
var XMLHttpRequest = __webpack_require__(7);
var XHR = __webpack_require__(34);
var JSONP = __webpack_require__(42);
var websocket = __webpack_require__(43);
var XHR = __webpack_require__(36);
var JSONP = __webpack_require__(44);
var websocket = __webpack_require__(45);
/**
* Export transports.
@ -3026,7 +3026,7 @@ module.exports = function(arr, obj){
var parser = __webpack_require__(5);
var Emitter = __webpack_require__(6);
var toArray = __webpack_require__(46);
var toArray = __webpack_require__(48);
var on = __webpack_require__(19);
var bind = __webpack_require__(20);
var debug = __webpack_require__(1)('socket.io-client:socket');
@ -3499,57 +3499,48 @@ module.exports = function(obj, fn){
/***/ }),
/* 21 */
/* 21 */,
/* 22 */,
/* 23 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_socket_io_client__ = __webpack_require__(22);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_socket_io_client__ = __webpack_require__(24);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_socket_io_client___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_socket_io_client__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_jquery__ = __webpack_require__(48);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_jquery__ = __webpack_require__(50);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_jquery___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_jquery__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_load_google_maps_api__ = __webpack_require__(51);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_load_google_maps_api___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_load_google_maps_api__);
/* global google mapuser userid disp noHeader */
/* global mapuser userid disp noHeader mapKey */
// Webpack imports
// Variables
var map, pano, marker, elevator, newLoc;
const mapElem = document.getElementById('map'),
panoElem = document.getElementById('pano'),
socket = __WEBPACK_IMPORTED_MODULE_0_socket_io_client___default.a('//'+window.location.hostname);
function waitForElements(vars,cb){
if ( vars.every(function(v){ return v!==undefined; }) ){
cb();
} else {
setTimeout(waitForElements(vars,cb), 100);
}
}
function onConnect(socket,userid,mapuserid) {
// Can get location
socket.emit('can-get', mapuserid );
console.log("🚹 Receiving updates for",mapuserid);
// Can set location too
if (mapuserid===userid) {
socket.emit('can-set', userid );
console.log("🚹 Sending updates for",userid);
}
}
// socket.io stuff
socket
.on('connect', function(){
console.log("⬆️ Connected!");
waitForElements([mapuser,userid], function() {
onConnect(socket,userid,mapuser._id);
});
// Can get location
socket.emit('can-get', mapuser._id );
console.log("🚹 Receiving updates for",mapuser._id);
// Can set location too
if (mapuser._id===userid) {
socket.emit('can-set', userid );
console.log("🚹 Sending updates for",userid);
}
})
.on('disconnect', function(){
console.log("⬇️ Disconnected!");
@ -3558,17 +3549,6 @@ socket
console.error('❌️',err.message);
});
// Parse location
function parseLoc(loc) {
loc.spd = (mapuser.settings.units=='standard')?parseFloat(loc.spd)*2.23694:parseFloat(loc.spd);
loc.dir = parseFloat(loc.dir);
loc.lat = parseFloat(loc.lat);
loc.lon = parseFloat(loc.lon);
loc.tim = new Date(loc.tim).toLocaleString();
loc.glatlng = new google.maps.LatLng(loc.lat, loc.lon);
return loc;
}
// Show/hide map if location is set/unset
function toggleMaps(loc) {
if (loc.lat===0&&loc.lon===0) {
@ -3587,28 +3567,26 @@ __WEBPACK_IMPORTED_MODULE_1_jquery___default.a(function() {
toggleMaps(mapuser.last);
});
// Google maps API callback
window.gmapsCb = function() {
//console.log("gmapsCb() called");
// Load google maps
__WEBPACK_IMPORTED_MODULE_2_load_google_maps_api___default.a({ key:mapKey })
.then(function(googlemaps) {
//console.log("Loaded google maps:",googlemaps);
// Make sure everything's ready...
waitForElements([mapuser,disp,noHeader], function() {
// Create map
if (disp!=='1') {
//console.log("Creating map...");
map = new google.maps.Map( mapElem, {
center: new google.maps.LatLng( mapuser.last.lat, mapuser.last.lon ),
map = new googlemaps.Map( mapElem, {
center: new googlemaps.LatLng( mapuser.last.lat, mapuser.last.lon ),
panControl: false,
scaleControl: mapuser.settings.showScale,
draggable: false,
zoom: mapuser.settings.defaultZoom,
streetViewControl: false,
zoomControlOptions: {position: google.maps.ControlPosition.LEFT_TOP},
mapTypeId: (mapuser.settings.defaultMap=='road')?google.maps.MapTypeId.ROADMAP:google.maps.MapTypeId.HYBRID
zoomControlOptions: {position: googlemaps.ControlPosition.LEFT_TOP},
mapTypeId: (mapuser.settings.defaultMap=='road')?googlemaps.MapTypeId.ROADMAP:googlemaps.MapTypeId.HYBRID
});
marker = new google.maps.Marker({
marker = new googlemaps.Marker({
position: { lat:mapuser.last.lat, lng:mapuser.last.lon },
title: mapuser.name,
map: map,
@ -3626,7 +3604,7 @@ window.gmapsCb = function() {
logoDiv.innerHTML = '<a href="https://tracman.org/">'+
'<img src="https://tracman.org/static/img/style/logo-28.png" alt="[]">'+
"<span class='text'>Tracman</span></a>";
map.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(logoDiv);
map.controls[googlemaps.ControlPosition.BOTTOM_LEFT].push(logoDiv);
}
// Create update time block
@ -3636,7 +3614,7 @@ window.gmapsCb = function() {
if (mapuser.last.time) {
timeDiv.innerHTML = 'location updated '+new Date(mapuser.last.time).toLocaleString();
}
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(timeDiv);
map.controls[googlemaps.ControlPosition.RIGHT_BOTTOM].push(timeDiv);
// Create speed block
if (mapuser.settings.showSpeed) {
@ -3655,13 +3633,13 @@ window.gmapsCb = function() {
speedSign.appendChild(speedLabel);
speedSign.appendChild(speedText);
speedSign.appendChild(speedUnit);
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(speedSign);
map.controls[googlemaps.ControlPosition.TOP_RIGHT].push(speedSign);
}
// Create altitude block
if (mapuser.settings.showAlt) {
//console.log("Creating altitude sign...");
const elevator = new google.maps.ElevationService,
const elevator = new googlemaps.ElevationService,
altitudeSign = document.createElement('div'),
altitudeLabel = document.createElement('div'),
altitudeText = document.createElement('div'),
@ -3672,14 +3650,14 @@ window.gmapsCb = function() {
altitudeSign.id = 'alt-sign';
altitudeText.innerHTML = '';
altitudeLabel.innerHTML = 'ALTITUDE';
getAltitude(new google.maps.LatLng(mapuser.last.lat,mapuser.last.lon), elevator, function(alt) {
getAltitude(new googlemaps.LatLng(mapuser.last.lat,mapuser.last.lon), elevator, function(alt) {
if (alt) { altitudeText.innerHTML = (mapuser.settings.units=='standard')?(alt*3.28084).toFixed():alt.toFixed(); }
});
altitudeUnit.innerHTML = (mapuser.settings.units=='standard')?'feet':'meters';
altitudeSign.appendChild(altitudeLabel);
altitudeSign.appendChild(altitudeText);
altitudeSign.appendChild(altitudeUnit);
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(altitudeSign);
map.controls[googlemaps.ControlPosition.TOP_RIGHT].push(altitudeSign);
}
}
@ -3689,148 +3667,159 @@ window.gmapsCb = function() {
//console.log("Creating streetview...");
updateStreetView(parseLoc(mapuser.last),10);
}
});
};
// Got location
socket.on('get', function(loc) {
console.log("🌐️ Got location:",loc.lat+", "+loc.lon);
// Parse location
newLoc = parseLoc(loc);
function parseLoc(loc) {
loc.spd = (mapuser.settings.units=='standard')?parseFloat(loc.spd)*2.23694:parseFloat(loc.spd);
loc.dir = parseFloat(loc.dir);
loc.lat = parseFloat(loc.lat);
loc.lon = parseFloat(loc.lon);
loc.tim = new Date(loc.tim).toLocaleString();
loc.glatlng = new googlemaps.LatLng(loc.lat, loc.lon);
return loc;
}
// Got location
socket.on('get', function(loc) {
console.log("🌐️ Got location:",loc.lat+", "+loc.lon);
// Update map
if (disp!=='1') {
// Update time
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#timestamp').text('location updated '+newLoc.tim);
// Update marker and map center
google.maps.event.trigger(map,'resize');
map.setCenter({ lat:newLoc.lat, lng:newLoc.lon });
marker.setPosition({ lat:newLoc.lat, lng:newLoc.lon });
// Update speed
if (mapuser.settings.showSpeed) {
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#spd').text( newLoc.spd.toFixed() );
}
// Parse location
newLoc = parseLoc(loc);
// Update altitude
if (mapuser.settings.showAlt) {
getAltitude({
lat: newLoc.lat,
lng: newLoc.lon
}, elevator, function(alt) {
if (alt) {
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#alt').text( (mapuser.settings.units=='standard')?(alt*3.28084).toFixed():alt.toFixed() );
// Update map
if (disp!=='1') {
// Update time
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#timestamp').text('location updated '+newLoc.tim);
// Update marker and map center
googlemaps.event.trigger(map,'resize');
map.setCenter({ lat:newLoc.lat, lng:newLoc.lon });
marker.setPosition({ lat:newLoc.lat, lng:newLoc.lon });
// Update speed
if (mapuser.settings.showSpeed) {
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#spd').text( newLoc.spd.toFixed() );
}
// Update altitude
if (mapuser.settings.showAlt) {
getAltitude({
lat: newLoc.lat,
lng: newLoc.lon
}, elevator, function(alt) {
if (alt) {
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#alt').text( (mapuser.settings.units=='standard')?(alt*3.28084).toFixed():alt.toFixed() );
}
});
}
}
// Update street view
if (disp!=='0' && mapuser.settings.showStreetview) {
updateStreetView(newLoc,10);
}
});
// Check altitude
function getAltitude(loc,elev,cb){
//console.log("Getting altitude...");
elev = elev || new googlemaps.ElevationService;
elev.getElevationForLocations({
'locations': [loc]
}, function(results, status) {
if (status === googlemaps.ElevationStatus.OK && results[0]) {
cb(results[0].elevation);
}
});
}
// Get street view imagery
function getStreetViewData(loc,rad,cb) {
// Ensure that the location hasn't changed
if (loc===newLoc) {
if (!sv) { var sv=new googlemaps.StreetViewService(); }
sv.getPanorama({
location: {
lat: loc.lat,
lng: loc.lon
},
radius: rad
}, function(data,status){ switch (status){
// Success
case googlemaps.StreetViewStatus.OK:
cb(data);
break;
// No results in that radius
case googlemaps.StreetViewStatus.ZERO_RESULTS:
// Try again with a bigger radius
getStreetViewData(loc,rad*2,cb);
break;
// Error
default:
console.error(new Error('❌️ Street view not available: '+status).message);
} });
} else { console.log('loc!==newLoc'); }
}
// Update streetview
function updateStreetView(loc) {
//console.log("Updating streetview...");
// Moving (show stationary image)
if (loc.spd>1) {
const imgElem = document.getElementById('panoImg');
getStreetViewData(loc, 2, function(data){
if (!imgElem) {
// Create image
pano = undefined;
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').empty();
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').append(__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('<img>',{
alt: 'Street view image',
src: 'https://maps.googleapis.com/maps/api/streetview?size=800x800&location='+loc.lat+','+loc.lon+'&fov=90&heading='+loc.dir+'&key={{api}}',
id: 'panoImg'
}));
}
// Set image
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#panoImg').attr('src','https://maps.googleapis.com/maps/api/streetview?size='+__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').width()+'x'+__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').height()+'&location='+data.location.latLng.lat()+','+data.location.latLng.lng()+'&fov=90&heading='+loc.dir+'&key={{api}}');
});
}
// Not moving and pano not set (create panoramic image)
else if (pano==null) {
getStreetViewData(loc, 2, function(data){
// Create panorama
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').empty();
const panoOptions = {
panControl: false,
zoomControl: false,
addressControl: false,
linksControl: false,
motionTracking: false,
motionTrackingControl: false
};
pano = new googlemaps.StreetViewPanorama(panoElem, panoOptions);
// Set panorama
pano.setPano(data.location.pano);
pano.setPov({
pitch: 0,
// Point towards users's location from street
heading: Math.atan((loc.lon-data.location.latLng.lng())/(loc.lat-data.location.latLng.lat()))*(180/Math.PI)
});
});
}
}
// Update street view
if (disp!=='0' && mapuser.settings.showStreetview) {
updateStreetView(newLoc,10);
}
}).catch((err) => {
console.error(err);
});
// Check altitude
function getAltitude(loc,elev,cb){
//console.log("Getting altitude...");
elev = elev || new google.maps.ElevationService;
elev.getElevationForLocations({
'locations': [loc]
}, function(results, status) {
if (status === google.maps.ElevationStatus.OK && results[0]) {
cb(results[0].elevation);
}
});
}
// Get street view imagery
function getStreetViewData(loc,rad,cb) {
// Ensure that the location hasn't changed
if (loc===newLoc) {
if (!sv) { var sv=new google.maps.StreetViewService(); }
sv.getPanorama({
location: {
lat: loc.lat,
lng: loc.lon
},
radius: rad
}, function(data,status){ switch (status){
// Success
case google.maps.StreetViewStatus.OK:
cb(data);
break;
// No results in that radius
case google.maps.StreetViewStatus.ZERO_RESULTS:
// Try again with a bigger radius
getStreetViewData(loc,rad*2,cb);
break;
// Error
default:
console.error(new Error('❌️ Street view not available: '+status).message);
} });
} else { console.log('loc!==newLoc'); }
}
// Update streetview
function updateStreetView(loc) {
//console.log("Updating streetview...");
// Moving (show stationary image)
if (loc.spd>1) {
const imgElem = document.getElementById('panoImg');
getStreetViewData(loc, 2, function(data){
if (!imgElem) {
// Create image
pano = undefined;
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').empty();
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').append(__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('<img>',{
alt: 'Street view image',
src: 'https://maps.googleapis.com/maps/api/streetview?size=800x800&location='+loc.lat+','+loc.lon+'&fov=90&heading='+loc.dir+'&key={{api}}',
id: 'panoImg'
}));
}
// Set image
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#panoImg').attr('src','https://maps.googleapis.com/maps/api/streetview?size='+__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').width()+'x'+__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').height()+'&location='+data.location.latLng.lat()+','+data.location.latLng.lng()+'&fov=90&heading='+loc.dir+'&key={{api}}');
});
}
// Not moving and pano not set (create panoramic image)
else if (pano==null) {
getStreetViewData(loc, 2, function(data){
// Create panorama
__WEBPACK_IMPORTED_MODULE_1_jquery___default.a('#pano').empty();
const panoOptions = {
panControl: false,
zoomControl: false,
addressControl: false,
linksControl: false,
motionTracking: false,
motionTrackingControl: false
};
pano = new google.maps.StreetViewPanorama(panoElem, panoOptions);
// Set panorama
pano.setPano(data.location.pano);
pano.setPov({
pitch: 0,
// Point towards users's location from street
heading: Math.atan((loc.lon-data.location.latLng.lng())/(loc.lat-data.location.latLng.lat()))*(180/Math.PI)
});
});
}
}
/***/ }),
/* 22 */
/* 24 */
/***/ (function(module, exports, __webpack_require__) {
@ -3838,7 +3827,7 @@ function updateStreetView(loc) {
* Module dependencies.
*/
var url = __webpack_require__(23);
var url = __webpack_require__(25);
var parser = __webpack_require__(5);
var Manager = __webpack_require__(13);
var debug = __webpack_require__(1)('socket.io-client');
@ -3930,7 +3919,7 @@ exports.Socket = __webpack_require__(18);
/***/ }),
/* 23 */
/* 25 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {
@ -4012,7 +4001,7 @@ function url (uri, loc) {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 24 */
/* 26 */
/***/ (function(module, exports) {
// shim for using process in browser
@ -4202,7 +4191,7 @@ process.umask = function() { return 0; };
/***/ }),
/* 25 */
/* 27 */
/***/ (function(module, exports, __webpack_require__) {
@ -4218,7 +4207,7 @@ exports.coerce = coerce;
exports.disable = disable;
exports.enable = enable;
exports.enabled = enabled;
exports.humanize = __webpack_require__(26);
exports.humanize = __webpack_require__(28);
/**
* The currently active debug mode names, and names to skip.
@ -4410,7 +4399,7 @@ function coerce(val) {
/***/ }),
/* 26 */
/* 28 */
/***/ (function(module, exports) {
/**
@ -4565,7 +4554,7 @@ function plural(ms, n, name) {
/***/ }),
/* 27 */
/* 29 */
/***/ (function(module, exports) {
var toString = {}.toString;
@ -4576,7 +4565,7 @@ module.exports = Array.isArray || function (arr) {
/***/ }),
/* 28 */
/* 30 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {/*global Blob,File*/
@ -4585,7 +4574,7 @@ module.exports = Array.isArray || function (arr) {
* Module requirements
*/
var isArray = __webpack_require__(29);
var isArray = __webpack_require__(31);
var isBuf = __webpack_require__(12);
var toString = Object.prototype.toString;
var withNativeBlob = typeof global.Blob === 'function' || toString.call(global.Blob) === '[object BlobConstructor]';
@ -4724,7 +4713,7 @@ exports.removeBlobs = function(data, callback) {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 29 */
/* 31 */
/***/ (function(module, exports) {
var toString = {}.toString;
@ -4735,19 +4724,19 @@ module.exports = Array.isArray || function (arr) {
/***/ }),
/* 30 */
/* 32 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(31);
module.exports = __webpack_require__(33);
/***/ }),
/* 31 */
/* 33 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(32);
module.exports = __webpack_require__(34);
/**
* Exports parser
@ -4759,7 +4748,7 @@ module.exports.parser = __webpack_require__(2);
/***/ }),
/* 32 */
/* 34 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {/**
@ -4772,7 +4761,7 @@ var debug = __webpack_require__(1)('engine.io-client:socket');
var index = __webpack_require__(17);
var parser = __webpack_require__(2);
var parseuri = __webpack_require__(10);
var parsejson = __webpack_require__(45);
var parsejson = __webpack_require__(47);
var parseqs = __webpack_require__(3);
/**
@ -5510,7 +5499,7 @@ Socket.prototype.filterUpgrades = function (upgrades) {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 33 */
/* 35 */
/***/ (function(module, exports) {
@ -5533,7 +5522,7 @@ try {
/***/ }),
/* 34 */
/* 36 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {/**
@ -5953,7 +5942,7 @@ function unloadHandler () {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 35 */
/* 37 */
/***/ (function(module, exports) {
@ -5978,7 +5967,7 @@ module.exports = Object.keys || function keys (obj){
/***/ }),
/* 36 */
/* 38 */
/***/ (function(module, exports) {
/**
@ -6013,7 +6002,7 @@ module.exports = function(arraybuffer, start, end) {
/***/ }),
/* 37 */
/* 39 */
/***/ (function(module, exports) {
module.exports = after
@ -6047,7 +6036,7 @@ function noop() {}
/***/ }),
/* 38 */
/* 40 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module, global) {var __WEBPACK_AMD_DEFINE_RESULT__;/*! https://mths.be/utf8js v2.1.2 by @mathias */
@ -6305,10 +6294,10 @@ function noop() {}
}(this));
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(39)(module), __webpack_require__(0)))
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(41)(module), __webpack_require__(0)))
/***/ }),
/* 39 */
/* 41 */
/***/ (function(module, exports) {
module.exports = function(module) {
@ -6336,7 +6325,7 @@ module.exports = function(module) {
/***/ }),
/* 40 */
/* 42 */
/***/ (function(module, exports) {
/*
@ -6409,7 +6398,7 @@ module.exports = function(module) {
/***/ }),
/* 41 */
/* 43 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {/**
@ -6512,7 +6501,7 @@ module.exports = (function() {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 42 */
/* 44 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {
@ -6750,7 +6739,7 @@ JSONPPolling.prototype.doWrite = function (data, fn) {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 43 */
/* 45 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {/**
@ -6767,7 +6756,7 @@ var BrowserWebSocket = global.WebSocket || global.MozWebSocket;
var NodeWebSocket;
if (typeof window === 'undefined') {
try {
NodeWebSocket = __webpack_require__(44);
NodeWebSocket = __webpack_require__(46);
} catch (e) { }
}
@ -7043,13 +7032,13 @@ WS.prototype.check = function () {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 44 */
/* 46 */
/***/ (function(module, exports) {
/* (ignored) */
/***/ }),
/* 45 */
/* 47 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {/**
@ -7087,7 +7076,7 @@ module.exports = function parsejson(data) {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 46 */
/* 48 */
/***/ (function(module, exports) {
module.exports = toArray
@ -7106,7 +7095,7 @@ function toArray(list, index) {
/***/ }),
/* 47 */
/* 49 */
/***/ (function(module, exports) {
@ -7197,7 +7186,7 @@ Backoff.prototype.setJitter = function(jitter){
/***/ }),
/* 48 */
/* 50 */
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
@ -17456,5 +17445,59 @@ return jQuery;
} );
/***/ }),
/* 51 */
/***/ (function(module, exports) {
var CALLBACK_NAME = '__googleMapsApiOnLoadCallback'
var OPTIONS_KEYS = ['client', 'key', 'language', 'region', 'v']
module.exports = function(options) {
options = options || {}
return new Promise(function(resolve, reject) {
// Exit if not running inside a browser.
if (typeof window === 'undefined') {
return reject(
new Error('Can only load the Google Maps API in the browser')
)
}
// Reject the promise after a timeout.
var timeoutId = setTimeout(function() {
window[CALLBACK_NAME] = function() {} // Set the on load callback to a no-op.
reject(new Error('Could not load the Google Maps API'))
}, options.timeout || 10000)
// Hook up the on load callback.
window[CALLBACK_NAME] = function() {
if (timeoutId !== null) {
clearTimeout(timeoutId)
}
resolve(window.google.maps)
delete window[CALLBACK_NAME]
}
// Prepare the `script` tag to be inserted into the page.
var scriptElement = document.createElement('script')
var params = ['callback=' + CALLBACK_NAME]
OPTIONS_KEYS.forEach(function(key) {
if (options[key]) {
params.push(key + '=' + options[key])
}
})
if (options.libraries && options.libraries.length) {
params.push('libraries=' + options.libraries.join(','))
}
scriptElement.src =
'https://maps.googleapis.com/maps/api/js?' + params.join('&')
// Insert the `script` tag.
document.body.appendChild(scriptElement)
})
}
/***/ })
/******/ ]);

View File

@ -1,209 +0,0 @@
'use strict';
/**
* Mellt
*
* Tests the strength of a password by calculating how long it would take to
* brute force it.
*
* @version 0.1.0
* @link http://mel.lt/ The homepage for this script.
* @link http://www.hammerofgod.com/passwordcheck.aspx Much of this is based
* on the description of Thor's Godly Privacy password strength checker,
* however the actual code below is all my own.
* @link http://xato.net/passwords/more-top-worst-passwords/ The included
* common passwords list is from Mark Burnett's password collection (which
* is excellent). You can of course use your own password file instead.
*/
var Mellt = function() {
/**
* @var integer HashesPerSecond The number of attempts per second you expect
* an attacker to be able to attempt. Set to 1 billion by default.
*/
this.HashesPerSecond = 1000000000;
/**
* @var string CommonPasswords A variable containing an array of common
* passwords to check against. If you include common-passwords.js in your
* HTML after including Mellt.js, the contents of that file will be used
* if this isn't set.
* Set this to null (and don't include common-passwords.js) to skip
* checking common passwords.
*/
this.CommonPasswords = null;
/**
* @var array $CharacterSets An array of strings, each string containing a
* character set. These should proceed in the order of simplest (0-9) to most
* complex (all characters). More complex = more characters.
*/
this.CharacterSets = [
// We're making some guesses here about human nature (again much of this is
// based on the TGP password strength checker, and Timothy "Thor" Mullen
// deserves the credit for the thinking behind this). Basically we're combining
// what we know about users (SHIFT+numbers are more common than other
// punctuation for example) combined with how an attacker will attack a
// password (most common letters first, expanding outwards).
//
// If you want to support passwords that use non-english characters, and
// your attacker knows this (for example, a Russian site would be expected
// to contain passwords in Russian characters) add your characters to one of
// the sets below, or create new sets and insert them in the right places.
"0123456789",
"abcdefghijklmnopqrstuvwxyz",
"abcdefghijklmnopqrstuvwxyz0123456789",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-=_+",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-=_+[]\"{}|;':,./<>?`~"
];
};
Mellt.prototype = {
CommonPasswords: null,
/**
* Tests password strength by simulating how long it would take a cracker to
* brute force your password.
*
* Also optionally tests against a list of common passwords (contained in an
* external file) to weed out things like "password", which from a pure brute
* force perspective would be harder to break if it wasn't so common.
*
* The character sets being used in this checker assume English (ASCII)
* characters (no umlauts for example). If you run a non-english site, and you
* suspect the crackers will realize this, you may want to modify the
* character set to include the characters in your language.
*
* @param string $password The password to test the strength of
* @return integer Returns an integer specifying how many days it would take
* to brute force the password (at 1 billion checks a second) or -1 to
* indicate the password was found in the common passwords file. Obviously if
* they don't have direct access to the hashed passwords this time would be
* longer, and even then most computers (at the time of this writing) won't be
* able to test 1 billion hashes a second, but this function measures worst
* case scenario, so... I would recommend you require at least 30 days to brute
* force a password, obviously more if you're a bank or other secure system.
* @throws Exception If an error is encountered.
*/
CheckPassword: function(password) {
// First check passwords in the common password file if available.
// We do this because "password" takes 129 seconds, but is the first
// thing an attacker will try.
if (!this.CommonPasswords && Mellt.prototype.CommonPasswords) {
this.CommonPasswords = Mellt.prototype.CommonPasswords;
}
if (this.CommonPasswords) {
var text = password.toLowerCase();
for (var t=0; t<this.CommonPasswords.length; t++) {
if (this.CommonPasswords[t]==text) {
// If their password exists in the common file, then it's
// zero time to crack this terrible password.
return -1;
}
}
}
// Figure out which character set the password is using (based on the most
// "complex" character in it).
var base = '';
var baseKey = null;
for (var t=0; t<password.length; t++) {
var char = password[t];
var foundChar = false;
for (var characterSetKey=0; characterSetKey<this.CharacterSets.length; characterSetKey++) {
var characterSet = this.CharacterSets[characterSetKey];
if (baseKey<=characterSetKey && characterSet.indexOf(char)>-1) {
baseKey = characterSetKey;
base = characterSet;
foundChar = true;
break;
}
}
// If the character we were looking for wasn't anywhere in any of the
// character sets, assign the largest (last) character set as default.
if (!foundChar) {
base = this.CharacterSets[this.CharacterSets.length-1];
break;
}
}
// Starting at the first character, figure out it's position in the character set
// and how many attempts will take to get there. For example, say your password
// was an integer (a bank card PIN number for example):
// 0 (or 0000 if you prefer) would be the very first password they attempted by the attacker.
// 9999 would be the last password they attempted (assuming 4 characters).
// Thus a password/PIN of 6529 would take 6529 attempts until the attacker found
// the proper combination. The same logic words for alphanumeric passwords, just
// with a larger number of possibilities for each position in the password. The
// key thing to note is the attacker doesn't need to test the entire range (every
// possible combination of all characters) they just need to get to the point in
// the list of possibilities that is your password. They can (in this example)
// ignore anything between 6530 and 9999. Using this logic, 'aaa' would be a worse
// password than 'zzz', because the attacker would encounter 'aaa' first.
var attempts = 0;
var charactersInBase = base.length;
var charactersInPassword = password.length;
for (var position=0; position<charactersInPassword; position++) {
// We power up to the reverse position in the string. For example, if we're trying
// to hack the 4 character PING code in the example above:
// First number * (number of characters possible in the charset ^ length of password)
// ie: 6 * (10^4) = 6000
// then add that same equation for the second number:
// 5 * (10^3) = 500
// then the third numbers
// 2 * (10^2) = 20
// and add on the last number
// 9
// Totals: 6000 + 500 + 20 + 9 = 6529 attempts before we encounter the correct password.
var powerOf = charactersInPassword - position - 1;
// Character position within the base set. We add one on because strpos is base
// 0, we want base 1.
var charAtPosition = base.indexOf(password[position])+1;
// If we're at the last character, simply add it's position in the character set
// this would be the "9" in the pin code example above.
if (powerOf==0) {
attempts = attempts + charAtPosition;
}
// Otherwise we need to iterate through all the other characters positions to
// get here. For example, to find the 5 in 25 we can't just guess 2 and then 5
// (even though Hollywood seems to insist this is possible), we need to try 0,1,
// 2,3...15,16,17...23,24,25 (got it).
else {
// This means we have to try every combination of values up to this point for
// all previous characters. Which means we need to iterate through the entire
// character set, X times, where X is our position -1. Then we need to multiply
// that by this character's position.
// Multiplier is the (10^4) or (10^3), etc in the pin code example above.
var multiplier = Math.pow(charactersInBase,powerOf);
// New attempts is the number of attempts we're adding for this position.
var newAttempts = charAtPosition * multiplier;
// Add that on to our existing number of attempts.
attempts = attempts + newAttempts;
}
}
// We can (worst case) try a billion passwords a second. Calculate how many days it
// will take us to get to the password.
var perDay = this.HashesPerSecond*60*60*24;
// This allows us to calculate a number of days to crack. We use days because anything
// that can be cracked in less than a day is basically useless, so there's no point in
// having a smaller granularity (hours for example).
var days = attempts / perDay;
// If it's going to take more than a billion days to crack, just return a billion. This
// helps when code outside this function isn't using bcmath. Besides, if the password
// can survive 2.7 million years it's probably ok.
if (days>1000000000) {
return 1000000000;
}
return Math.round(days);
}
};

View File

@ -1,10 +1,10 @@
'use strict';
/* global mapuser userid disp noHeader */
/* global mapuser userid disp noHeader mapKey */
// Webpack imports
import io from 'socket.io-client';
import $ from 'jquery';
import google from 'google';
import loadGoogleMapsAPI from 'load-google-maps-api';
// Variables
var map, pano, marker, elevator, newLoc;
@ -12,35 +12,21 @@ const mapElem = document.getElementById('map'),
panoElem = document.getElementById('pano'),
socket = io('//'+window.location.hostname);
function waitForElements(vars,cb){
if ( vars.every(function(v){ return v!==undefined; }) ){
cb();
} else {
setTimeout(waitForElements(vars,cb), 100);
}
}
function onConnect(socket,userid,mapuserid) {
// Can get location
socket.emit('can-get', mapuserid );
console.log("🚹 Receiving updates for",mapuserid);
// Can set location too
if (mapuserid===userid) {
socket.emit('can-set', userid );
console.log("🚹 Sending updates for",userid);
}
}
// socket.io stuff
socket
.on('connect', function(){
console.log("⬆️ Connected!");
waitForElements([mapuser,userid], function() {
onConnect(socket,userid,mapuser._id);
});
// Can get location
socket.emit('can-get', mapuser._id );
console.log("🚹 Receiving updates for",mapuser._id);
// Can set location too
if (mapuser._id===userid) {
socket.emit('can-set', userid );
console.log("🚹 Sending updates for",userid);
}
})
.on('disconnect', function(){
console.log("⬇️ Disconnected!");
@ -49,17 +35,6 @@ socket
console.error('❌️',err.message);
});
// Parse location
function parseLoc(loc) {
loc.spd = (mapuser.settings.units=='standard')?parseFloat(loc.spd)*2.23694:parseFloat(loc.spd);
loc.dir = parseFloat(loc.dir);
loc.lat = parseFloat(loc.lat);
loc.lon = parseFloat(loc.lon);
loc.tim = new Date(loc.tim).toLocaleString();
loc.glatlng = new google.maps.LatLng(loc.lat, loc.lon);
return loc;
}
// Show/hide map if location is set/unset
function toggleMaps(loc) {
if (loc.lat===0&&loc.lon===0) {
@ -78,28 +53,26 @@ $(function() {
toggleMaps(mapuser.last);
});
// Google maps API callback
window.gmapsCb = function() {
//console.log("gmapsCb() called");
// Load google maps
loadGoogleMapsAPI({ key:mapKey })
.then(function(googlemaps) {
//console.log("Loaded google maps:",googlemaps);
// Make sure everything's ready...
waitForElements([mapuser,disp,noHeader], function() {
// Create map
if (disp!=='1') {
//console.log("Creating map...");
map = new google.maps.Map( mapElem, {
center: new google.maps.LatLng( mapuser.last.lat, mapuser.last.lon ),
map = new googlemaps.Map( mapElem, {
center: new googlemaps.LatLng( mapuser.last.lat, mapuser.last.lon ),
panControl: false,
scaleControl: mapuser.settings.showScale,
draggable: false,
zoom: mapuser.settings.defaultZoom,
streetViewControl: false,
zoomControlOptions: {position: google.maps.ControlPosition.LEFT_TOP},
mapTypeId: (mapuser.settings.defaultMap=='road')?google.maps.MapTypeId.ROADMAP:google.maps.MapTypeId.HYBRID
zoomControlOptions: {position: googlemaps.ControlPosition.LEFT_TOP},
mapTypeId: (mapuser.settings.defaultMap=='road')?googlemaps.MapTypeId.ROADMAP:googlemaps.MapTypeId.HYBRID
});
marker = new google.maps.Marker({
marker = new googlemaps.Marker({
position: { lat:mapuser.last.lat, lng:mapuser.last.lon },
title: mapuser.name,
map: map,
@ -117,7 +90,7 @@ window.gmapsCb = function() {
logoDiv.innerHTML = '<a href="https://tracman.org/">'+
'<img src="https://tracman.org/static/img/style/logo-28.png" alt="[]">'+
"<span class='text'>Tracman</span></a>";
map.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(logoDiv);
map.controls[googlemaps.ControlPosition.BOTTOM_LEFT].push(logoDiv);
}
// Create update time block
@ -127,7 +100,7 @@ window.gmapsCb = function() {
if (mapuser.last.time) {
timeDiv.innerHTML = 'location updated '+new Date(mapuser.last.time).toLocaleString();
}
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(timeDiv);
map.controls[googlemaps.ControlPosition.RIGHT_BOTTOM].push(timeDiv);
// Create speed block
if (mapuser.settings.showSpeed) {
@ -146,13 +119,13 @@ window.gmapsCb = function() {
speedSign.appendChild(speedLabel);
speedSign.appendChild(speedText);
speedSign.appendChild(speedUnit);
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(speedSign);
map.controls[googlemaps.ControlPosition.TOP_RIGHT].push(speedSign);
}
// Create altitude block
if (mapuser.settings.showAlt) {
//console.log("Creating altitude sign...");
const elevator = new google.maps.ElevationService,
const elevator = new googlemaps.ElevationService,
altitudeSign = document.createElement('div'),
altitudeLabel = document.createElement('div'),
altitudeText = document.createElement('div'),
@ -163,14 +136,14 @@ window.gmapsCb = function() {
altitudeSign.id = 'alt-sign';
altitudeText.innerHTML = '';
altitudeLabel.innerHTML = 'ALTITUDE';
getAltitude(new google.maps.LatLng(mapuser.last.lat,mapuser.last.lon), elevator, function(alt) {
getAltitude(new googlemaps.LatLng(mapuser.last.lat,mapuser.last.lon), elevator, function(alt) {
if (alt) { altitudeText.innerHTML = (mapuser.settings.units=='standard')?(alt*3.28084).toFixed():alt.toFixed(); }
});
altitudeUnit.innerHTML = (mapuser.settings.units=='standard')?'feet':'meters';
altitudeSign.appendChild(altitudeLabel);
altitudeSign.appendChild(altitudeText);
altitudeSign.appendChild(altitudeUnit);
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(altitudeSign);
map.controls[googlemaps.ControlPosition.TOP_RIGHT].push(altitudeSign);
}
}
@ -180,141 +153,152 @@ window.gmapsCb = function() {
//console.log("Creating streetview...");
updateStreetView(parseLoc(mapuser.last),10);
}
});
};
// Got location
socket.on('get', function(loc) {
console.log("🌐️ Got location:",loc.lat+", "+loc.lon);
// Parse location
newLoc = parseLoc(loc);
function parseLoc(loc) {
loc.spd = (mapuser.settings.units=='standard')?parseFloat(loc.spd)*2.23694:parseFloat(loc.spd);
loc.dir = parseFloat(loc.dir);
loc.lat = parseFloat(loc.lat);
loc.lon = parseFloat(loc.lon);
loc.tim = new Date(loc.tim).toLocaleString();
loc.glatlng = new googlemaps.LatLng(loc.lat, loc.lon);
return loc;
}
// Got location
socket.on('get', function(loc) {
console.log("🌐️ Got location:",loc.lat+", "+loc.lon);
// Update map
if (disp!=='1') {
// Update time
$('#timestamp').text('location updated '+newLoc.tim);
// Update marker and map center
google.maps.event.trigger(map,'resize');
map.setCenter({ lat:newLoc.lat, lng:newLoc.lon });
marker.setPosition({ lat:newLoc.lat, lng:newLoc.lon });
// Update speed
if (mapuser.settings.showSpeed) {
$('#spd').text( newLoc.spd.toFixed() );
}
// Parse location
newLoc = parseLoc(loc);
// Update altitude
if (mapuser.settings.showAlt) {
getAltitude({
lat: newLoc.lat,
lng: newLoc.lon
}, elevator, function(alt) {
if (alt) {
$('#alt').text( (mapuser.settings.units=='standard')?(alt*3.28084).toFixed():alt.toFixed() );
// Update map
if (disp!=='1') {
// Update time
$('#timestamp').text('location updated '+newLoc.tim);
// Update marker and map center
googlemaps.event.trigger(map,'resize');
map.setCenter({ lat:newLoc.lat, lng:newLoc.lon });
marker.setPosition({ lat:newLoc.lat, lng:newLoc.lon });
// Update speed
if (mapuser.settings.showSpeed) {
$('#spd').text( newLoc.spd.toFixed() );
}
// Update altitude
if (mapuser.settings.showAlt) {
getAltitude({
lat: newLoc.lat,
lng: newLoc.lon
}, elevator, function(alt) {
if (alt) {
$('#alt').text( (mapuser.settings.units=='standard')?(alt*3.28084).toFixed():alt.toFixed() );
}
});
}
}
// Update street view
if (disp!=='0' && mapuser.settings.showStreetview) {
updateStreetView(newLoc,10);
}
});
// Check altitude
function getAltitude(loc,elev,cb){
//console.log("Getting altitude...");
elev = elev || new googlemaps.ElevationService;
elev.getElevationForLocations({
'locations': [loc]
}, function(results, status) {
if (status === googlemaps.ElevationStatus.OK && results[0]) {
cb(results[0].elevation);
}
});
}
// Get street view imagery
function getStreetViewData(loc,rad,cb) {
// Ensure that the location hasn't changed
if (loc===newLoc) {
if (!sv) { var sv=new googlemaps.StreetViewService(); }
sv.getPanorama({
location: {
lat: loc.lat,
lng: loc.lon
},
radius: rad
}, function(data,status){ switch (status){
// Success
case googlemaps.StreetViewStatus.OK:
cb(data);
break;
// No results in that radius
case googlemaps.StreetViewStatus.ZERO_RESULTS:
// Try again with a bigger radius
getStreetViewData(loc,rad*2,cb);
break;
// Error
default:
console.error(new Error('❌️ Street view not available: '+status).message);
} });
} else { console.log('loc!==newLoc'); }
}
// Update streetview
function updateStreetView(loc) {
//console.log("Updating streetview...");
// Moving (show stationary image)
if (loc.spd>1) {
const imgElem = document.getElementById('panoImg');
getStreetViewData(loc, 2, function(data){
if (!imgElem) {
// Create image
pano = undefined;
$('#pano').empty();
$('#pano').append($('<img>',{
alt: 'Street view image',
src: 'https://maps.googleapis.com/maps/api/streetview?size=800x800&location='+loc.lat+','+loc.lon+'&fov=90&heading='+loc.dir+'&key={{api}}',
id: 'panoImg'
}));
}
// Set image
$('#panoImg').attr('src','https://maps.googleapis.com/maps/api/streetview?size='+$('#pano').width()+'x'+$('#pano').height()+'&location='+data.location.latLng.lat()+','+data.location.latLng.lng()+'&fov=90&heading='+loc.dir+'&key={{api}}');
});
}
// Not moving and pano not set (create panoramic image)
else if (pano==null) {
getStreetViewData(loc, 2, function(data){
// Create panorama
$('#pano').empty();
const panoOptions = {
panControl: false,
zoomControl: false,
addressControl: false,
linksControl: false,
motionTracking: false,
motionTrackingControl: false
};
pano = new googlemaps.StreetViewPanorama(panoElem, panoOptions);
// Set panorama
pano.setPano(data.location.pano);
pano.setPov({
pitch: 0,
// Point towards users's location from street
heading: Math.atan((loc.lon-data.location.latLng.lng())/(loc.lat-data.location.latLng.lat()))*(180/Math.PI)
});
});
}
}
// Update street view
if (disp!=='0' && mapuser.settings.showStreetview) {
updateStreetView(newLoc,10);
}
}).catch((err) => {
console.error(err);
});
// Check altitude
function getAltitude(loc,elev,cb){
//console.log("Getting altitude...");
elev = elev || new google.maps.ElevationService;
elev.getElevationForLocations({
'locations': [loc]
}, function(results, status) {
if (status === google.maps.ElevationStatus.OK && results[0]) {
cb(results[0].elevation);
}
});
}
// Get street view imagery
function getStreetViewData(loc,rad,cb) {
// Ensure that the location hasn't changed
if (loc===newLoc) {
if (!sv) { var sv=new google.maps.StreetViewService(); }
sv.getPanorama({
location: {
lat: loc.lat,
lng: loc.lon
},
radius: rad
}, function(data,status){ switch (status){
// Success
case google.maps.StreetViewStatus.OK:
cb(data);
break;
// No results in that radius
case google.maps.StreetViewStatus.ZERO_RESULTS:
// Try again with a bigger radius
getStreetViewData(loc,rad*2,cb);
break;
// Error
default:
console.error(new Error('❌️ Street view not available: '+status).message);
} });
} else { console.log('loc!==newLoc'); }
}
// Update streetview
function updateStreetView(loc) {
//console.log("Updating streetview...");
// Moving (show stationary image)
if (loc.spd>1) {
const imgElem = document.getElementById('panoImg');
getStreetViewData(loc, 2, function(data){
if (!imgElem) {
// Create image
pano = undefined;
$('#pano').empty();
$('#pano').append($('<img>',{
alt: 'Street view image',
src: 'https://maps.googleapis.com/maps/api/streetview?size=800x800&location='+loc.lat+','+loc.lon+'&fov=90&heading='+loc.dir+'&key={{api}}',
id: 'panoImg'
}));
}
// Set image
$('#panoImg').attr('src','https://maps.googleapis.com/maps/api/streetview?size='+$('#pano').width()+'x'+$('#pano').height()+'&location='+data.location.latLng.lat()+','+data.location.latLng.lng()+'&fov=90&heading='+loc.dir+'&key={{api}}');
});
}
// Not moving and pano not set (create panoramic image)
else if (pano==null) {
getStreetViewData(loc, 2, function(data){
// Create panorama
$('#pano').empty();
const panoOptions = {
panControl: false,
zoomControl: false,
addressControl: false,
linksControl: false,
motionTracking: false,
motionTrackingControl: false
};
pano = new google.maps.StreetViewPanorama(panoElem, panoOptions);
// Set panorama
pano.setPano(data.location.pano);
pano.setPov({
pitch: 0,
// Point towards users's location from street
heading: Math.atan((loc.lon-data.location.latLng.lng())/(loc.lat-data.location.latLng.lat()))*(180/Math.PI)
});
});
}
}

View File

@ -94,23 +94,24 @@
{% block javascript %}
{{super()}}
<!-- google maps API -->
<script type="application/javascript" src="https://maps.googleapis.com/maps/api/js?key={{mapApi}}" async></script>
<!-- webpacked javascript -->
<script type="application/javascript" src="/static/js/dist/map.js"></script>
{% if user.id == mapuser.id %}
<!-- client-side controls javascript -->
<script type="application/javascript" src="/static/js/map-controls.min.js"></script>
{% endif %}
<!-- Variables from server-side -->
<script>
const mapuser = JSON.parse('{{mapuser |dump|safe}}'),
mapKey = "{{mapApi |safe}}",
noHeader = "{{noHeader |safe}}",
disp = "{{disp |safe}}", // 0=map, 1=streetview, 2=both
userid = "{{user._id |safe}}",
token = "{{user.sk32 |safe}}";
</script>
<!-- google maps API -->
<!--<script type="application/javascript" src="https://maps.googleapis.com/maps/api/js?key={{mapApi}}&callback=gmapsCb" async defer></script>-->
<!-- webpacked javascript -->
<script type="application/javascript" src="/static/js/dist/map.js"></script>
{% if user.id == mapuser.id %}
<!-- client-side controls javascript -->
<script type="application/javascript" src="/static/js/dist/controls.js"></script>
{% endif %}
{% endblock %}

View File

@ -53,7 +53,7 @@
{% block javascript %}
{{super()}}
<script type="application/javascript" src="/static/js/mellt.min.js"></script>
<script type="application/javascript" src="/static/js/common-passwords.min.js"></script>
<script type="application/javascript" src="/static/js/password.min.js"></script>
<script type="application/javascript" src="/static/js/dist/mellt.js"></script>
<script type="application/javascript" src="/static/js/dist/commonpasswords.js"></script>
<script type="application/javascript" src="/static/js/dist/password.js"></script>
{% endblock %}

View File

@ -150,5 +150,5 @@
{% block javascript %}
{{super()}}
<script type="application/javascript" src="/static/js/settings.min.js"></script>
<script type="application/javascript" src="/static/js/dist/settings.js"></script>
{% endblock %}

View File

@ -13,4 +13,4 @@
</div>
</footer>
<script type="application/javascript" src="/static/js/footer.min.js"></script>
<script type="application/javascript" src="/static/js/dist/footer.js"></script>

View File

@ -56,4 +56,4 @@
</div>
{% endfor %}
<script type="application/javascript" src="/static/js/header.min.js"></script>
<script type="application/javascript" src="/static/js/dist/header.js"></script>

View File

@ -1,12 +1,18 @@
var path = require('path');
module.exports = {
entry: './static/js/src/map.js',
output: {
filename: 'map.js',
path: path.resolve(__dirname, 'static/js/dist')
entry: {
header: './static/js/src/header.js',
footer: './static/js/src/footer.js',
map: './static/js/src/map.js',
controls: './static/js/src/map-controls.js',
settings: './static/js/src/settings.js',
password: './static/js/src/password.js',
mellt: './static/js/src/mellt.js',
commonpasswords: './static/js/src/common-passwords.js'
},
externals: {
google: 'google'
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'static/js/dist')
}
};