Me gustaría agregar una etiqueta aria en un objeto marcador. Actualmente tengo una función que carga todos los marcadores y quiero poner una etiqueta aria como propiedad del marcador. Actualmente estoy poniendo la etiqueta aria como una propiedad cuando creo el objeto marcador, pero creo que esto puede estar mal. ¿Cómo podría agregar una etiqueta aria a un marcador?
loadLocationMarkers({ lat, lng }, idx) { const markerIcon = this.createIcon(idx); const markerObj = new google.maps.Marker({ icon: markerIcon, index: idx, selected: idx === this.selected, map: this.map, position: new google.maps.LatLng(lat, lng), optimized: false, zIndex: this.calculateZIndex(idx), 'aria-label': 'Location Marker', }); if (markerObj.selected) { this.selectedMarkerObj = markerObj; } markerObj.addListener('click', () => { const index = markerObj.get('index'); this.dispatch(updateSelected(index), this.handleClick(markerObj)); }); return markerObj; }Use el title que establecerá la aria-label .
https://developers.google.com/maps/documentation/javascript/reference/marker#MarkerOptions.title
new google.maps.Marker({ icon: markerIcon, index: idx, selected: idx === this.selected, map: this.map, position: new google.maps.LatLng(lat, lng), optimized: false, zIndex: this.calculateZIndex(idx), title: 'Location Marker', // <--- added this }); De la salida de la muestra de marcadores simples con title="Hello World!" .
<div aria-label="Hello World!" role="img" tabindex="-1" ... > <img ... /><map ><area tabindex="-1" title="Hello World!" ... /></map> </div>Nota :
tabindexes-1ya que no hay detector de eventos en el marcador.