Skip to content

Commit f9f1362

Browse files
committed
Add new event mapfocused
1 parent 27c4862 commit f9f1362

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

src/mapml-viewer.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ export class MapViewer extends HTMLElement {
364364
this.dispatchEvent(new CustomEvent("layerchange", {details:{target: this, originalEvent: e}}));
365365
}
366366
}, false);
367+
368+
this.parentElement.addEventListener('keyup', function (e) {
369+
if(e.keyCode === 9 && document.activeElement.nodeName === "MAPML-VIEWER"){
370+
document.activeElement.dispatchEvent(new CustomEvent('mapfocused', {detail:
371+
{target: this}}));
372+
}
373+
});
374+
this.parentElement.addEventListener('mousedown', function (e) {
375+
if(document.activeElement.nodeName === "MAPML-VIEWER"){
376+
document.activeElement.dispatchEvent(new CustomEvent('mapfocused', {detail:
377+
{target: this}}));
378+
}
379+
});
367380
this._map.on('load',
368381
function () {
369382
this.dispatchEvent(new CustomEvent('load', {detail: {target: this}}));

src/mapml/handlers/AnnounceMovement.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export var AnnounceMovement = L.Handler.extend({
66
});
77

88
this._map.options.mapEl.addEventListener('moveend', this.announceBounds);
9-
this._map.options.mapEl.addEventListener('focus', this.focusAnnouncement);
109
this._map.dragging._draggable.addEventListener('dragstart', this.dragged);
10+
this._map.options.mapEl.addEventListener('mapfocused', this.focusAnnouncement);
1111
},
1212
removeHooks: function () {
1313
this._map.off({
@@ -16,26 +16,32 @@ export var AnnounceMovement = L.Handler.extend({
1616
});
1717

1818
this._map.options.mapEl.removeEventListener('moveend', this.announceBounds);
19-
this._map.options.mapEl.removeEventListener('focus', this.focusAnnouncement);
2019
this._map.dragging._draggable.removeEventListener('dragstart', this.dragged);
20+
this._map.options.mapEl.removeEventListener('mapfocused', this.focusAnnouncement);
2121
},
2222

2323
focusAnnouncement: function () {
24-
let el = this.querySelector(".mapml-web-map") ? this.querySelector(".mapml-web-map").shadowRoot.querySelector(".leaflet-container") :
25-
this.shadowRoot.querySelector(".leaflet-container");
26-
27-
let mapZoom = this._map.getZoom();
28-
let location = M.gcrsToTileMatrix(this);
29-
let standard = " zoom level " + mapZoom + " column " + location[0] + " row " + location[1];
30-
31-
if(mapZoom === this._map._layersMaxZoom){
32-
standard = "At maximum zoom level, zoom in disabled " + standard;
33-
}
34-
else if(mapZoom === this._map._layersMinZoom){
35-
standard = "At minimum zoom level, zoom out disabled " + standard;
36-
}
37-
38-
el.setAttribute("aria-roledescription", "region " + standard);
24+
let mapEl = this;
25+
setTimeout(function (){
26+
let el = mapEl.querySelector(".mapml-web-map") ? mapEl.querySelector(".mapml-web-map").shadowRoot.querySelector(".leaflet-container") :
27+
mapEl.shadowRoot.querySelector(".leaflet-container");
28+
29+
let mapZoom = mapEl._map.getZoom();
30+
let location = M.gcrsToTileMatrix(mapEl);
31+
let standard = " zoom level " + mapZoom + " column " + location[0] + " row " + location[1];
32+
33+
if(mapZoom === mapEl._map._layersMaxZoom){
34+
standard = "At maximum zoom level, zoom in disabled " + standard;
35+
}
36+
else if(mapZoom === mapEl._map._layersMinZoom){
37+
standard = "At minimum zoom level, zoom out disabled " + standard;
38+
}
39+
40+
el.setAttribute("aria-roledescription", "region " + standard);
41+
setTimeout(function () {
42+
el.removeAttribute("aria-roledescription");
43+
}, 2000);
44+
}, 0);
3945
},
4046

4147
announceBounds: function () {

src/web-map.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,19 @@ export class WebMap extends HTMLMapElement {
402402
this.dispatchEvent(new CustomEvent("layerchange", {details:{target: this, originalEvent: e}}));
403403
}
404404
}, false);
405+
406+
this.parentElement.addEventListener('keyup', function (e) {
407+
if(e.keyCode === 9 && document.activeElement.nodeName === "MAPML-VIEWER"){
408+
document.activeElement.dispatchEvent(new CustomEvent('mapfocused', {detail:
409+
{target: this}}));
410+
}
411+
});
412+
this.parentElement.addEventListener('mousedown', function (e) {
413+
if(document.activeElement.nodeName === "MAPML-VIEWER"){
414+
document.activeElement.dispatchEvent(new CustomEvent('mapfocused', {detail:
415+
{target: this}}));
416+
}
417+
});
405418
this._map.on('load',
406419
function () {
407420
this.dispatchEvent(new CustomEvent('load', {detail: {target: this}}));

0 commit comments

Comments
 (0)