Skip to content

Commit a8a1144

Browse files
authored
feat: Updates marker a11y sample to use gmp-map element. (#822)
* feat: Updates sample to use gmp-map element. Change-Id: I85acd733a5a79b705a0695ba3bf0fca26fadbd20 * Attach marker to mapElement instead of innerMap * Change Google Maps API version from beta to weekly * Remove innerMap variable from initMap function Removed unused innerMap variable from initMap function. * Refactor to use append
1 parent d564802 commit a8a1144

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

samples/advanced-markers-accessibility/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
<link rel="stylesheet" type="text/css" href="./style.css" />
1313
<script type="module" src="./index.js"></script>
14-
</head>
15-
<body>
16-
<div id="map"></div>
1714

1815
<!-- prettier-ignore -->
1916
<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: "beta"});</script>
17+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
18+
</head>
19+
<body>
20+
<gmp-map zoom="12" center="34.84555,-111.8035" map-id="4504f8b37365c3d0"></gmp-map>
2121
</body>
2222
</html>
2323
<!-- [END maps_advanced_markers_accessibility] -->

samples/advanced-markers-accessibility/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
*/
66

77
// [START maps_advanced_markers_accessibility]
8+
const mapElement = document.querySelector('gmp-map') as google.maps.MapElement;
9+
810
async function initMap() {
911
// Request needed libraries.
1012
const { Map, InfoWindow } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
1113
const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
1214

13-
const map = new Map(document.getElementById("map") as HTMLElement, {
14-
zoom: 12,
15-
center: { lat: 34.84555, lng: -111.8035 },
16-
mapId: '4504f8b37365c3d0',
17-
});
18-
1915
// Set LatLng and title text for the markers. The first marker (Boynton Pass)
2016
// receives the initial focus when tab is pressed. Use arrow keys to move
2117
// between markers; press tab again to cycle through the map controls.
@@ -47,19 +43,19 @@ async function initMap() {
4743

4844
// Create the markers.
4945
tourStops.forEach(({position, title}, i) => {
46+
// [START maps_advanced_markers_accessibility_marker]
5047
const pin = new PinElement({
5148
//@ts-ignore
5249
glyphText: `${i + 1}`,
5350
scale: 1.5,
5451
});
55-
// [START maps_advanced_markers_accessibility_marker]
5652
const marker = new AdvancedMarkerElement({
5753
position,
58-
map,
5954
title: `${i + 1}. ${title}`,
60-
content: pin.element,
6155
gmpClickable: true,
6256
});
57+
marker.append(pin);
58+
mapElement.append(marker);
6359
// [END maps_advanced_markers_accessibility_marker]
6460
// [START maps_advanced_markers_accessibility_event_listener]
6561
// Add a click listener for each marker, and set up the info window.
@@ -74,4 +70,4 @@ async function initMap() {
7470
}
7571

7672
initMap();
77-
// [END maps_advanced_markers_accessibility]
73+
// [END maps_advanced_markers_accessibility]

0 commit comments

Comments
 (0)