Skip to content
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 6 commits into from
Nov 23, 2021

Conversation

ben-lu-uw
Copy link
Contributor

@ben-lu-uw ben-lu-uw commented Oct 14, 2021

This implements meaningful pan and zoom from issue #396 and "bounce back" when max/min pan has been reached.
As of the making of this draft this functionality has only been implemented for mapml-viewer + templatedtilelayers and only been tested on tms.html. Currently looking for feedback.
Known issues:

  • When the map is dragged out of bounds the return behavior is inconsistent
  • Max/min zoom announcement has only been implemented with +/- keys
  • Have not considered the behavior when multiple layers are present

@ahmadayubi
Copy link
Member

You may want to consider creating a new handler that extends L.Handler similar to ContextMenu.js. Then in that handler you can listen for zoom and moveend events in one place without having to modify all the different moveend handlers in the layers.

You would also be able to conditionally add the new handler. So you'd only need to check if M.options.announceMovement is true or not once rather than on every moveend.

For contextmenu, it looks like this,
https://github.com/Maps4HTML/Web-Map-Custom-Element/blob/14375f26c641a03c74cb798856d63a9c232caa27/src/mapml-viewer.js#L196-L201

For announceMovement, you could do the same and instead of true pass in M.options.announceMovement.

This is a good resource: https://leafletjs.com/examples/extending/extending-3-controls.html

@@ -5,6 +5,32 @@ import './mapml.js'; // refactored URI usage, replaced with URL standard
import './Leaflet.fullscreen.js';
import { MapLayer } from './layer.js';

class ExtendedMap extends L.Map {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it's a good idea to include one class definition in the definition file for another. Maybe it's own class file, if indeed a class is necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have so far not had to extend L.Map, so would try to stay away from that. If that's impossible, I don't think that Leaflet yet (properly) supports ES6 modules, it has its own extension mechanism, see here: https://leafletjs.com/examples/extending/extending-1-classes.html and here https://leafletjs.com/examples/extending/extending-3-controls.html

@@ -100,7 +126,8 @@ export class MapViewer extends HTMLElement {
constructor() {
// Always call super first in constructor
super();

this.insertAdjacentHTML("beforebegin", "<output role='status' aria-live='polite' aria-atomic='true' id='screenReaderOutput' style='clip: rect(0 0 0 0);clip-path: inset(50%);height: 1px;overflow: hidden;position: absolute;white-space: nowrap;width: 1px;'></output>");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize, I think I mentioned an "attached" method, which no longer is part of custom elements; I should have said "connectedCallback" might be a good location for this. However, I thought I remembered from somewhere that you shouldn't do DOM manipulation in the constructor, but in reading our own code, that doesn't make sense, so maybe where you've got it is correct TBD.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/mapml-viewer.js Outdated Show resolved Hide resolved
@ben-lu-uw ben-lu-uw marked this pull request as ready for review October 25, 2021 17:44
src/mapml-viewer.js Outdated Show resolved Hide resolved
addHooks: function () {
this._map.on({
moveend: this.announceBounds,
zoomend: this.totalBounds,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the bounds are in terms of pcrs you only need to calculate it once at the beginning and whenever a layer is added or removed from the map.

zoomlevel

In the above you can see that on different zoom levels the value this function sets doesn't change.

}
});

this.totalLayerBounds = bounds;
Copy link
Member

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.

let visible = mapZoom <= this._layersMaxZoom && mapZoom >= this._layersMinZoom &&
this.totalLayerBounds.overlaps(mapBounds);

if(!this.totalLayerBounds){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!this.totalLayerBounds is checked after the variable is already used, the mapZoom <= this._layersMaxZoom && mapZoom >= this._layersMinZoom && this.totalLayerBounds.overlaps(mapBounds); could be conditionally called, something like:

let visible = true;

if(this.totalLayerBounds){
  visible = mapZoom <= this._layersMaxZoom && mapZoom >= this._layersMinZoom &&
              this.totalLayerBounds.overlaps(mapBounds);
}

let standard = "zoom level " + mapZoom + " column " + column + " row " + row;

if(!visible){
mapEl._addToHistory();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually adding to history may cause other issues, one I noticed was after being out of bounds you cannot go back (the index also has other odd behaviors):

2021-10-25.14-29-28.mp4

@ben-lu-uw ben-lu-uw marked this pull request as draft October 26, 2021 03:36
@ben-lu-uw
Copy link
Contributor Author

ben-lu-uw commented Oct 26, 2021

Hopefully resolved the indexing issues but now when reaching the top bounds, the map bounces back to an unexpected location on certain occasions.
Edit: seems like it also happens on the main branch as well:

2021-10-26.11-26-08.mov

Moved to issue #542

@prushforth
Copy link
Member

@Malvoz why don't links announce where they go? For map links, I think it would be good to know whether the link will navigate the page or the map, for example. Do web links not have that notion? For visual users, we see the destination of the link in the bottom left of the screen/map, so there's some sense that we're not going to hell by clicking on the link. Do non-visual users not get that same assurance somehow?

@Malvoz
Copy link
Member

Malvoz commented Nov 4, 2021

@prushforth To my knowledge links are always just announced "link" along with their accessible name/desc, even when they're target="_blank" for example. So no, non-visual users do not get that same assurance, I believe. Which is bad for screen reader users, but good for us since we're using fake links and would otherwise have had to replicate and translate that language.

Create util function for zoom/movement screen reader support

Fix setTimeout

Focus on the map

Focus on the map

Fix focus on the map

Add announceMoveAndZoom functionality to all layer types

Use aria-label for announce zoom and move

Use output element for announcing zoom and move

Add/Fix zoom and pan bounds

Add dragging bounds

Create new handler to listen for move events

Add bounds

Implement combined bounds to handle multiple layers bound check [work in progress]

Implement combined bounds to handle multiple layers bound check [work in progress]

Fix total bounds and bounds check

Add total bounds rectangle to debug layer

Change output element and total layer bounds rectangle position in dom to satisfy tests

Disable bounds check when no bounds are present

Refactor output element

Set initial bounds to center of first bounds instead of [0,0]

Clean up code

Refactor output element class name

Resolve indexing issues [work in progress]

Make deselected layers not considered for the total bounds

Use layeradd/layerremove instead of checkdisable for timing reasons

Announce location on focus

Fix max/min zoom announcements

Fix dragged out of bounds condition

Fix dragged out of bounds condition

Merge in history fix

Fix double moveend call issue

Remove console log

Add announceMovement test
@ben-lu-uw ben-lu-uw force-pushed the announce_zoom_and_move branch from a40b530 to 357b403 Compare November 18, 2021 02:55
@ben-lu-uw ben-lu-uw marked this pull request as ready for review November 18, 2021 16:13
Copy link
Member

@prushforth prushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it you have to reload the map for the extension setting to take effect on announcing/not announcing map location. In general the experience is what I expect, more or less; a few extra things that I don't recognized are announced. In this example page, when you tab to the second map, initially the location isn't announced. rows and columns are projection specific, we may need to figure out improvements incrementally. For example, as you remove layers from the map, the bounds should change.

This is a big change @ben-lu-uw , thank you for your hard work on it. Merging.

@prushforth prushforth merged commit ddf4db8 into Maps4HTML:main Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants