From 4cc25abe15963243bd0552e8c29d3ec3f06c557b Mon Sep 17 00:00:00 2001 From: David Seifried Date: Sun, 15 May 2011 18:47:00 -0400 Subject: [PATCH] Tweening now working properly with both mine and Coles version, minor tweeks still to fix --- plugins/googlemap/popcorn.googlemap.js | 81 +++++++++----------------- plugins/googlemap/tween.html | 32 ++++++++-- 2 files changed, 57 insertions(+), 56 deletions(-) diff --git a/plugins/googlemap/popcorn.googlemap.js b/plugins/googlemap/popcorn.googlemap.js index 44be615..215dc0b 100644 --- a/plugins/googlemap/popcorn.googlemap.js +++ b/plugins/googlemap/popcorn.googlemap.js @@ -176,85 +176,62 @@ var googleCallback; var tween = function (rM, t) { - setTimeout(function () { - console.log(rM); - sView.setPosition(rM); - - }, t); + setTimeout(function () { + + if(options.tween){ + + var p = new google.maps.LatLng(rM.position.lat, rM.position.lng); + sView.setPosition(p); + + sView.setPov({ + heading: rM.pov.heading, + zoom: 1, + pitch: 1 + }); + + } + else{ + sView.setPosition(rM); + } + }, t); } + var tmr = 0; - if ( !!options.startLoc && !!options.endLoc ){ - + if ( !options.tween && ( options.location && options.endLoc) ){ + // Create an array to store all the lat/lang values along our route var checkpoints = []; - // Helper function to split up each portion on a route into smaller chunks, creating a smoother and more fluent tween - // Also pushes the data into the checkpoints array - var getSteps = function (start, end){ - var latDiff = (end.lat() - start.lat()) / 100, - lngDiff = (end.lng() - start.lng()) / 100, - lat = start.lat(), - lng = start.lng(); - - for(var i = 0; i < 99; i++){ - lat += latDiff; - lng += lngDiff; - checkpoints.push(new google.maps.LatLng(lat, lng)); - } - checkpoints.push(new google.maps.LatLng(end.lat(), end.lng())); - } - var directionsService = new google.maps.DirectionsService(); var directionsDisplay = new google.maps.DirectionsRenderer(sView); var request = { - origin: options.startLoc, + origin: options.location, destination:options.endLoc, travelMode: google.maps.TravelMode.DRIVING }; directionsService.route(request, function(response, status) { - if (status == google.maps.DirectionsStatus.OK) { - directionsDisplay.setDirections(response); - showSteps(response); - } + if (status == google.maps.DirectionsStatus.OK) { + directionsDisplay.setDirections(response); + showSteps(response); + } }); function showSteps(directionResult) { - for (var j = 0; j < directionResult.routes[0].overview_path.length-1; j++) { - getSteps(directionResult.routes[0].overview_path[j], directionResult.routes[0].overview_path[j+1]); + for (var j = 0; j < directionResult.routes[0].overview_path.length; j++) { + checkpoints.push(new google.maps.LatLng(directionResult.routes[0].overview_path[j].lat(), directionResult.routes[0].overview_path[j].lng())); } for ( var i = 0; i < checkpoints.length; i++ ) { tmr = tmr + options.interval; tween( checkpoints[i], tmr ); } - - - interval = window.setInterval(function(){ - i++; - // use trig to adjust the heading towards destination - if ( i > 0 ) { - //console.log(k); - var radians = Math.atan2( ( checkpoints[i].lng() - checkpoints[i-1].lng() ), - ( checkpoints[i].lat() - checkpoints[i-1].lat() ) ); - var degrees = Math.round( ( radians / (Math.PI/180) ) ); - var pov = panorama.getPov(); - pov.heading = degrees; - sView.setPov(pov); - } - sView.setPosition(checkpoints[i]); - //console.log(checkpoints.length); - if(i == checkpoints.length-1){ - console.log("DONE"); - window.clearInterval(interval); - } - }, options.interval); } } - else if ( options.tween.length > 0 ){ + else { for ( i = 0; i < options.tween.length; i++ ) { tmr = tmr + options.tween[i].interval; tween( options.tween[i], tmr ); diff --git a/plugins/googlemap/tween.html b/plugins/googlemap/tween.html index d5b04d0..2ea0ff4 100644 --- a/plugins/googlemap/tween.html +++ b/plugins/googlemap/tween.html @@ -15,13 +15,37 @@ end: 20, // seconds type: "STREETVIEW", target: "map1", - location:"Toronto", + location: "6th Line, Oakville, Ontario", + //lat: 35.7795324, + //lng: -78.63915450000002, zoom: "1", heading: "180", pitch: "1", - interval: 10, - startLoc: "Burlington", - endLoc: "Oakville" + interval: 1000, + endLoc: "York university" + /*tween:[ + { + position: {lat: 35.778056, lng: -78.63903579999999}, + pov: {heading: 183.5, zoom: 1, pitch:1}, + interval:2000 + }, + { position: {lat: 35.7770258, lng: -78.63929150000001}, + pov: {heading: 180, zoom: 1, pitch:1}, + interval:2000 + }, + { position: {lat: 35.775581, lng: -78.639395}, + pov: {heading: 180, zoom: 1, pitch:1}, + interval:2000 + }, + { position: {lat: 35.775581, lng: -78.639395}, + pov: {heading: 105, zoom: 1, pitch:1}, + interval:2000 + }, + { position: {lat: 35.775581, lng: -78.639395}, + pov: {heading: 0, zoom: 1, pitch:1}, + interval:2000 + } + ]*/ } ); }, false); -- 2.43.0