Skip to content

Commit ee134b6

Browse files
authored
Added 3d samples (#305)
* Added region tags and prettierignores to 3d html files * Fixed marker html region tag * Added additional 3d samples * updated fly camera to / around sample * Add/modify licenses, update comments, add .ds_store to gitignore and remove said files from PR * delete .ds_store files * revert packagelock
1 parent 4311a49 commit ee134b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1708
-132
lines changed

.DS_Store

-8 KB
Binary file not shown.

samples/.DS_Store

-6 KB
Binary file not shown.

samples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/
33
/playwright-report/
44
/blob-report/
55
/playwright/.cache/
6+
**/.DS_Store
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright 2025 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_3d_camera_to_around] -->
8+
<html>
9+
<head>
10+
<title>Map</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
</head>
15+
<body>
16+
<div id="map"></div>
17+
18+
<!-- prettier-ignore -->
19+
<script>(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))})
20+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "alpha",});</script>
21+
</body>
22+
</html>
23+
<!-- [END maps_3d_camera_to_around] -->
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// @ts-nocheck
8+
// [START maps_3d_camera_to_around]
9+
async function init() {
10+
const { Map3DElement } = await google.maps.importLibrary("maps3d");
11+
12+
const map = new Map3DElement(
13+
{ center: { lat: 37.79810773998413, lng : -122.41784275049939, altitude: 89.08476932205978 }, range: 6062.016931506805, tilt: 81.17100663963272, heading: -56.047035719765596, }
14+
);
15+
16+
map.mode = "SATELLITE";
17+
18+
document.body.append(map);
19+
20+
// Used for both the fly to function and the location to fly around.
21+
const flyToCamera = {
22+
center: { lat: 21.263523536467105, lng : -157.80663691939296, altitude: 80.28936069489404 },
23+
range: 1500.8202963253427, tilt: 76.9173260789542 ,heading: -44.59196007522445,
24+
};
25+
26+
// Fly the camera from San Francisco to Hawaii, can be controlled by a button alternatively.
27+
map.flyCameraTo({
28+
// Where we are going to.
29+
endCamera: flyToCamera,
30+
// How long we want the flight to take.
31+
durationMillis: 30000,
32+
});
33+
34+
// When the animation has completed, fly around the location.
35+
map.addEventListener('gmp-animationend', () => {
36+
map.flyCameraAround({
37+
// Location to fly around.
38+
camera: flyToCamera,
39+
// Length of time to fly to the location.
40+
durationMillis: 50000,
41+
// Number of rotations to make in the specified time.
42+
rounds: 1
43+
});
44+
}, {once: true}); // Stop animation after flying around.
45+
46+
// At any time stop the animation.
47+
map.addEventListener('gmp-click', (event) => {
48+
map.stopCameraAnimation();
49+
});
50+
}
51+
52+
init();
53+
// [END maps_3d_camera_to_around]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/3d-camera-to-around",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh 3d-camera-to-around && bash ../app.sh 3d-camera-to-around && bash ../docs.sh 3d-camera-to-around && npm run build:vite --workspace=. && bash ../dist.sh 3d-camera-to-around",
6+
"test": "tsc && npm run build:vite --workspace=.",
7+
"start": "tsc && vite build --base './' && vite",
8+
"build:vite": "vite build --base './'",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_3d_camera_to_around] */
7+
/* * Always set the map height explicitly to define the size of the div element
8+
* that contains the map.
9+
*/
10+
html,
11+
map {
12+
height: 100%;
13+
}
14+
body {
15+
height: 100%;
16+
margin: 0;
17+
padding: 0;
18+
}
19+
/* [END maps_3d_camera_to_around] */
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"target": "esnext",
5+
"strict": true,
6+
"noImplicitAny": false,
7+
"lib": [
8+
"es2015",
9+
"esnext",
10+
"es6",
11+
"dom",
12+
"dom.iterable"
13+
],
14+
"moduleResolution": "Node",
15+
"jsx": "preserve"
16+
}
17+
}

samples/3d-label-toggle/index.html

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 2025 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_3d_label_toggle] -->
8+
<html>
9+
<head>
10+
<title>Map</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
</head>
15+
<body>
16+
<div id="map"></div>
17+
18+
<button class="toggleButton" id="toggleButton">Labels are off. (SATELLITE)</button>
19+
20+
<!-- prettier-ignore -->
21+
<script>(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))})
22+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "alpha",});</script>
23+
</body>
24+
</html>
25+
<!-- [END maps_3d_label_toggle] -->

samples/3d-label-toggle/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// @ts-nocheck
8+
// [START maps_3d_label_toggle]
9+
let map;
10+
async function init() {
11+
const { Map3DElement, MapMode } = await google.maps.importLibrary("maps3d");
12+
13+
map = new Map3DElement(
14+
{ center: { lat: 37.79810773998413, lng: -122.41784275049939, altitude: 89.08476932205978 }, range: 6062.016931506805, tilt: 81.17100663963272, heading: -56.047035719765596, }
15+
);
16+
17+
map.mode = MapMode.SATELLITE;
18+
19+
document.body.append(map);
20+
21+
const locationCamera = {
22+
center: { lat: 21.263523536467105, lng: -157.80663691939296, altitude: 80.28936069489404 },
23+
range: 1500.8202963253427, tilt: 76.9173260789542, heading: -44.59196007522445,
24+
};
25+
26+
// Get the button element by its ID
27+
const toggleButton = document.getElementById('toggleButton');
28+
toggleButton.addEventListener('click', function () {
29+
// Toggle the labels.
30+
if (map.mode == MapMode.SATELLITE) {
31+
// Setting the map mode to HYBRID turns the labels on.
32+
map.mode = MapMode.HYBRID;
33+
document.getElementById('toggleButton').innerText = "Labels are on. (HYBRID)";
34+
} else {
35+
// Setting the map mode to SATELLITE turns the labels on.
36+
map.mode = MapMode.SATELLITE;
37+
document.getElementById('toggleButton').innerText = "Labels are off. (SATELLITE)";
38+
}
39+
});
40+
}
41+
42+
init();
43+
// [END maps_3d_label_toggle]

0 commit comments

Comments
 (0)