Skip to content

Commit 93f2e8a

Browse files
Add 3d samples (#289)
* Add 3d samples First round of updates * Update index.html * Update index.html * Update index.html * Moved 3d samples directories * updated region tags * Update playwright.config.ts * Update playwright.config.ts --------- Co-authored-by: William French <[email protected]>
1 parent 2c0eeec commit 93f2e8a

File tree

31 files changed

+789
-0
lines changed

31 files changed

+789
-0
lines changed

samples/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Map</title>
5+
6+
<link rel="stylesheet" type="text/css" href="./style.css" />
7+
<script type="module" src="./index.js"></script>
8+
</head>
9+
<body>
10+
<div id="map"></div>
11+
12+
<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))})
13+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "alpha",});</script>
14+
</body>
15+
</html>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* * https://www.apache.org/licenses/LICENSE-2.0
8+
* * Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
// @ts-nocheck
16+
// [START maps_3d_marker_customization]
17+
async function init() {
18+
const { Map3DElement, Marker3DElement } = await google.maps.importLibrary("maps3d");
19+
const { PinElement } = await google.maps.importLibrary("marker");
20+
21+
const map = new Map3DElement({
22+
center: { lat: 37.4176, lng: -122.02, altitude: 0 },
23+
tilt: 67.5,
24+
range: 7000,
25+
mode: 'HYBRID'
26+
});
27+
28+
map.mode = "SATELLITE";
29+
30+
// Change the border color.
31+
const pinBorder = new PinElement({
32+
borderColor: '#FFFFFF',
33+
});
34+
const markerWithBorder = new Marker3DElement({
35+
position: { lat: 37.415, lng: -122.035 },
36+
});
37+
markerWithBorder.append(pinBorder);
38+
39+
// Add a label.
40+
const markerWithLabel = new Marker3DElement({
41+
position: { lat: 37.419, lng: -122.03 },
42+
label: 'Simple label'
43+
});
44+
45+
// Adjust the scale.
46+
const pinScaled = new PinElement({
47+
scale: 1.5,
48+
});
49+
const markerWithScale = new Marker3DElement({
50+
position: { lat: 37.419, lng: -122.02 },
51+
});
52+
markerWithScale.append(pinScaled);
53+
54+
// Change the glyph color.
55+
const pinGlyph = new PinElement({
56+
glyphColor: 'white',
57+
});
58+
const markerWithGlyphColor = new Marker3DElement({
59+
position: { lat: 37.415, lng: -122.025 },
60+
});
61+
markerWithGlyphColor.append(pinGlyph);
62+
63+
// Change many elements together and extrude marker.
64+
const pinTextGlyph = new PinElement({
65+
background: '#F0F6FC',
66+
glyph: 'E',
67+
glyphColor: 'red',
68+
borderColor: '#0000FF',
69+
});
70+
const markerWithGlyphText = new Marker3DElement({
71+
position: { lat: 37.415, lng: -122.015, altitude: 50 },
72+
extruded: true,
73+
altitudeMode: "RELATIVE_TO_GROUND",
74+
});
75+
markerWithGlyphText.append(pinTextGlyph);
76+
77+
// Hide the glyph.
78+
const pinNoGlyph = new PinElement({
79+
glyph: '',
80+
});
81+
const markerWithNoGlyph = new Marker3DElement({
82+
position: { lat: 37.415, lng: -122.005 },
83+
});
84+
markerWithNoGlyph.append(pinNoGlyph);
85+
86+
// Change the background color.
87+
const pinBackground = new PinElement({
88+
background: '#FBBC04',
89+
});
90+
91+
const markerWithBackground = new Marker3DElement({
92+
position: { lat: 37.419, lng: -122.01 },
93+
});
94+
markerWithBackground.append(pinBackground);
95+
96+
map.append(markerWithLabel);
97+
map.append(markerWithScale);
98+
map.append(markerWithBackground);
99+
map.append(markerWithBorder);
100+
map.append(markerWithGlyphColor);
101+
map.append(markerWithGlyphText);
102+
map.append(markerWithNoGlyph);
103+
104+
document.body.append(map);
105+
}
106+
107+
init();
108+
// [END maps_3d_marker_customization]
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-marker-customization",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh 3d-marker-customization && bash ../app.sh 3d-marker-customization && bash ../docs.sh 3d-marker-customization && npm run build:vite --workspace=. && bash ../dist.sh 3d-marker-customization",
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* * https://www.apache.org/licenses/LICENSE-2.0
8+
* * Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
/* [START maps_3d_marker_customization] */
15+
/* * Always set the map height explicitly to define the size of the div element
16+
* that contains the map.
17+
*/
18+
html,
19+
map {
20+
height: 100%;
21+
}
22+
body {
23+
height: 100%;
24+
margin: 0;
25+
padding: 0;
26+
}
27+
/* [END maps_3d_marker_customization] */
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-places/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Map</title>
5+
6+
<link rel="stylesheet" type="text/css" href="./style.css" />
7+
<script type="module" src="./index.js"></script>
8+
</head>
9+
<body>
10+
<div id="map"></div>
11+
12+
<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))})
13+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "alpha",});</script>
14+
<div id="details" class="detailsContainer">
15+
<div id="placeName"></div>
16+
<div id="placeId"></div>
17+
<div id="placeType"></div>
18+
</div>
19+
<div class="textContainer">
20+
<div class="text">Click on a place to get details.</div>
21+
</div>
22+
</body>
23+
</html>

