Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var geocoo = new google.maps.Geocoder();
- var fenway = new google.maps.LatLng(-37.793237, 175.303775);
- var botswana = new google.maps.LatLng(-20.472393999999998, 24.515585999999995);
- var NewYork = new google.maps.LatLng(40.753497, -73.996356);
- var sandy = new google.maps.LatLng(40.554113, -74.110851);
- var sanFran = new google.maps.LatLng(37.775679, -122.425017);
- var HMSOcelot = new google.maps.LatLng(51.395492, 0.526726);
- var places = {
- hamilton: fenway,
- botswana: botswana,
- newyork: NewYork,
- sandy: sandy,
- sanFran: sanFran,
- submarine: HMSOcelot
- }
- var defaultStart = NewYork;
- $.urlParam = function(name)
- {
- var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
- if (results == null)
- {
- return null;
- }
- else
- {
- return results[1] || 0;
- }
- }
- function appendStatusDisplay(message)
- {
- var text = $("#statusDisplay").html();
- text += "<br>" + message;
- $("#statusDisplay").html(text);
- }
- var startLocation;
- var dataService;
- var panorama;
- var list;
- var place = $.urlParam('place');
- function initialize()
- {
- dataService = new google.maps.StreetViewService();
- if (places[place])
- {
- startLocation = places[place];
- run();
- }
- else if (!!place)
- {
- geocoo.geocode({ address: decodeURIComponent(place) }, function(data, status)
- {
- console.log(data);
- if (!!data[0])
- {
- startLocation = data[0].geometry.location;
- }
- else
- {
- startLocation = defaultStart;
- }
- run();
- });
- }
- else
- {
- startLocation = defaultStart;
- run();
- }
- }
- function run()
- {
- var panoramaOptions = {
- position: startLocation,
- pov: {
- heading: 90,
- pitch: 10,
- zoom: 1
- },
- linksControl: false,
- panControl: false,
- disableDefaultUI: true
- };
- panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), panoramaOptions);
- var map = new google.maps.Map(document.getElementById('map-canvas'));
- map.setStreetView(panorama);
- geocoo.geocode({ address: decodeURIComponent(startLocation) }, function(data, status)
- {
- appendStatusDisplay(data[0].address_components[0].short_name + " " + data[0].address_components[1].short_name);
- appendStatusDisplay(startLocation);
- });
- google.maps.event.addListener(panorama, "pov_changed", function()
- {
- console.log("pov_changed, doStreetView");
- SyncThreeCamera(panorama.getPov().heading, panorama.getPov().pitch);
- });
- google.maps.event.addListener(panorama, "links_changed", function()
- {
- console.log("nuking spheres and creating paths");
- nukeSpheres();
- if (list === undefined)
- {
- list = new PanoListWrapper(new PanoNode(panorama.pano, panorama.getPosition(), panorama.links, panorama.centerHeading));
- }
- list.naiveDisplay(10, list.currentPano);
- });
- google.maps.event.addListener(panorama, "zoom_changed", function()
- {
- camera = cameraFromGoogleZoom(panorama.getZoom());
- SyncThreeCamera(panorama.getPov().heading, panorama.getPov().pitch)
- });
- }
- function PanoListWrapper(firstNode)
- {
- var hashedNodeList = {};
- hashedNodeList[firstNode.panoID] = firstNode;
- this.currentPano = firstNode;
- this.getNodeList = function()
- {
- return hashedNodeList;
- }
- this.setCurrentPano = function(newPano)
- {
- currentPano = newPano;
- if(!hashedNodeList.hasOwnProperty(newPano.panoID))
- {//probably not needed, but doesn't hurt to be safe
- hashedNodeList[newPano.panoID] = newPano;
- }
- }
- this.naiveDisplay = function(count, startNode)
- {//diplay count(integer) nodes along each direction(startNode.getLinks())
- //var startNodeLinks = startNode.getLinks();
- //console.log(startNodeLinks);
- function waitForLinks()
- {
- if(startNode.getLinks()===undefined)
- {
- window.setTimeout(waitForLinks, 50);
- }
- else
- {
- resume();
- }
- }
- function resume()
- {
- for (pathStartID in startNode.getLinks())
- {
- var currentStep = hashedNodeList[pathStartID];
- var newStep = currentStep;
- for (var i = 0; i < count; i++)
- {
- function resumeDraw()
- {
- createPanoSphere(google.maps.geometry.spherical.computeHeading(startNode.position, currentStep.position),
- google.maps.geometry.spherical.computeDistanceBetween(startNode.position, currentStep.position),
- currentStep,
- currentStep.centerHeading);
- console.log("debug, forwardNode source1");
- newStep = currentStep.getNextForwardNode(startNode.getLinks()[pathStartID].heading);
- }
- function waitForStep()
- {
- if (newStep === undefined)
- {
- console.log("debug, forwardNode source2");
- console.log(newStep);
- newStep = currentStep.getNextForwardNode(startNode.getLinks()[pathStartID].heading);
- console.log(newStep);
- window.setTimeout(waitForStep, 50);
- }
- else
- {
- console.log("debug, foward node found:");
- console.log(newStep);
- currentStep = newStep;
- resumeDraw();
- }
- }
- waitForStep();
- }
- }
- }
- waitForLinks();
- }
- }
- function PanoNode(panoID, position, newLinks, centerHeading)
- {
- this.sphere;
- this.panoID = panoID;
- this.position = position;
- this.links = {};
- this.centerHeading = centerHeading;
- for (var i = 0; i < newLinks.length; i++)
- {
- this.links[newLinks[i].pano] = null;
- }
- }
- PanoNode.prototype.getLinks = function()
- {//gets all links from this node
- // pulling them from Google if they are not locally available
- // or
- // setting pointers to the correct location if they have already been pulled to local previously
- var waitingForData = 0;
- function decrementWaiting()
- {
- waitingForData--;
- if (waitingForData > 0)
- {
- }
- else
- {
- return this.links;
- }
- }
- for (linkID in this.links)
- {
- if (this.links[linkID] === null)
- {
- if (list.getNodeList.hasOwnProperty(linkID))
- {//node to link to already exists locally
- var linkDistance = google.maps.geometry.spherical.computeDistanceBetween(this.position, list.getNodeList[linkID].position);
- var linkHeading = google.maps.geometry.spherical.computeHeading(this.position, list.getNodeList[linkID].position);
- this.links[linkID] = new PanoLink(linkDistance, linkHeading, linkID, list.getNodeList[linkID]);
- }
- else
- {
- waitingForData++;
- this.links[linkID]=-1;
- (function(position, linkID, links)
- {
- dataService.getPanoramaById(linkID, function(svData, svStatus)
- {
- if (svStatus != "OK")
- {
- alert("svStatus not OK, unable to extend node graph\nCheck connection and Google server status");
- }
- var linkDistance = google.maps.geometry.spherical.computeDistanceBetween(position, svData.location.latLng);
- var linkHeading = google.maps.geometry.spherical.computeHeading(position, svData.location.latLng);
- links[linkID] = new PanoLink(linkDistance, linkHeading, linkID, new PanoNode(linkID, svData.location.latLng, svData.links, svData.tiles.centerHeading));
- decrementWaiting();
- });
- }(this.position, linkID, this.links));
- }
- }
- else if (this.links[linkID] === -1)
- {
- waitingForData++;
- }
- }
- if (waitingForData > 0)
- {
- }
- else
- {
- return this.links;
- }
- }
- PanoNode.prototype.getVisibleLinks = function(heading, viewAngle)//using view angle as distance from center
- {//gets the links the kinect is able to select from
- var visibleLinks = {}
- var allLinks = this.getLinks;
- for (linkID in Object.keys(allLinks))
- {
- if(allLinks[linkID].heading>viewAngle+heading||allLinks[linkID].heading<=viewAngle+heading)
- {
- visibleLinks[linkID] = allLinks[linkID];
- }
- }
- return visibleLinks;
- }
- PanoNode.prototype.getNextForwardNode = function(direction)
- {
- var context = this;
- var bestMatch;
- var bestMatchValue=361;//heading in degrees, 361 should always be above maximum value
- //var allLinks = this.getLinks();
- function waitForLinks()
- {
- if (context.getLinks() === undefined)
- {
- window.setTimeout(waitForLinks, 50);
- }
- else
- {
- return resume();
- }
- }
- function resume()
- {
- for (currentLink in context.getLinks())
- {
- console.log("debug, findNextForward from " + currentLink);
- var testCost = Math.abs(context.getLinks()[currentLink].heading - direction);
- if(testCost<bestMatchValue)
- {
- bestMatchValue=testCost;
- bestMatch=currentLink;
- }
- }
- console.log("debug, findNextForward result " + bestMatch);
- console.log(context.getLinks()[bestMatch].getNode());
- return context.getLinks()[bestMatch].getNode();
- }
- waitForLinks();
- }
- function PanoLink(distance, heading, linkID, newPanoNode)
- {
- this.distance = distance;
- this.heading = heading;
- this.node = linkID;
- if (!list.getNodeList().hasOwnProperty(linkID))
- {
- list.getNodeList()[linkID] = newPanoNode;
- }
- }
- PanoLink.prototype.getNode = function()
- {
- return list.getNodeList()[this.node];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement