I realized that GraphicsMagick offers a simple way to prepare images for Streetview. The software runs on a large number of operating systems. An alternative is ImageMagick.
Tutorial based on Maps Javascript API V3
Example prerequisite
Panorama image my_panorama.jpg
, sized 18432×9216 px (360° horizontally, 180°
vertically), stitched with ICE.
Example definitions
Creation of tiles
Unix command line (on Windows/DOS, replace cp
by copy
):
cp my_panorama.jpg tile_0_0.jpg
gm convert panorama.jpg -crop 9216x4608 tile_1_%d.jpg
gm convert panorama.jpg -crop 4608x2304 tile_2_%d.jpg
gm convert panorama.jpg -crop 2304x1152 tile_3_%d.jpg
gm convert panorama.jpg -crop 1152x576 tile_4_%d.jpg
gm mogrify -size 1152x576 -resize 1152x576 +profile "tile_*_*.jpg"
Tool for displaying panorama with Streetview
Just copy&paste this code. To view the panorama with Google Streetview, simply open the file index.html
(see below) in a modern web browser.
index.html
:
<!DOCTYPE html>
<html>
<head>
<title>My panorama</title>
<meta charset="utf-8">
<link href="index.css" rel="stylesheet">
<script
src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
</script>
<script src="index.js"></script>
</head>
<body>
<div id="panorama"></div>
</body>
</html>
index.css
:
html, body, #panorama {
height: 100%;
margin: 0;
padding: 0;
}
index.js
:
function initialize() {
var panoOptions = {
pano: 'myPanorama',
visible: true,
panoProvider: getCustomPanorama
};
var panorama = new google.maps.StreetViewPanorama(
document.getElementById('panorama'), panoOptions);
}
function getCustomPanoramaTileUrl(pano, zoom, tileX, tileY) {
var n = tileY * Math.pow(2, zoom) + tileX;
return 'tile_' + zoom + '_' + n + '.jpg';
}
function getCustomPanorama(pano, zoom, tileX, tileY) {
if (pano === 'myPanorama') {
return {
tiles: {
tileSize: new google.maps.Size(1152, 576),
worldSize: new google.maps.Size(18432, 9216),
centerHeading: 105,
getTileUrl: getCustomPanoramaTileUrl
}
};
}
}
google.maps.event.addDomListener(window, 'load', initialize);
Further reading
Google's tutorial "Providing Custom StreetView Panoramas"