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

Add support for alt text for legend images #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add support for alt text for legend images #7

wants to merge 4 commits into from

Conversation

pmacMaps
Copy link

I've added an alt property to the legend images. I'm using the label property.

I also added a second map service to the example that has label values set.

Copy link
Owner

@w8r w8r left a comment

Choose a reason for hiding this comment

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

I

@@ -3,8 +3,8 @@ EsriLeaflet.LegendControl = L.Control.extend({
options: {
listTemplate: '<ul>{layers}</ul>',
layerTemplate: '<li><strong>{layerName}</strong><ul>{legends}</ul></li>',
listRowTemplate: '<li><img width="{width}" height="{height}" src="data:{contentType};base64,{imageData}"><span>{label}</span></li>',
emptyLabel: '<all values>',
listRowTemplate: '<li><img alt="map legend icon representing {label}" width="{width}" height="{height}" src="data:{contentType};base64,{imageData}"><span>{label}</span></li>',
Copy link
Owner

Choose a reason for hiding this comment

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

I don't like hard-coded English phrases in the template, it increases the accessibility, but affects the localisation, is there a way around it?

Copy link
Author

Choose a reason for hiding this comment

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

I agree with this. Would adding an option that let's the user specify the text of the alt attribute be a reasonable solution?

Something like the following:

L.esri.Controls.legend([dynamicLayer, featureLayer], {
   position: 'topright',
   altTextTemplate: 'icon representing a map layer'
}).addTo(map);

I would still want to use the label property, but understand it could get tricky without knowing what the user would pass in?

Any thoughts or suggestions?

Copy link
Owner

Choose a reason for hiding this comment

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

it's a good suggestion! But probably it would require a second pass to substitute? or it can be replaced where it's added.

    listRowTemplate: '<li><img alt="'+ altTextTemplate +'" width="{width}" height="{height}" src="data:{contentType};base64,{imageData}"><span>{label}</span></li>',

@w8r
Copy link
Owner

w8r commented May 31, 2019

Thanks a lot for your PR, do you think we can fix the localisation issue there?

Replace with just the map service legend 'label' property.

Update README to reflect change.
@pmacMaps
Copy link
Author

I removed the English text in the alt attribute, and now only reference the label property from the map service. This still helps with web accessibility (assuming there is a label for the map layer).

I still think it would be cool to add a constructor option to set default alt text. I tried, but failed to figure it out. And anyway, it is your call if you would even want that.

Thanks for the feedback.

@w8r
Copy link
Owner

w8r commented May 31, 2019

I suggested a way to pass the alt string template, do you want to add it? I can merge without it though, if you don't have time

@pmacMaps
Copy link
Author

I did try something similar to what you proposed. But I kept getting jshint errors and the files wouldn't build.

I don't know when I'll be able to dig into this further, so I would be fine if you merge it as is.

@pmacMaps
Copy link
Author

Did you want to merge it as is? Even though we want to add in the user-defined alt template text. This will at least provide a basic level of the alt attribute.

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.

2 participants