Merged hotfix-0.6.5 into master
commit
475417981a
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
var map, pano, marker, elevator;
|
var map, pano, marker, elevator, newLoc;
|
||||||
const mapElem = document.getElementById('map'),
|
const mapElem = document.getElementById('map'),
|
||||||
panoElem = document.getElementById('pano'),
|
panoElem = document.getElementById('pano'),
|
||||||
socket = io('//'+window.location.hostname);
|
socket = io('//'+window.location.hostname);
|
||||||
|
@ -186,29 +186,29 @@ socket.on('get', function(loc) {
|
||||||
console.log("🌐️ Got location:",loc.lat+", "+loc.lon);
|
console.log("🌐️ Got location:",loc.lat+", "+loc.lon);
|
||||||
|
|
||||||
// Parse location
|
// Parse location
|
||||||
loc = parseLoc(loc);
|
newLoc = parseLoc(loc);
|
||||||
|
|
||||||
// Update map
|
// Update map
|
||||||
if (disp!=='1') {
|
if (disp!=='1') {
|
||||||
|
|
||||||
// Update time
|
// Update time
|
||||||
$('#timestamp').text('location updated '+loc.tim);
|
$('#timestamp').text('location updated '+newLoc.tim);
|
||||||
|
|
||||||
// Update marker and map center
|
// Update marker and map center
|
||||||
google.maps.event.trigger(map,'resize');
|
google.maps.event.trigger(map,'resize');
|
||||||
map.setCenter({ lat:loc.lat, lng:loc.lon });
|
map.setCenter({ lat:newLoc.lat, lng:newLoc.lon });
|
||||||
marker.setPosition({ lat:loc.lat, lng:loc.lon });
|
marker.setPosition({ lat:newLoc.lat, lng:newLoc.lon });
|
||||||
|
|
||||||
// Update speed
|
// Update speed
|
||||||
if (mapuser.settings.showSpeed) {
|
if (mapuser.settings.showSpeed) {
|
||||||
$('#spd').text( loc.spd.toFixed() );
|
$('#spd').text( newLoc.spd.toFixed() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update altitude
|
// Update altitude
|
||||||
if (mapuser.settings.showAlt) {
|
if (mapuser.settings.showAlt) {
|
||||||
getAltitude({
|
getAltitude({
|
||||||
lat:loc.lat,
|
lat: newLoc.lat,
|
||||||
lng:loc.lon
|
lng: newLoc.lon
|
||||||
}, elevator, function(alt) {
|
}, elevator, function(alt) {
|
||||||
if (alt) {
|
if (alt) {
|
||||||
$('#alt').text( (mapuser.settings.units=='standard')?(alt*3.28084).toFixed():alt.toFixed() );
|
$('#alt').text( (mapuser.settings.units=='standard')?(alt*3.28084).toFixed():alt.toFixed() );
|
||||||
|
@ -220,7 +220,7 @@ socket.on('get', function(loc) {
|
||||||
|
|
||||||
// Update street view
|
// Update street view
|
||||||
if (disp!=='0' && mapuser.settings.showStreetview) {
|
if (disp!=='0' && mapuser.settings.showStreetview) {
|
||||||
updateStreetView(loc,10);
|
updateStreetView(newLoc,10);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -239,39 +239,41 @@ function getAltitude(loc,elev,cb){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get street view imagery
|
// Get street view imagery
|
||||||
//TODO: Use global loc object?
|
|
||||||
function getStreetViewData(loc,rad,cb) {
|
function getStreetViewData(loc,rad,cb) {
|
||||||
if (!sv) { var sv=new google.maps.StreetViewService(); }
|
// Ensure that the location hasn't changed
|
||||||
sv.getPanorama({
|
if (loc===newLoc) {
|
||||||
location: {
|
if (!sv) { var sv=new google.maps.StreetViewService(); }
|
||||||
lat: loc.lat,
|
sv.getPanorama({
|
||||||
lng: loc.lon
|
location: {
|
||||||
},
|
lat: loc.lat,
|
||||||
radius:rad
|
lng: loc.lon
|
||||||
}, function(data,status){ switch (status){
|
},
|
||||||
// Success
|
radius: rad
|
||||||
case google.maps.StreetViewStatus.OK:
|
}, function(data,status){ switch (status){
|
||||||
cb(data);
|
// Success
|
||||||
break;
|
case google.maps.StreetViewStatus.OK:
|
||||||
// No results in that radius
|
cb(data);
|
||||||
case google.maps.StreetViewStatus.ZERO_RESULTS:
|
break;
|
||||||
// Square the radius and try again
|
// No results in that radius
|
||||||
getStreetViewData(loc,rad*rad*.5,cb);
|
case google.maps.StreetViewStatus.ZERO_RESULTS:
|
||||||
break;
|
// Try again with a bigger radius
|
||||||
// Error
|
getStreetViewData(loc,rad*2,cb);
|
||||||
default:
|
break;
|
||||||
console.error(new Error('❌️ Street view not available: '+status).message);
|
// Error
|
||||||
} });
|
default:
|
||||||
|
console.error(new Error('❌️ Street view not available: '+status).message);
|
||||||
|
} });
|
||||||
|
} else { console.log('loc!==newLoc'); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update streetview
|
// Update streetview
|
||||||
function updateStreetView(loc) {
|
function updateStreetView(loc) {
|
||||||
//console.log("Updating streetview...");
|
//console.log("Updating streetview...");
|
||||||
|
|
||||||
// Moving
|
// Moving (show stationary image)
|
||||||
if (loc.spd>1) {
|
if (loc.spd>1) {
|
||||||
var imgElem = document.getElementById('panoImg');
|
const imgElem = document.getElementById('panoImg');
|
||||||
getStreetViewData(loc, 50, function(data){
|
getStreetViewData(loc, 2, function(data){
|
||||||
if (!imgElem) {
|
if (!imgElem) {
|
||||||
// Create image
|
// Create image
|
||||||
pano = undefined;
|
pano = undefined;
|
||||||
|
@ -287,9 +289,9 @@ function updateStreetView(loc) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not moving and pano not set
|
// Not moving and pano not set (create panoramic image)
|
||||||
else if (pano==null) {
|
else if (pano==null) {
|
||||||
getStreetViewData(loc, 10, function(data){
|
getStreetViewData(loc, 2, function(data){
|
||||||
// Create panorama
|
// Create panorama
|
||||||
$('#pano').empty();
|
$('#pano').empty();
|
||||||
const panoOptions = {
|
const panoOptions = {
|
||||||
|
@ -305,6 +307,7 @@ function updateStreetView(loc) {
|
||||||
pano.setPano(data.location.pano);
|
pano.setPano(data.location.pano);
|
||||||
pano.setPov({
|
pano.setPov({
|
||||||
pitch: 0,
|
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)
|
heading: Math.atan((loc.lon-data.location.latLng.lng())/(loc.lat-data.location.latLng.lat()))*(180/Math.PI)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue