Skip to content

Commit 660bdb8

Browse files
authored
fix: Updates samples to use correct marker event name. (#1268)
* fix: Updates samples to use correct marker event name. * Add gmpClickable property to AdvancedMarkerElement * Enable marker to be clickable on the map * Enable clickable markers in weather API map
1 parent 7e1be9e commit 660bdb8

5 files changed

Lines changed: 8 additions & 5 deletions

File tree

samples/advanced-markers-accessibility/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function initMap() {
6464
// [END maps_advanced_markers_accessibility_marker]
6565
// [START maps_advanced_markers_accessibility_event_listener]
6666
// Add a click listener for each marker, and set up the info window.
67-
marker.addListener('click', ({ domEvent, latLng }) => {
67+
marker.addEventListener('gmp-click', (domEvent) => {
6868
const { target } = domEvent;
6969
infoWindow.close();
7070
infoWindow.setContent(marker.title);

samples/deckgl-heatmap/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async function initMap(): Promise<void> {
155155
});
156156

157157
// Add click listener to the marker
158-
marker.addListener('click', () => {
158+
marker.addEventListener('gmp-click', () => {
159159
infoWindow.close();
160160
const content = `
161161
<div>Location: ${latLng.lat().toFixed(3)}, ${latLng.lng().toFixed(3)}</div>

samples/event-simple/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async function initMap() {
2424
position: center,
2525
map: innerMap,
2626
title: 'Click to zoom',
27+
gmpClickable: true,
2728
});
2829

2930
innerMap.addListener('center_changed', () => {
@@ -35,7 +36,7 @@ async function initMap() {
3536
});
3637

3738
// Zoom in when the marker is clicked.
38-
marker.addListener('click', () => {
39+
marker.addListener('gmp-click', () => {
3940
innerMap.setZoom(8);
4041
innerMap.setCenter(marker.position as google.maps.LatLng);
4142
});

samples/places-placeid-finder/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ async function initMap(): Promise<void> {
5757
map: map,
5858
collisionBehavior:
5959
google.maps.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL,
60+
gmpClickable: true,
6061
});
6162

62-
marker.addListener('click', () => {
63+
marker.addEventListener('gmp-click', () => {
6364
infowindow.open(map, marker);
6465
});
6566

samples/weather-api-current-compact/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ async function createAndAddMarker(
139139
position: { lat: location.lat, lng: location.lng },
140140
content: weatherWidget,
141141
title: location.name, // Add a title for accessibility
142+
gmpClickable: true,
142143
});
143144

144145
// Store the marker type
@@ -152,7 +153,7 @@ async function createAndAddMarker(
152153
);
153154

154155
// Add click listener to the marker
155-
marker.addListener('click', () => {
156+
marker.addEventListener('gmp-click', () => {
156157
const widgetContainer = weatherWidget.shadowRoot!.querySelector(
157158
'.widget-container'
158159
) as HTMLDivElement;

0 commit comments

Comments
 (0)