Skip to content

Commit 29d24b5

Browse files
authored
feat: Migrates streetview-custom-simple, updates to latest standards (#1789)
* feat: Migrates streetview-custom-simple to js-api-samples Change-Id: I20db709f9aaaf08a716fc5ca066e395c2b20e1bc * fix: Moves function so that panorama.registerPanoProvider is next to instantiation Change-Id: I6c73cbc5b1e73c9decb26020eb43fc882f57bad1
1 parent 6ba5289 commit 29d24b5

7 files changed

Lines changed: 183 additions & 0 deletions

File tree

‎package-lock.json‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Google Maps JavaScript Sample
2+
3+
## streetview-custom-simple
4+
5+
Custom Street View Panoramas
6+
7+
## Setup
8+
9+
### Before starting run:
10+
11+
`npm i`
12+
13+
### Run an example on a local web server
14+
15+
`cd samples/streetview-custom-simple`
16+
`npm start`
17+
18+
### Build an individual example
19+
20+
`cd samples/streetview-custom-simple`
21+
`npm run build`
22+
23+
From 'samples':
24+
25+
`npm run build --workspace=streetview-custom-simple/`
26+
27+
### Build all of the examples.
28+
29+
From 'samples':
30+
31+
`npm run build-all`
32+
33+
### Run lint to check for problems
34+
35+
`cd samples/streetview-custom-simple`
36+
`npx eslint index.ts`
37+
38+
## Feedback
39+
40+
For feedback related to this sample, please open a new issue on
41+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright 2026 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_streetview_custom_simple] -->
8+
<html>
9+
<head>
10+
<title>Custom Street View Panoramas</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
<script>
15+
// prettier-ignore
16+
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
17+
key: "GOOGLE_MAPS_API_KEY"
18+
});
19+
</script>
20+
</head>
21+
<body>
22+
<div id="map"></div>
23+
</body>
24+
</html>
25+
<!-- [END maps_streetview_custom_simple] -->
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_streetview_custom_simple]
8+
async function init(): Promise<void> {
9+
// Request needed libraries.
10+
const [{ StreetViewPanorama }, { Size }] = await Promise.all([
11+
google.maps.importLibrary('streetView'),
12+
google.maps.importLibrary('core'),
13+
]);
14+
15+
// Construct the appropriate StreetViewPanoramaData given
16+
// the passed pano IDs.
17+
function getCustomPanorama(
18+
pano: string
19+
): google.maps.StreetViewPanoramaData | null {
20+
if (pano === 'reception') {
21+
return {
22+
location: {
23+
pano: 'reception',
24+
description: 'Google Sydney - Reception',
25+
},
26+
links: [],
27+
// The text for the copyright control.
28+
copyright: 'Imagery (c) 2010 Google',
29+
// The definition of the tiles for this panorama.
30+
tiles: {
31+
tileSize: new Size(1024, 512),
32+
worldSize: new Size(2048, 1024),
33+
// The heading in degrees at the origin of the panorama
34+
// tile set.
35+
centerHeading: 105,
36+
getTileUrl: getCustomPanoramaTileUrl,
37+
},
38+
};
39+
}
40+
return null;
41+
}
42+
43+
// Set up Street View and initially set it visible. Register the
44+
// custom panorama provider function. Set the StreetView to display
45+
// the custom panorama 'reception' which we check for below.
46+
const panorama = new StreetViewPanorama(document.getElementById('map')!, {
47+
pano: 'reception',
48+
visible: true,
49+
});
50+
51+
panorama.registerPanoProvider(getCustomPanorama);
52+
}
53+
54+
// Return a pano image given the panoID.
55+
function getCustomPanoramaTileUrl(
56+
pano: string,
57+
zoom: number,
58+
tileX: number,
59+
tileY: number
60+
): string {
61+
return `https://developers.google.com/maps/documentation/javascript/examples/full/images/panoReception1024-${String(zoom)}-${String(tileX)}-${String(tileY)}.jpg`;
62+
}
63+
64+
void init();
65+
// [END maps_streetview_custom_simple]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@js-api-samples/streetview-custom-simple",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "bash ../build-single.sh",
6+
"test": "tsc && npm run build:vite --workspace=.",
7+
"start": "tsc && vite build --config ../../vite.config.js --base './' && vite --config ../../vite.config.js",
8+
"build:vite": "vite build --config ../../vite.config.js --base './'",
9+
"preview": "vite preview --config ../../vite.config.js"
10+
},
11+
"author": "Google LLC"
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_streetview_custom_simple] */
7+
/*
8+
* Always set the map height explicitly to define the size of the div element
9+
* that contains the map.
10+
*/
11+
#map {
12+
height: 100%;
13+
}
14+
15+
/*
16+
* Optional: Makes the sample page fill the window.
17+
*/
18+
html,
19+
body {
20+
height: 100%;
21+
margin: 0;
22+
padding: 0;
23+
}
24+
25+
/* [END maps_streetview_custom_simple] */
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "."
5+
},
6+
"include": ["./*.ts"]
7+
}

0 commit comments

Comments
 (0)