Custom Street View Panoramas

This example displays a custom panorama of the Google Sydney office. Note that this example doesn't use a map or default Street View imagery.

Read the documentation .

TypeScript

 function 
  
 initPano 
 () 
  
 { 
  
 // Set up Street View and initially set it visible. Register the 
  
 // custom panorama provider function. Set the StreetView to display 
  
 // the custom panorama 'reception' which we check for below. 
  
 const 
  
 panorama 
  
 = 
  
 new 
  
 google 
 . 
 maps 
 . 
 StreetViewPanorama 
 ( 
  
 document 
 . 
 getElementById 
 ( 
 "map" 
 ) 
  
 as 
  
 HTMLElement 
 , 
  
 { 
  
 pano 
 : 
  
 "reception" 
 , 
  
 visible 
 : 
  
 true 
  
 } 
  
 ); 
  
 panorama 
 . 
 registerPanoProvider 
 ( 
 getCustomPanorama 
 ); 
 } 
 // Return a pano image given the panoID. 
 function 
  
 getCustomPanoramaTileUrl 
 ( 
  
 pano 
 : 
  
 string 
 , 
  
 zoom 
 : 
  
 number 
 , 
  
 tileX 
 : 
  
 number 
 , 
  
 tileY 
 : 
  
 number 
 ) 
 : 
  
 string 
  
 { 
  
 return 
  
 ( 
  
 "https://developers.google.com/maps/documentation/javascript/examples/full/images/" 
  
 + 
  
 "panoReception1024-" 
  
 + 
  
 zoom 
  
 + 
  
 "-" 
  
 + 
  
 tileX 
  
 + 
  
 "-" 
  
 + 
  
 tileY 
  
 + 
  
 ".jpg" 
  
 ); 
 } 
 // Construct the appropriate StreetViewPanoramaData given 
 // the passed pano IDs. 
 function 
  
 getCustomPanorama 
 ( 
 pano 
 : 
  
 string 
 ) 
 : 
  
 google 
 . 
 maps 
 . 
 StreetViewPanoramaData 
  
 { 
  
 if 
  
 ( 
 pano 
  
 === 
  
 "reception" 
 ) 
  
 { 
  
 return 
  
 { 
  
 location 
 : 
  
 { 
  
 pano 
 : 
  
 "reception" 
 , 
  
 description 
 : 
  
 "Google Sydney - Reception" 
 , 
  
 }, 
  
 links 
 : 
  
 [], 
  
 // The text for the copyright control. 
  
 copyright 
 : 
  
 "Imagery (c) 2010 Google" 
 , 
  
 // The definition of the tiles for this panorama. 
  
 tiles 
 : 
  
 { 
  
 tileSize 
 : 
  
 new 
  
 google 
 . 
 maps 
 . 
 Size 
 ( 
 1024 
 , 
  
 512 
 ), 
  
 worldSize 
 : 
  
 new 
  
 google 
 . 
 maps 
 . 
 Size 
 ( 
 2048 
 , 
  
 1024 
 ), 
  
 // The heading in degrees at the origin of the panorama 
  
 // tile set. 
  
 centerHeading 
 : 
  
 105 
 , 
  
 getTileUrl 
 : 
  
 getCustomPanoramaTileUrl 
 , 
  
 }, 
  
 }; 
  
 } 
  
 // @ts-ignore TODO fix typings 
  
 return 
  
 null 
 ; 
 } 
 declare 
  
 global 
  
 { 
  
 interface 
  
 Window 
  
 { 
  
 initPano 
 : 
  
 () 
  
 = 
>  
 void 
 ; 
  
 } 
 } 
 window 
 . 
 initPano 
  
 = 
  
 initPano 
 ; 
  

