Skip to content

Commit fc1f14b

Browse files
authored
Add addtl. marker samples and accessibility sample (#330)
1 parent 72bde37 commit fc1f14b

File tree

15 files changed

+510
-0
lines changed

15 files changed

+510
-0
lines changed
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_accessibility_features] -->
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_accessibility_features] -->
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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_accessibility_features]
9+
async function initMap() {
10+
const { Map3DElement, Marker3DInteractiveElement, PopoverElement } = await google.maps.importLibrary("maps3d");
11+
const { PinElement } = await google.maps.importLibrary("marker");
12+
13+
const map = new Map3DElement({
14+
center: { lat: 34.8405, lng : -111.7909, altitude: 1322.70 }, range: 13279.50, tilt: 67.44 ,heading: 0.01,
15+
mode: 'SATELLITE'
16+
});
17+
18+
// Set LatLng and title text for the markers. The first marker (Boynton Pass)
19+
// receives the initial focus when tab is pressed. Use arrow keys to move
20+
// between markers; press tab again to cycle through the map controls.
21+
const tourStops = [
22+
{
23+
position: { lat: 34.8791806, lng: -111.8265049 },
24+
title: "Boynton Pass",
25+
},
26+
{
27+
position: { lat: 34.8559195, lng: -111.7988186 },
28+
title: "Airport Mesa",
29+
},
30+
{
31+
position: { lat: 34.832149, lng: -111.7695277 },
32+
title: "Chapel of the Holy Cross",
33+
},
34+
{
35+
position: { lat: 34.823736, lng: -111.8001857 },
36+
title: "Red Rock Crossing",
37+
},
38+
{
39+
position: { lat: 34.800326, lng: -111.7665047 },
40+
title: "Bell Rock",
41+
},
42+
];
43+
44+
tourStops.forEach(({ position, title }, i) => {
45+
const pin = new PinElement({
46+
glyph: `${i + 1}`,
47+
scale: 1.5,
48+
glyphColor: "#FFFFFF"
49+
});
50+
const popover = new PopoverElement({
51+
open: true,
52+
});
53+
54+
const content = `${i + 1}. ${title}`;
55+
const header = document.createElement('span');
56+
// Include the label for screen readers.
57+
header.ariaLabel = `This is marker ${i + 1}. ${title}`;
58+
header.slot = 'header';
59+
60+
popover.append(header);
61+
popover.append(content);
62+
63+
const interactiveMarker = new Marker3DInteractiveElement({
64+
position,
65+
gmpPopoverTargetElement: popover
66+
});
67+
68+
interactiveMarker.append(pin);
69+
70+
map.append(interactiveMarker);
71+
map.append(popover);
72+
});
73+
74+
document.body.append(map);
75+
}
76+
77+
initMap();
78+
// [END maps_3d_accessibility_features]
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-accessibility-features",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh 3d-accessibility-features && bash ../app.sh 3d-accessibility-features && bash ../docs.sh 3d-accessibility-features && npm run build:vite --workspace=. && bash ../dist.sh 3d-accessibility-features",
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_accessibility_features] */
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_accessibility_features] */
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+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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_marker_collision_behavior] -->
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+
22+
<div class="detailsContainer">
23+
<label for="collisionSelect">Marker Collision behavior.</label>
24+
<select id="collisionSelect" >
25+
<option value="REQUIRED">REQUIRED</option>
26+
<option value="REQUIRED_AND_HIDES_OPTIONAL">REQUIRED_AND_HIDES_OPTIONAL</option>
27+
<option value="OPTIONAL_AND_HIDES_LOWER_PRIORITY">OPTIONAL_AND_HIDES_LOWER_PRIORITY</option>
28+
</select>
29+
<div style="font-size: 0.7em; width:500px;">
30+
<b>REQUIRED:</b> (default) Always display the marker regardless of collision.<br>
31+
<b>OPTIONAL_AND_HIDES_LOWER_PRIORITY:</b> Display the marker only if it does not overlap with other markers. If two markers of this type would overlap, the one with the higher zIndex is shown. If they have the same zIndex, the one with the lower vertical screen position is shown.<br>
32+
<b>REQUIRED_AND_HIDES_OPTIONAL:</b> Always display the marker regardless of collision, and hide any OPTIONAL_AND_HIDES_LOWER_PRIORITY markers or labels that would overlap with the marker.<br>
33+
</div>
34+
</div>
35+
36+
<div class="textContainer">
37+
<div class="text">Select the marker collision method.</div>
38+
</div>
39+
</body>
40+
</html>
41+
<!-- [END maps_3d_marker_collision_behavior] -->
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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_marker_collision_behavior]
9+
let map;
10+
async function init() {
11+
// Request needed libraries.
12+
const { Map3DElement, Marker3DElement } = await google.maps.importLibrary("maps3d");
13+
14+
map = new Map3DElement({
15+
center: { lat: 47.6094, lng: -122.3390, altitude: 0 },
16+
range: 1000,
17+
mode: 'HYBRID'
18+
});
19+
20+
map.mode = "SATELLITE";
21+
let zindex = 0;
22+
for (const [lng, lat] of positions) {
23+
const marker = new Marker3DElement({
24+
position: { lat, lng },
25+
// Try setting a different collision behavior here.
26+
collisionBehavior: google.maps.CollisionBehavior.REQUIRED,
27+
drawsWhenOccluded : true,
28+
zIndex : zindex++,
29+
label: zindex.toString(),
30+
});
31+
map.append(marker);
32+
}
33+
34+
const collisionSelect = document.getElementById('collisionSelect');
35+
collisionSelect.addEventListener('change', handleCollisionSelection);
36+
document.body.append(map);
37+
}
38+
39+
function handleCollisionSelection() {
40+
const selectedIndex = collisionSelect.selectedIndex;
41+
for (const marker of map.getElementsByTagName("gmp-marker-3d")) {
42+
marker.collisionBehavior = collisionSelect.value;
43+
}
44+
}
45+
46+
const positions = [
47+
[-122.3402, 47.6093],
48+
[-122.3402, 47.6094],
49+
[-122.3403, 47.6094],
50+
[-122.3384, 47.6098],
51+
[-122.3389, 47.6095],
52+
[-122.3396, 47.6095],
53+
[-122.3379, 47.6097],
54+
[-122.3378, 47.6097],
55+
[-122.3396, 47.6091],
56+
[-122.3383, 47.6089],
57+
[-122.3379, 47.6093],
58+
[-122.3381, 47.6095],
59+
[-122.3378, 47.6095],
60+
];
61+
62+
init();
63+
64+
// [END maps_3d_marker_collision_behavior]
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-collision-behavior",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh 3d-marker-collision-behavior && bash ../app.sh 3d-marker-collision-behavior && bash ../docs.sh 3d-marker-collision-behavior && npm run build:vite --workspace=. && bash ../dist.sh 3d-marker-collision-behavior",
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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_3d_marker_collision_behavior] */
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+
.textContainer {
20+
background-color: #4d90fe;
21+
box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3);
22+
margin: 10px;
23+
overflow: hidden;
24+
position: absolute;
25+
left: 50%;
26+
bottom: 5px;
27+
transform: translateX(-50%);
28+
border: 1px solid white;
29+
border-radius: 2px;
30+
padding: 5px;
31+
z-index: 1000;
32+
}
33+
34+
.detailsContainer {
35+
background-color: #fff;
36+
box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3);
37+
margin: 10px;
38+
font: 400 18px Roboto, Arial, sans-serif;
39+
overflow: hidden;
40+
position: absolute;
41+
left: 50%;
42+
bottom: 50px;
43+
transform: translateX(-50%);
44+
border: 2px solid #4d90fe;
45+
border-radius: 2px;
46+
padding: 5px;
47+
z-index: 1000;
48+
}
49+
50+
.text {
51+
color: white;
52+
font-size: 1em;
53+
text-align: center;
54+
}
55+
/* [END maps_3d_marker_collision_behavior] */
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+
}

0 commit comments

Comments
 (0)