]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Tweening now working properly with both mine and Coles version, minor tweeks still...
authorDavid Seifried <david.c.seifried@gmail.com>
Sun, 15 May 2011 22:47:00 +0000 (18:47 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Sun, 15 May 2011 22:47:00 +0000 (18:47 -0400)
plugins/googlemap/popcorn.googlemap.js
plugins/googlemap/tween.html

index 44be61585caa49cb476445e66fc24756333f6ed2..215dc0bf51d03c8f39818476fd98232408d55fe2 100644 (file)
@@ -176,85 +176,62 @@ var googleCallback;
 \r
                                 var tween = function (rM, t) {\r
 \r
-                                        setTimeout(function () {\r
-                                          console.log(rM);\r
-                                          sView.setPosition(rM);\r
-                                          \r
-                                        }, t);\r
+                                  setTimeout(function () {\r
+\r
+                                    if(options.tween){\r
+\r
+                                      var p = new google.maps.LatLng(rM.position.lat, rM.position.lng);\r
+                                           sView.setPosition(p);\r
+\r
+                                           sView.setPov({\r
+                                             heading: rM.pov.heading,\r
+                                             zoom: 1,\r
+                                             pitch: 1\r
+                                           });\r
+\r
+                                    }\r
+                                    else{\r
+                                      sView.setPosition(rM);\r
+                                    }   \r
+                                  }, t);\r
 \r
                                 }\r
+\r
                                 var tmr = 0;\r
         \r
-                                if ( !!options.startLoc && !!options.endLoc ){\r
-   \r
+                                if ( !options.tween && ( options.location && options.endLoc) ){\r
+                                  \r
                                   //  Create an array to store all the lat/lang values along our route\r
                                   var checkpoints = [];\r
 \r
-                                  //  Helper function to split up each portion on a route into smaller chunks, creating a smoother and more fluent tween\r
-                                  //  Also pushes the data into the checkpoints array\r
-                                  var getSteps = function (start, end){\r
-                                    var latDiff = (end.lat() - start.lat()) / 100,\r
-                                        lngDiff = (end.lng() - start.lng()) / 100,\r
-                                        lat = start.lat(), \r
-                                        lng = start.lng();\r
-\r
-                                    for(var i = 0; i < 99; i++){\r
-                                      lat += latDiff;\r
-                                      lng += lngDiff;\r
-                                      checkpoints.push(new google.maps.LatLng(lat, lng));\r
-                                    }\r
-                                    checkpoints.push(new google.maps.LatLng(end.lat(), end.lng()));\r
-                                  }\r
-\r
                                   var directionsService = new google.maps.DirectionsService();\r
 \r
                                   var directionsDisplay = new google.maps.DirectionsRenderer(sView);\r
 \r
                                   var request = {\r
-                                    origin: options.startLoc,\r
+                                    origin: options.location,\r
                                     destination:options.endLoc,\r
                                     travelMode: google.maps.TravelMode.DRIVING\r
                                   };\r
 \r
                                   directionsService.route(request, function(response, status) {\r
-                                        if (status == google.maps.DirectionsStatus.OK) {\r
-                                          directionsDisplay.setDirections(response);\r
-                                          showSteps(response);\r
-                                        }\r
+                                    if (status == google.maps.DirectionsStatus.OK) {\r
+                                      directionsDisplay.setDirections(response);\r
+                                      showSteps(response);\r
+                                    }\r
                                   });\r
 \r
                                   function showSteps(directionResult) {\r
-                                    for (var j = 0; j < directionResult.routes[0].overview_path.length-1; j++) {\r
-                                      getSteps(directionResult.routes[0].overview_path[j], directionResult.routes[0].overview_path[j+1]);\r
+                                    for (var j = 0; j < directionResult.routes[0].overview_path.length; j++) {\r
+                                      checkpoints.push(new google.maps.LatLng(directionResult.routes[0].overview_path[j].lat(), directionResult.routes[0].overview_path[j].lng()));\r
                                     }     \r
                                     for ( var i = 0; i < checkpoints.length; i++ ) {\r
                                       tmr = tmr + options.interval;\r
                                       tween( checkpoints[i], tmr );\r
                                     }\r
-\r
-\r
-                                  interval = window.setInterval(function(){\r
-                                        i++;\r
-                                        // use trig to adjust the heading towards destination\r
-                                       if ( i > 0 ) {\r
-                                          //console.log(k);\r
-                                          var radians = Math.atan2( ( checkpoints[i].lng() - checkpoints[i-1].lng() ), \r
-                                                                   ( checkpoints[i].lat() - checkpoints[i-1].lat() ) );\r
-                                          var degrees = Math.round( ( radians / (Math.PI/180) ) );\r
-                                          var pov = panorama.getPov();\r
-                                          pov.heading = degrees;\r
-                                          sView.setPov(pov); \r
-                                        }\r
-                                        sView.setPosition(checkpoints[i]);\r
-                                        //console.log(checkpoints.length);\r
-                                        if(i == checkpoints.length-1){\r
-                                          console.log("DONE");\r
-                                          window.clearInterval(interval);\r
-                                      }\r
-                                      }, options.interval);\r
                                   }\r
                                 }\r
-                                else if ( options.tween.length > 0 ){\r
+                                else {\r
                                   for ( i = 0; i < options.tween.length; i++ ) {\r
                                     tmr = tmr + options.tween[i].interval;\r
                                     tween( options.tween[i], tmr );\r
index d5b04d0dbd38d1a14be9e6e6a8ca0f0a6aa05615..2ea0ff4321ed96c8607eaf3c31f16af81892cc2d 100644 (file)
         end: 20, // seconds\r
         type: "STREETVIEW",\r
         target: "map1",\r
-        location:"Toronto",\r
+        location: "6th Line, Oakville, Ontario",\r
+        //lat: 35.7795324,\r
+        //lng: -78.63915450000002,\r
         zoom: "1",\r
         heading: "180",\r
         pitch: "1",\r
-                               interval: 10,\r
-                               startLoc: "Burlington",\r
-                               endLoc: "Oakville"\r
+                               interval: 1000,\r
+                               endLoc: "York university"\r
+        /*tween:[ \r
+                       {\r
+                               position: {lat: 35.778056, lng: -78.63903579999999}, \r
+                                   pov: {heading: 183.5, zoom: 1, pitch:1}, \r
+                                   interval:2000 \r
+                               },\r
+                           {   position: {lat: 35.7770258, lng: -78.63929150000001}, \r
+                               pov: {heading: 180, zoom: 1, pitch:1},\r
+                               interval:2000\r
+                           },\r
+                           {   position: {lat: 35.775581, lng: -78.639395}, \r
+                               pov: {heading: 180, zoom: 1, pitch:1},\r
+                               interval:2000\r
+                           }, \r
+                           {   position: {lat: 35.775581, lng: -78.639395}, \r
+                               pov: {heading: 105, zoom: 1, pitch:1},\r
+                               interval:2000\r
+                           },\r
+                           {   position: {lat: 35.775581, lng: -78.639395}, \r
+                               pov: {heading: 0, zoom: 1, pitch:1},\r
+                               interval:2000\r
+                           }   \r
+      ]*/\r
       } );\r
     }, false);\r
   </script>\r