1 | //https://maps.google.co.nz/maps/myplaces?ll=-38.75087,174.607258&spn=0.052479,0.154324&ctz=-780&t=h&z=13&layer=c&cbll=-38.750878,174.607314&panoid=N3qt_joqFI-93LKlaJBqBQ&cbp=11,198.35,,0,2.89
|
---|
2 | //https://maps.google.co.nz/?ll=-37.793237,175.303775&spn=0.001833,0.002411&t=h&z=19&layer=c&cbll=-37.793237,175.303775&panoid=qCIp44Wk4np0MUIEw_wjEA&cbp=12,98.51,,0,0
|
---|
3 | var fenway = new google.maps.LatLng(-37.793237, 175.303775);
|
---|
4 | var botswana = new google.maps.LatLng(-20.472393999999998, 24.515585999999995);
|
---|
5 | var NowyJork = new google.maps.LatLng(42.435272, -73.789272);
|
---|
6 | var sandy = new google.maps.LatLng(40.554113, -74.110851);
|
---|
7 | var sanFran = new google.maps.LatLng(37.775679, -122.425017);
|
---|
8 | var HMSOcelot = new google.maps.LatLng(51.395492,0.526726);
|
---|
9 |
|
---|
10 | var geocoo = new google.maps.Geocoder();
|
---|
11 |
|
---|
12 |
|
---|
13 | $.urlParam = function(name){
|
---|
14 | Â Â var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
|
---|
15 | Â Â if (results==null){
|
---|
16 | Â Â Â Â return null;
|
---|
17 | Â Â }
|
---|
18 | Â Â else{
|
---|
19 | Â Â Â Â return results[1] || 0;
|
---|
20 | Â Â }
|
---|
21 | }
|
---|
22 |
|
---|
23 | var startLocation;
|
---|
24 | var steps;
|
---|
25 |
|
---|
26 | places = { hamilton: fenway,
|
---|
27 | botswana: botswana,
|
---|
28 | newyork: NowyJork,
|
---|
29 | sandy: sandy,
|
---|
30 | sanFran: sanFran,
|
---|
31 | submarine: HMSOcelot
|
---|
32 | }
|
---|
33 |
|
---|
34 | var place = $.urlParam('place');
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | if(places[place]){
|
---|
39 | startLocation = places[place];
|
---|
40 | coolParty();
|
---|
41 | }
|
---|
42 | else if (!!place)
|
---|
43 | {
|
---|
44 | geocoo.geocode({address:decodeURIComponent(place)}, function(data, status){
|
---|
45 | console.log(data);
|
---|
46 | if(data[0])
|
---|
47 | startLocation = data[0].geometry.location;
|
---|
48 | else
|
---|
49 | startLocation = fenway;
|
---|
50 | coolParty();
|
---|
51 | });
|
---|
52 | }
|
---|
53 | else{ startLocation = fenway
|
---|
54 | coolParty();
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | var selectedLink;
|
---|
59 | var timeoutHandle;
|
---|
60 |
|
---|
61 | var panorama;
|
---|
62 | var dataService;
|
---|
63 |
|
---|
64 | var SVPaths = [];
|
---|
65 |
|
---|
66 | function coolParty(){
|
---|
67 |
|
---|
68 | var map = new google.maps.Map(
|
---|
69 | document.getElementById('map-canvas'));
|
---|
70 | var panoramaOptions = {
|
---|
71 | position: startLocation,
|
---|
72 | pov: {
|
---|
73 | heading: 90,
|
---|
74 | pitch: 10,
|
---|
75 | zoom: 1
|
---|
76 |
|
---|
77 | },
|
---|
78 | linksControl:false,
|
---|
79 | panControl:false,
|
---|
80 | disableDefaultUI: true
|
---|
81 | };
|
---|
82 |
|
---|
83 | dataService = new google.maps.StreetViewService();
|
---|
84 | panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), panoramaOptions);
|
---|
85 | map.setStreetView(panorama);
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | google.maps.event.addListener(panorama, "pov_changed", function() {
|
---|
90 | SyncThreeCamera(panorama.getPov().heading, panorama.getPov().pitch); //moved back to kinect
|
---|
91 | });
|
---|
92 |
|
---|
93 | google.maps.event.addListener(panorama, "links_changed", function() {
|
---|
94 | console.log("nuking spheres and creating paths");
|
---|
95 | nukeSpheres();
|
---|
96 | createPaths();
|
---|
97 |
|
---|
98 | });
|
---|
99 | google.maps.event.addListener(panorama, "zoom_changed", function(){
|
---|
100 | camera = cameraFromGoogleZoom(panorama.getZoom());
|
---|
101 | SyncThreeCamera(panorama.getPov().heading, panorama.getPov().pitch)
|
---|
102 | });
|
---|
103 | }
|
---|
104 | /*
|
---|
105 | function LoadLinks( depth ) {
|
---|
106 | var links = panorama.getLinks();
|
---|
107 | for ( var i = 0; i < links.length; ++i ) {
|
---|
108 |
|
---|
109 | ( function( panoLink ) {
|
---|
110 | dataService.getPanoramaById( panoLink.pano, function( svData, svStatus ) {
|
---|
111 | if ( svStatus == google.maps.StreetViewStatus.OK ) {
|
---|
112 | var distance = google.maps.geometry.spherical.computeDistanceBetween( panorama.getPosition(), svData.location.latLng );
|
---|
113 | var heading = panoLink.heading;
|
---|
114 | } else console.log( svData );
|
---|
115 |
|
---|
116 | } );
|
---|
117 | } )( links[ i ] )
|
---|
118 |
|
---|
119 | }
|
---|
120 | }*/
|
---|
121 |
|
---|
122 | var skipSteps = 2;
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 | function selecto(newIndex) {
|
---|
127 | var index = newIndex - 1;
|
---|
128 | var pathIndex = pickLink(panorama.getLinks());
|
---|
129 |
|
---|
130 | //document.getElementById("kinectgripthing").innerHTML = "path: " + newIndex;
|
---|
131 |
|
---|
132 | if(index >= SVPaths[pathIndex].length)
|
---|
133 | index = SVPaths[pathIndex].length - 1;
|
---|
134 | if (index >= 0 && SVPaths[pathIndex].length > index) {
|
---|
135 | selectSphere(SVPaths[pathIndex][index]);
|
---|
136 | return SVPaths[pathIndex][index];
|
---|
137 | } else
|
---|
138 | deselectSphere();
|
---|
139 | }
|
---|
140 |
|
---|
141 | function selectSphere(link) {
|
---|
142 | if (link !== selectedLink) {
|
---|
143 | deselectSphere();
|
---|
144 | selectedLink = link;
|
---|
145 | if (selectedLink.sphere) {
|
---|
146 | selectedLink.sphere.scale = new THREE.Vector3(2, 2, 2);
|
---|
147 | selectoMore(selectedLink.sphere);
|
---|
148 | }
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | function deselectSphere() {
|
---|
153 | if (selectedLink && selectedLink.sphere){
|
---|
154 | selectedLink.sphere.scale = new THREE.Vector3(1, 1, 1);
|
---|
155 | if (selectedLink.sphere.anim)
|
---|
156 | userUnselectSphere(selectedLink.sphere);
|
---|
157 | }
|
---|
158 |
|
---|
159 | selectedLink = null;
|
---|
160 | if (timeoutHandle !== null){
|
---|
161 | window.clearTimeout(timeoutHandle);
|
---|
162 | console.log("CLEARED TIMER")
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | var selectTime = 700;
|
---|
167 | function selectoMore(sphere) {
|
---|
168 |
|
---|
169 | timeoutHandle = window.setTimeout(function() {
|
---|
170 | userSelectSphere(sphere);
|
---|
171 |
|
---|
172 | /*
|
---|
173 | //separate stage 1
|
---|
174 | sphere.startTime = performance.now();
|
---|
175 | var speed = sphere.distance / selectTime;
|
---|
176 | //alert("heading equals " + sphere.heading + " and x equals " + sphere.position.x + " and distance equals " + sphere.distance );
|
---|
177 | //alert("all up is " + Math.sin(sphere.heading) * (sphere.position.x / sphere.distance));
|
---|
178 | var vec = new THREE.Vector3(Math.sin(sphere.heading) * (sphere.position.x / sphere.distance) , 0 , Math.cos(sphere.heading) * (sphere.position.z / sphere.distance) );
|
---|
179 | //alert("Raw vec is");
|
---|
180 | //alert(JSON.stringify(vec));
|
---|
181 | vec.normalize();
|
---|
182 | vec.multiplyScalar(speed);
|
---|
183 | //alert("scaled vec is");
|
---|
184 | //alert(JSON.stringify(vec));
|
---|
185 | sphere.vec = vec;
|
---|
186 | */
|
---|
187 | /*
|
---|
188 |
|
---|
189 | document.getElementById("kinectgripthing").innerHTML= "sphere " + sphere.id + ":<br> " + JSON.stringify(vec) + "<br>";
|
---|
190 | spheros.push(sphere);//begins animation
|
---|
191 | */
|
---|
192 |
|
---|
193 | }, selectTime);
|
---|
194 | console.log("SETTIMER");
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | function userSelectSphere(sphere){
|
---|
199 | //alert(JSON.stringify(getHipCameraPoint()));
|
---|
200 | sphere.anim = new Ease(sphere.startPos,getHipCameraPoint(), 500);
|
---|
201 | }
|
---|
202 | function userUnselectSphere(sphere){
|
---|
203 | var timeo = Math.min(500, sphere.anim.time)
|
---|
204 | sphere.anim = new Ease(sphere.position, sphere.startPos, timeo);
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | function jumpLoop(startPano) {
|
---|
209 |
|
---|
210 | //console.log("entered jumpLoop with " + steps + " steps")
|
---|
211 | steps--;
|
---|
212 | getLinks(startPano, jumpLoopFinish);
|
---|
213 | }
|
---|
214 |
|
---|
215 | function getLinks(startPano, finalMethod) {
|
---|
216 | dataService.getPanoramaById(startPano, function(StreetViewPanoramaData, StreetViewStatus) {
|
---|
217 |
|
---|
218 | if (StreetViewStatus == "OK") pickHop(StreetViewPanoramaData.links, finalMethod);
|
---|
219 | else {
|
---|
220 | console.log("StreetViewStatus was " + StreetViewStatus + " so I gave up")
|
---|
221 | };
|
---|
222 | });
|
---|
223 | }
|
---|
224 |
|
---|
225 | function jumpLoopFinish(responsePano) {
|
---|
226 | if (steps <= 0) { //break from loop
|
---|
227 | //panorama.setPano(responsePano);
|
---|
228 | dataService.getPanoramaById(responsePano.pano, function(svData, svStatus) {
|
---|
229 | if (svStatus == google.maps.StreetViewStatus.OK) {
|
---|
230 | var distance = google.maps.geometry.spherical.computeDistanceBetween(panorama.getPosition(), svData.location.latLng);
|
---|
231 | console.log("jumping to " + responsePano.pano);
|
---|
232 | var heading = google.maps.geometry.spherical.computeHeading(panorama.getPosition(), svData.location.latLng);
|
---|
233 | //createPanoSphere( heading, distance, responsePano );
|
---|
234 | panorama.setPano(responsePano.pano);
|
---|
235 | }
|
---|
236 | });
|
---|
237 | skipSteps++;
|
---|
238 | return;
|
---|
239 | }
|
---|
240 | console.log("steps = " + steps + " and going another round now from " + responsePano);
|
---|
241 | jumpLoop(responsePano.pano);
|
---|
242 | }
|
---|
243 |
|
---|
244 | /**
|
---|
245 | *links, the collection of google streetview links
|
---|
246 | *finalMethod, method to pass result on to
|
---|
247 | **/
|
---|
248 |
|
---|
249 | function pickLink(links) { //based off the current pano's heading return next forward jump
|
---|
250 | //console.log("Starting jump from " + startPano);
|
---|
251 | var setPano = null;
|
---|
252 | var povHeading = panorama.getPov().heading;
|
---|
253 | var minDiff = 360;
|
---|
254 | var theIndex;
|
---|
255 |
|
---|
256 | //console.log("Starting picklink panorama pano is " + startPano);//+ " and startPano is " + startPano
|
---|
257 | for (var k = 0; k < links.length; k++) {
|
---|
258 |
|
---|
259 | var linkBearing = (links[k].heading + 360) % 360;
|
---|
260 | var povHead = (povHeading + 360) % 360;
|
---|
261 |
|
---|
262 | var diff = Math.abs(linkBearing - povHead);
|
---|
263 | //console.log("diff is " + diff + " at " + dummyLinks[k].pano);
|
---|
264 | if (diff > 180) {
|
---|
265 | diff = 360 - diff;
|
---|
266 | }
|
---|
267 | if (minDiff > diff) {
|
---|
268 | minDiff = diff;
|
---|
269 | setPano = links[k];
|
---|
270 | theIndex = k;
|
---|
271 | }
|
---|
272 | // console.log(links[k].description + " " + k + ": " + linkBearing + " minus " + povHead + " = " + (linkBearing - povHead) + ", mindiff is " + minDiff);
|
---|
273 |
|
---|
274 | }
|
---|
275 | //console.log("Picked " + setPano + '\n');
|
---|
276 | //finalMethod( theIndex );
|
---|
277 | //console.log("k is " +k);
|
---|
278 | //console.log(theIndex);
|
---|
279 | return theIndex;
|
---|
280 | }
|
---|
281 |
|
---|
282 | function pickHop(links) { //based off the current pano's heading return next forward jump
|
---|
283 | var setPano = null;
|
---|
284 | var povHeading = panorama.getPov().heading;
|
---|
285 | var minDiff = 360;
|
---|
286 |
|
---|
287 | for (var k = 0; k < links.length; k++) {
|
---|
288 |
|
---|
289 | var linkBearing = (links[k].heading + 360) % 360;
|
---|
290 | var povHead = (povHeading + 360) % 360;
|
---|
291 |
|
---|
292 | var diff = Math.abs(linkBearing - povHead);
|
---|
293 | //console.log("diff is " + diff + " at " + dummyLinks[k].pano);
|
---|
294 | if (diff > 180) {
|
---|
295 | diff = 360 - diff;
|
---|
296 | }
|
---|
297 | if (minDiff > diff) {
|
---|
298 | minDiff = diff;
|
---|
299 | setPano = links[k];
|
---|
300 | }
|
---|
301 |
|
---|
302 | }
|
---|
303 |
|
---|
304 | return setPano;
|
---|
305 | }
|
---|
306 |
|
---|
307 | function createPaths() {
|
---|
308 | console.log("Recomputing Paths");
|
---|
309 | var newPaths = panorama.getLinks();
|
---|
310 | SVPaths = [];
|
---|
311 |
|
---|
312 | for (var i = 0; i < newPaths.length; ++i) {
|
---|
313 | SVPaths[i] = [newPaths[i]];
|
---|
314 | extendPath(SVPaths[i], 10);
|
---|
315 | }
|
---|
316 | console.log(SVPaths);
|
---|
317 | }
|
---|
318 |
|
---|
319 | function extendPath(path, steps) {
|
---|
320 | var curLink = path[path.length - 1];
|
---|
321 |
|
---|
322 | dataService.getPanoramaById(curLink.pano, function(svData, svStatus) {
|
---|
323 |
|
---|
324 | if (svStatus == google.maps.StreetViewStatus.OK) {
|
---|
325 |
|
---|
326 | var distance = google.maps.geometry.spherical.computeDistanceBetween(panorama.getPosition(), svData.location.latLng);
|
---|
327 | var heading = google.maps.geometry.spherical.computeHeading(panorama.getPosition(), svData.location.latLng);
|
---|
328 |
|
---|
329 | createPanoSphere(heading, distance, curLink, svData.tiles.centerHeading);
|
---|
330 | curLink.distance = distance;
|
---|
331 | curLink.heading = heading;
|
---|
332 | } else
|
---|
333 | alert("Ohhh myyy goooooooooooood");
|
---|
334 |
|
---|
335 |
|
---|
336 | if (svStatus == "OK") pickExtendLink(curLink.heading, svData.links, function(nextLink) {
|
---|
337 |
|
---|
338 | path.push(nextLink);
|
---|
339 |
|
---|
340 | if (steps > 1)
|
---|
341 | extendPath(path, steps - 1);
|
---|
342 | });
|
---|
343 | else
|
---|
344 | console.log("StreetViewStatus was " + svStatus + " so I gave up");
|
---|
345 |
|
---|
346 | });
|
---|
347 | }
|
---|
348 |
|
---|
349 | function pickExtendLink(heading, links, finalMethod) { //based off the current pano's heading return next forward jump
|
---|
350 | //console.log("Starting jump from " + startPano);
|
---|
351 | var setPano = null;
|
---|
352 | var povHeading = heading;
|
---|
353 | var minDiff = 360;
|
---|
354 |
|
---|
355 | //console.log("Starting picklink panorama pano is " + startPano);//+ " and startPano is " + startPano
|
---|
356 | for (var k = 0; k < links.length; k++) {
|
---|
357 |
|
---|
358 | var linkBearing = (links[k].heading + 360) % 360;
|
---|
359 | var povHead = (povHeading + 360) % 360;
|
---|
360 |
|
---|
361 | var diff = Math.abs(linkBearing - povHead);
|
---|
362 | //console.log("diff is " + diff + " at " + dummyLinks[k].pano);
|
---|
363 | if (diff > 180) {
|
---|
364 | diff = 360 - diff;
|
---|
365 | }
|
---|
366 | if (minDiff > diff) {
|
---|
367 | minDiff = diff;
|
---|
368 | setPano = links[k];
|
---|
369 | }
|
---|
370 | // console.log(links[k].description + " " + k + ": " + linkBearing + " minus " + povHead + " = " + (linkBearing - povHead) + ", mindiff is " + minDiff);
|
---|
371 |
|
---|
372 | }
|
---|
373 | //console.log("Picked " + setPano + '\n');
|
---|
374 | finalMethod(setPano);
|
---|
375 | return setPano;
|
---|
376 | }
|
---|
377 |
|
---|