samples/3d-places/index.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* * https://www.apache.org/licenses/LICENSE-2.0
8+
* * Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
//@ts-nocheck
15+
// [START maps_3d_places]
16+
let map3DElement = null;
17+
async function init() {
18+
const { Map3DElement } = await google.maps.importLibrary("maps3d");
19+
{ }
20+
map3DElement = new Map3DElement({
21+
center: { lat: 51.532, lng : -0.124, altitude: 30 },
22+
range: 1400,
23+
tilt: 64,
24+
heading: -5,
25+
mode: 'HYBRID'
26+
});
27+
28+
document.body.append(map3DElement);
29+
30+
map3DElement.addEventListener('gmp-click', async (event) => {
31+
if (event.placeId) {
32+
const place = await event.fetchPlace();
33+
await place.fetchFields({ fields: ['*'] });
34+
35+
// Display place details.
36+
document.getElementById("placeName").innerHTML = "<b>Name :</b><br>&nbsp;" + place.displayName;
37+
document.getElementById("placeId").innerHTML = "<b>Id :</b><br>&nbsp;" + place.id;
38+
document.getElementById("placeType").innerHTML = "<b>Types :<b/>";
39+
40+
for (const type of place.types) {
41+
document.getElementById("placeType").innerHTML += "<br>&nbsp;" + type ;
42+
}
43+
44+
document.getElementById("details").style.display = "block";
45+
}
46+
});
47+
48+
}
49+
init();
50+
// [END maps_3d_places]

samples/3d-places/package.json

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-places",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh 3d-places && bash ../app.sh 3d-places && bash ../docs.sh 3d-places && npm run build:vite --workspace=. && bash ../dist.sh 3d-places",
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+
}

samples/3d-places/style.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* * https://www.apache.org/licenses/LICENSE-2.0
8+
* * Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
/* [START maps_3d_places] */
15+
/* * Always set the map height explicitly to define the size of the div element
16+
* that contains the map.
17+
*/
18+
html,
19+
body {
20+
height: 100%;
21+
margin: 0;
22+
padding: 0;
23+
font-family: "Centra No2", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
24+
font-size: 0.9em;
25+
}
26+
27+
.textContainer {
28+
background-color: #4d90fe;
29+
margin: 10px;
30+
overflow: hidden;
31+
position: absolute;
32+
left: 50%;
33+
top: 10px;
34+
border: 1px solid white;
35+
border-radius: 10px;
36+
padding: 5px;
37+
z-index: 1000;
38+
color: white;
39+
}
40+
41+
.detailsContainer {
42+
background-color: #00000078;
43+
margin: 10px;
44+
overflow: hidden;
45+
position: absolute;
46+
top: 100px;
47+
left : 10px;
48+
padding: 10px;
49+
z-index: 1000;
50+
display:none;
51+
color: white;
52+
border-radius: 15px;
53+
}
54+
55+
/* [END maps_3d_places] */

0 commit comments

Comments
 (0)