-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Announce zoom and move and implementing map boundaries #533
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0a377e3
Announce move and zoom and implement bounce back at bounds
ben-lu-uw 9afeeff
Readd output CSS
ben-lu-uw c38162d
Implement Ahmad's M.options.announceMovement
ben-lu-uw ed8ca15
Add new event mapfocused
ben-lu-uw 357b403
Fix tests
ben-lu-uw d96a354
Add announce movement locales
ben-lu-uw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
export var AnnounceMovement = L.Handler.extend({ | ||
addHooks: function () { | ||
this._map.on({ | ||
layeradd: this.totalBounds, | ||
layerremove: this.totalBounds, | ||
}); | ||
|
||
this._map.options.mapEl.addEventListener('moveend', this.announceBounds); | ||
this._map.dragging._draggable.addEventListener('dragstart', this.dragged); | ||
this._map.options.mapEl.addEventListener('mapfocused', this.focusAnnouncement); | ||
}, | ||
removeHooks: function () { | ||
this._map.off({ | ||
layeradd: this.totalBounds, | ||
layerremove: this.totalBounds, | ||
}); | ||
|
||
this._map.options.mapEl.removeEventListener('moveend', this.announceBounds); | ||
this._map.dragging._draggable.removeEventListener('dragstart', this.dragged); | ||
this._map.options.mapEl.removeEventListener('mapfocused', this.focusAnnouncement); | ||
}, | ||
|
||
focusAnnouncement: function () { | ||
let mapEl = this; | ||
setTimeout(function (){ | ||
let el = mapEl.querySelector(".mapml-web-map") ? mapEl.querySelector(".mapml-web-map").shadowRoot.querySelector(".leaflet-container") : | ||
mapEl.shadowRoot.querySelector(".leaflet-container"); | ||
|
||
let mapZoom = mapEl._map.getZoom(); | ||
let location = M.gcrsToTileMatrix(mapEl); | ||
let standard = M.options.locale.amZoom + " " + mapZoom + " " + M.options.locale.amColumn + " " + location[0] + " " + M.options.locale.amRow + " " + location[1]; | ||
|
||
if(mapZoom === mapEl._map._layersMaxZoom){ | ||
standard = M.options.locale.amMaxZoom + " " + standard; | ||
} | ||
else if(mapZoom === mapEl._map._layersMinZoom){ | ||
standard = M.options.locale.amMinZoom + " " + standard; | ||
} | ||
|
||
el.setAttribute("aria-roledescription", "region " + standard); | ||
setTimeout(function () { | ||
el.removeAttribute("aria-roledescription"); | ||
}, 2000); | ||
}, 0); | ||
}, | ||
|
||
announceBounds: function () { | ||
if(this._traversalCall > 0){ | ||
return; | ||
} | ||
let mapZoom = this._map.getZoom(); | ||
let mapBounds = M.pixelToPCRSBounds(this._map.getPixelBounds(),mapZoom,this._map.options.projection); | ||
|
||
let visible = true; | ||
if(this._map.totalLayerBounds){ | ||
visible = mapZoom <= this._map._layersMaxZoom && mapZoom >= this._map._layersMinZoom && | ||
this._map.totalLayerBounds.overlaps(mapBounds); | ||
} | ||
|
||
let output = this.querySelector(".mapml-web-map") ? this.querySelector(".mapml-web-map").shadowRoot.querySelector(".mapml-screen-reader-output") : | ||
this.shadowRoot.querySelector(".mapml-screen-reader-output"); | ||
|
||
//GCRS to TileMatrix | ||
let location = M.gcrsToTileMatrix(this); | ||
let standard = M.options.locale.amZoom + " " + mapZoom + " " + M.options.locale.amColumn + " " + location[0] + " " + M.options.locale.amRow + " " + location[1]; | ||
|
||
if(!visible){ | ||
let outOfBoundsPos = this._history[this._historyIndex]; | ||
let inBoundsPos = this._history[this._historyIndex - 1]; | ||
this.back(); | ||
this._history.pop(); | ||
|
||
if(outOfBoundsPos.zoom !== inBoundsPos.zoom){ | ||
output.innerText = M.options.locale.amZoomedOut; | ||
} | ||
else if(this._map.dragging._draggable.wasDragged){ | ||
output.innerText = M.options.locale.amDraggedOut; | ||
} | ||
else if(outOfBoundsPos.x > inBoundsPos.x){ | ||
output.innerText = M.options.locale.amEastBound; | ||
} | ||
else if(outOfBoundsPos.x < inBoundsPos.x){ | ||
output.innerText = M.options.locale.amWestBound; | ||
} | ||
else if(outOfBoundsPos.y < inBoundsPos.y){ | ||
output.innerText = M.options.locale.amNorthBound; | ||
} | ||
else if(outOfBoundsPos.y > inBoundsPos.y){ | ||
output.innerText = M.options.locale.amSouthBound; | ||
} | ||
|
||
} | ||
else{ | ||
let prevZoom = this._history[this._historyIndex - 1] ? this._history[this._historyIndex - 1].zoom : this._history[this._historyIndex].zoom; | ||
if(mapZoom === this._map._layersMaxZoom && mapZoom !== prevZoom){ | ||
output.innerText = M.options.locale.amMaxZoom + " " + standard; | ||
} | ||
else if(mapZoom === this._map._layersMinZoom && mapZoom !== prevZoom){ | ||
output.innerText = M.options.locale.amMinZoom + " " + standard; | ||
} | ||
else { | ||
output.innerText = standard; | ||
} | ||
} | ||
this._map.dragging._draggable.wasDragged = false; | ||
}, | ||
|
||
totalBounds: function () { | ||
let layers = Object.keys(this._layers); | ||
let bounds = L.bounds(); | ||
|
||
layers.forEach(i => { | ||
if(this._layers[i].layerBounds){ | ||
if(!bounds){ | ||
let point = this._layers[i].layerBounds.getCenter(); | ||
bounds = L.bounds(point, point); | ||
} | ||
bounds.extend(this._layers[i].layerBounds.min); | ||
bounds.extend(this._layers[i].layerBounds.max); | ||
} | ||
}); | ||
|
||
this.totalLayerBounds = bounds; | ||
}, | ||
|
||
dragged: function () { | ||
this.wasDragged = true; | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculated bounds seems to be static, if a layer is deselected the value doesn't reflect that. If a layer is deselected I'm not sure if it should be considered, unless that was something that was decided on.