Skip to content

Commit 300e154

Browse files
authored
feat: Migrates the advanced marker accessibility sample. (#587)
1 parent ce0ac7a commit 300e154

File tree

8 files changed

+211
-0
lines changed

8 files changed

+211
-0
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ jobs:
110110

111111
- name: Commit and Push Changes (to temp branch)
112112
run: |
113+
echo "--- Debugging package-lock.json state ---"
114+
git status --porcelain package-lock.json || true # Show if it's modified
115+
git diff package-lock.json || true # Show actual diff if modified
116+
echo "-------------------------------------"
113117
git add dist/ package-lock.json
114118
if [ -z "$(git status --porcelain)" ]; then
115119
echo "No changes to commit"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Google Maps JavaScript Sample
2+
3+
This sample is generated from @googlemaps/js-samples located at
4+
https://github.com/googlemaps-samples/js-api-samples.
5+
6+
## Setup
7+
8+
### Before starting run:
9+
10+
`npm i`
11+
12+
### Run an example on a local web server
13+
14+
First `cd` to the folder for the sample to run, then:
15+
16+
`npm start`
17+
18+
### Build an individual example
19+
20+
From `samples/`:
21+
22+
`npm run build --workspace=sample-name/`
23+
24+
### Build all of the examples.
25+
26+
From `samples/`:
27+
28+
`npm run build-all`
29+
30+
## Feedback
31+
32+
For feedback related to this sample, please open a new issue on
33+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
{% spaceless %}{% include "maps/documentation/javascript/examples/full/_apikey.html" %}{% endspaceless %}<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
6+
<meta charset="utf-8">
7+
<title>Make markers clickable and accessible.</title>
8+
<style>
9+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-accessibility/style.css" region_tag="maps_advanced_markers_accessibility" html_escape="False" %}
10+
</style>
11+
</head>
12+
<body>
13+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-accessibility/index.html" region_tag="maps_advanced_markers_accessibility_body" html_escape="False" %}
14+
{{ api_loader_dynamic }}
15+
<script>
16+
{% includecode content_path="maps/documentation/javascript/examples/samples/advanced-markers-accessibility/index.js" region_tag="maps_advanced_markers_accessibility" html_escape="False" %}
17+
</script>
18+
</body>
19+
</html>
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 2019 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_advanced_markers_accessibility] -->
8+
<html>
9+
<head>
10+
<title>Advanced Marker Accessibility</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: "beta"});</script>
21+
</body>
22+
</html>
23+
<!-- [END maps_advanced_markers_accessibility] -->
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_advanced_markers_accessibility]
8+
async function initMap() {
9+
// Request needed libraries.
10+
const { Map, InfoWindow } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
11+
const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
12+
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+
19+
// Set LatLng and title text for the markers. The first marker (Boynton Pass)
20+
// receives the initial focus when tab is pressed. Use arrow keys to move
21+
// between markers; press tab again to cycle through the map controls.
22+
const tourStops = [
23+
{
24+
position: { lat: 34.8791806, lng: -111.8265049 },
25+
title: "Boynton Pass"
26+
},
27+
{
28+
position: { lat: 34.8559195, lng: -111.7988186 },
29+
title: "Airport Mesa"
30+
},
31+
{
32+
position: { lat: 34.832149, lng: -111.7695277 },
33+
title: "Chapel of the Holy Cross"
34+
},
35+
{
36+
position: { lat: 34.823736, lng: -111.8001857 },
37+
title: "Red Rock Crossing"
38+
},
39+
{
40+
position: { lat: 34.800326, lng: -111.7665047 },
41+
title: "Bell Rock"
42+
},
43+
];
44+
45+
// Create an info window to share between markers.
46+
const infoWindow = new InfoWindow();
47+
48+
// Create the markers.
49+
tourStops.forEach(({position, title}, i) => {
50+
const pin = new PinElement({
51+
glyph: `${i + 1}`,
52+
scale: 1.5,
53+
});
54+
// [START maps_advanced_markers_accessibility_marker]
55+
const marker = new AdvancedMarkerElement({
56+
position,
57+
map,
58+
title: `${i + 1}. ${title}`,
59+
content: pin.element,
60+
gmpClickable: true,
61+
});
62+
// [END maps_advanced_markers_accessibility_marker]
63+
// [START maps_advanced_markers_accessibility_event_listener]
64+
// Add a click listener for each marker, and set up the info window.
65+
marker.addListener('click', ({ domEvent, latLng }) => {
66+
const { target } = domEvent;
67+
infoWindow.close();
68+
infoWindow.setContent(marker.title);
69+
infoWindow.open(marker.map, marker);
70+
});
71+
// [END maps_advanced_markers_accessibility_event_listener]
72+
});
73+
}
74+
75+
initMap();
76+
// [END maps_advanced_markers_accessibility]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/advanced-markers-accessibility",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh advanced-markers-accessibility && bash ../app.sh advanced-markers-accessibility && bash ../docs.sh advanced-markers-accessibility && npm run build:vite --workspace=. && bash ../dist.sh advanced-markers-accessibility",
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_advanced_markers_accessibility] */
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_advanced_markers_accessibility] */
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)