Add referrerPolicy to TileLayer (#7945)

* add referrerPolicy to TileLayer, fixes #7943

* fix typo in docstring

HT: https://github.com/Leaflet/Leaflet/pull/7945#discussion_r792419377

* drop the "true" option handling for the new referrerPolicy TileLayer option

https://github.com/Leaflet/Leaflet/pull/7945#discussion_r793113681
This commit is contained in:
Nathan Vander Wilt
2022-01-26 18:23:41 -08:00
committed by GitHub
parent 409c17c14b
commit f1f4e05ba1

View File

@ -77,7 +77,15 @@ export var TileLayer = GridLayer.extend({
// Whether the crossOrigin attribute will be added to the tiles. // Whether the crossOrigin attribute will be added to the tiles.
// If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data. // If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data.
// Refer to [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values. // Refer to [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values.
crossOrigin: false crossOrigin: false,
// @option referrerPolicy: Boolean|String = false
// Whether the referrerPolicy attribute will be added to the tiles.
// If a String is provided, all tiles will have their referrerPolicy attribute set to the String provided.
// This may be needed if your map's rendering context has a strict default but your tile provider expects a valid referrer
// (e.g. to validate an API token).
// Refer to [HTMLImageElement.referrerPolicy](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy) for valid String values.
referrerPolicy: false
}, },
initialize: function (url, options) { initialize: function (url, options) {
@ -140,6 +148,12 @@ export var TileLayer = GridLayer.extend({
tile.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin; tile.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;
} }
// for this new option we follow the documented behavior
// more closely by only setting the property when string
if (typeof this.options.referrerPolicy === 'string') {
tile.referrerPolicy = this.options.referrerPolicy;
}
/* /*
Alt tag is set to empty string to keep screen readers from reading URL and for compliance reasons Alt tag is set to empty string to keep screen readers from reading URL and for compliance reasons
https://www.w3.org/TR/WCAG20-TECHS/H67 https://www.w3.org/TR/WCAG20-TECHS/H67