JavaScript

 function 
  
 initPano 
 () 
  
 { 
  
 // Set up Street View and initially set it visible. Register the 
  
 // custom panorama provider function. Set the StreetView to display 
  
 // the custom panorama 'reception' which we check for below. 
  
 const 
  
 panorama 
  
 = 
  
 new 
  
 google 
 . 
 maps 
 . 
 StreetViewPanorama 
 ( 
  
 document 
 . 
 getElementById 
 ( 
 "map" 
 ), 
  
 { 
  
 pano 
 : 
  
 "reception" 
 , 
  
 visible 
 : 
  
 true 
  
 }, 
  
 ); 
  
 panorama 
 . 
 registerPanoProvider 
 ( 
 getCustomPanorama 
 ); 
 } 
 // Return a pano image given the panoID. 
 function 
  
 getCustomPanoramaTileUrl 
 ( 
 pano 
 , 
  
 zoom 
 , 
  
 tileX 
 , 
  
 tileY 
 ) 
  
 { 
  
 return 
  
 ( 
  
 "https://developers.google.com/maps/documentation/javascript/examples/full/images/" 
  
 + 
  
 "panoReception1024-" 
  
 + 
  
 zoom 
  
 + 
  
 "-" 
  
 + 
  
 tileX 
  
 + 
  
 "-" 
  
 + 
  
 tileY 
  
 + 
  
 ".jpg" 
  
 ); 
 } 
 // Construct the appropriate StreetViewPanoramaData given 
 // the passed pano IDs. 
 function 
  
 getCustomPanorama 
 ( 
 pano 
 ) 
  
 { 
  
 if 
  
 ( 
 pano 
  
 === 
  
 "reception" 
 ) 
  
 { 
  
 return 
  
 { 
  
 location 
 : 
  
 { 
  
 pano 
 : 
  
 "reception" 
 , 
  
 description 
 : 
  
 "Google Sydney - Reception" 
 , 
  
 }, 
  
 links 
 : 
  
 [], 
  
 // The text for the copyright control. 
  
 copyright 
 : 
  
 "Imagery (c) 2010 Google" 
 , 
  
 // The definition of the tiles for this panorama. 
  
 tiles 
 : 
  
 { 
  
 tileSize 
 : 
  
 new 
  
 google 
 . 
 maps 
 . 
 Size 
 ( 
 1024 
 , 
  
 512 
 ), 
  
 worldSize 
 : 
  
 new 
  
 google 
 . 
 maps 
 . 
 Size 
 ( 
 2048 
 , 
  
 1024 
 ), 
  
 // The heading in degrees at the origin of the panorama 
  
 // tile set. 
  
 centerHeading 
 : 
  
 105 
 , 
  
 getTileUrl 
 : 
  
 getCustomPanoramaTileUrl 
 , 
  
 }, 
  
 }; 
  
 } 
  
 // @ts-ignore TODO fix typings 
  
 return 
  
 null 
 ; 
 } 
 window 
 . 
 initPano 
  
 = 
  
 initPano 
 ; 
  

CSS

 /* 
 * Always set the map height explicitly to define the size of the div element 
 * that contains the map. 
 */ 
 # 
 map 
  
 { 
  
 height 
 : 
  
 100 
 % 
 ; 
 } 
 /* 
 * Optional: Makes the sample page fill the window. 
 */ 
 html 
 , 
 body 
  
 { 
  
 height 
 : 
  
 100 
 % 
 ; 
  
 margin 
 : 
  
 0 
 ; 
  
 padding 
 : 
  
 0 
 ; 
 } 
  

HTML

<html>
  <head>
    <title>Custom Street View Panoramas</title>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="map"></div>

    <!-- 
      The `defer` attribute causes the script to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises. See
      https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initPano&v=weekly"
      defer
    ></script>
  </body>
</html>  

Try Sample

Clone Sample

Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

  
  git 
  
 clone 
  
 - 
 b 
  
 sample 
 - 
 streetview 
 - 
 custom 
 - 
 simple 
  
 https 
 : 
 //github.com/googlemaps/js-samples.git 
 
  
  cd 
  
 js 
 - 
 samples 
 
  
  npm 
  
 i 
 
  
  npm 
  
 start 
 

Other samples can be tried by switching to any branch beginning with sample- SAMPLE_NAME .

  
  git 
  
 checkout 
  
 sample 
 - 
  SAMPLE_NAME 
 
 
  
  npm 
  
 i 
 
  
  npm 
  
 start 
 
Create a Mobile Website
View Site in Mobile | Classic
Share by: