Imported remaing Tracman logic
parent
c30572f0b2
commit
4e76e12243
56
script.js
56
script.js
|
@ -1,5 +1,8 @@
|
|||
'use strict';
|
||||
/* global navigator $ */
|
||||
/* global navigator googlemaps $ */
|
||||
|
||||
var pano, newLoc;
|
||||
const main = document.getElementsByTagName('main')[0];
|
||||
|
||||
// Get street view imagery
|
||||
function getStreetViewData(loc,rad,cb) {
|
||||
|
@ -29,41 +32,12 @@ function getStreetViewData(loc,rad,cb) {
|
|||
}
|
||||
}
|
||||
|
||||
// Track GPS location
|
||||
if (!navigator.geolocation){ /* Show error */ }
|
||||
else { navigator.geolocation.watchPosition(
|
||||
|
||||
// Got location
|
||||
function(pos) {
|
||||
|
||||
// Moving (show image)
|
||||
if (loc.spd>1) {
|
||||
|
||||
// Create image
|
||||
const imgElem = document.getElementById('panoImg');
|
||||
if (!imgElem) {
|
||||
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
|
||||
getStreetViewData(loc, 2, function(data){
|
||||
$('#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='+mapKey);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Not moving and pano not set (create panoramic image)
|
||||
else if (pano==null) {
|
||||
function updateStreetView(loc){
|
||||
|
||||
// Create panorama
|
||||
$('#pano').empty();
|
||||
pano = new googlemaps.StreetViewPanorama(panoElem, {
|
||||
if ( typeof pano == 'undefined' ){
|
||||
$('main').empty();
|
||||
pano = new googlemaps.StreetViewPanorama(main, {
|
||||
panControl: false,
|
||||
zoomControl: false,
|
||||
addressControl: false,
|
||||
|
@ -71,6 +45,7 @@ else { navigator.geolocation.watchPosition(
|
|||
motionTracking: false,
|
||||
motionTrackingControl: false
|
||||
});
|
||||
}
|
||||
|
||||
// Set panorama
|
||||
getStreetViewData(loc, 2, function(data){
|
||||
|
@ -81,8 +56,21 @@ else { navigator.geolocation.watchPosition(
|
|||
heading: Math.atan((loc.lon-data.location.latLng.lng())/(loc.lat-data.location.latLng.lat()))*(180/Math.PI)
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Track GPS location
|
||||
if (!navigator.geolocation){ /* Show error */ }
|
||||
else { navigator.geolocation.watchPosition(
|
||||
|
||||
// Got location
|
||||
function(pos) {
|
||||
newLoc = {
|
||||
lat: pos.coords.latitude,
|
||||
lon: pos.coords.longitude,
|
||||
tim: new Date()
|
||||
};
|
||||
updateStreetView(newLoc,10);
|
||||
},
|
||||
|
||||
// Got error
|
||||
|
|
Loading…
Reference in New Issue