Created
September 17, 2012 22:56
-
-
Save YenTheFirst/3740290 to your computer and use it in GitHub Desktop.
custom art streetview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> | |
<script> | |
panorama_sets = { | |
'blue': { | |
'description': 'blue desc', | |
'baseUrl': 'terrible_room.png', | |
'centerHeading': 0, | |
'latLng': new google.maps.LatLng(37.7871837, -122.4002961), | |
'links': [ | |
{ | |
'heading': 90, | |
'pano': 'green', | |
'description': 'green' | |
} | |
], | |
'outdoorLinks': [ | |
{ | |
'heading': 50, | |
'description': 'new montgomery' | |
} | |
] | |
}, | |
'green': { | |
'description': 'green desc', | |
'baseUrl': 'green_room.png', | |
'centerHeading': 0, | |
'latLng': new google.maps.LatLng(37.7650501, -122.4196959), | |
'links': [ | |
{ | |
'heading': 270, | |
'pano': 'blue', | |
'description': 'blue' | |
} | |
], | |
'outdoorLinks': [ | |
{ | |
'heading': 90, | |
'description': '16th & mission' | |
} | |
] | |
} | |
} | |
function setDefaults(dataSet) { | |
for (var key in dataSet) { | |
if (!dataSet.hasOwnProperty(key)){ | |
continue; | |
} | |
var data = dataSet[key]; | |
if (!('location' in data)){ | |
data.location = { | |
'description': data.description, | |
'latLng': data.latLng, | |
'pano': key | |
}; | |
} | |
if (!('links' in data)){ | |
data.links = []; | |
} | |
if (!('tiles' in data)){ | |
data.tiles = { | |
'centerHeading': data.centerHeading, | |
'tileSize': new google.maps.Size(1024, 512), | |
'worldSize': new google.maps.Size(1024, 512), | |
'getTileUrl': getCustomPanoramaTileUrl | |
}; | |
} | |
} | |
} | |
outstanding_calls = 0 | |
function searchOutdoorLink(key, data, link, outside_location, outdoorLinks) { | |
var client = new google.maps.StreetViewService(); | |
var searchRadius=50; | |
outstanding_calls++; | |
client.getPanoramaByLocation(outside_location, searchRadius, function(result, status) { | |
if (status == google.maps.StreetViewStatus.OK) { | |
console.log("got result for "+key + "/"+link.description); | |
var outside_pano = result.location.pano; | |
if (!(outside_pano in outdoorLinks)) { | |
outdoorLinks[outside_pano] = [] | |
} | |
outdoorLinks[outside_pano].push({ | |
'heading': (link.heading-180) % 360, | |
'description': data.description, | |
'pano': key | |
}); | |
data.links.push({ | |
'heading': link.heading, | |
'description': link.description, | |
'pano': outside_pano | |
}) | |
link.pano = outside_pano; | |
} | |
outstanding_calls--; | |
}); | |
} | |
function setOutdoorLinks(dataSet) { | |
var outdoorLinks = {}; | |
for (var key in dataSet) { | |
if (!dataSet.hasOwnProperty(key)){ | |
continue; | |
} | |
var data = dataSet[key]; | |
if ('outdoorLinks' in data) { | |
console.log("setting outdoor for "+key); | |
var outgoing = data['outdoorLinks'] | |
for (var i=0; i<outgoing.length; i++) { | |
var link = outgoing[i]; | |
searchOutdoorLink(key, data, link, link.latLng||data.latLng, outdoorLinks) | |
} | |
} | |
} | |
//while (outstanding_calls > 0) {}; | |
return outdoorLinks; | |
} | |
function initialize() { | |
console.log("init called"); | |
setDefaults(panorama_sets); | |
outdoorLinks = setOutdoorLinks(panorama_sets); | |
var panoOptions = { | |
pano: 'blue', | |
visible: true, | |
panoProvider: getCustomPanorama | |
}; | |
panorama = new google.maps.StreetViewPanorama( | |
document.getElementById('pano_canvas'), panoOptions); | |
google.maps.event.addListener(panorama, 'links_changed', createCustomLinks); | |
} | |
function getCustomPanoramaTileUrl(pano, zoom, tileX, tileY) { | |
console.log("get url called with: " + pano + zoom + tileX + tileY); | |
return "http://localhost:8000/"+panorama_sets[pano].baseUrl | |
} | |
function getCustomPanorama(pano, zoom, tileX, tileY) { | |
console.log("get custom called with: " + pano + zoom + tileX + tileY); | |
var data = panorama_sets[pano] | |
console.log(data); | |
return data; | |
} | |
function createCustomLinks() { | |
var links = panorama.getLinks(); | |
var panoId = panorama.getPano(); | |
if (panoId in outdoorLinks){ | |
backlinks = outdoorLinks[panoId]; | |
for (var i=0; i<backlinks.length; i++) { | |
links.push(backlinks[i]); | |
} | |
} | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
</script> | |
</head> | |
<body> | |
<div id="pano_canvas" style="width: 1024px; height: 512px"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment