TileLayer: fix Safari 16.5 compatibility (#9992)

This commit is contained in:
Simon Legner 2025-11-22 15:35:00 +01:00 committed by GitHub
parent 14ca480c43
commit bc29e77ac3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View File

@ -406,6 +406,23 @@ describe('TileLayer', () => {
});
});
it('supports relative tile URLs', () => {
const layer = new TileLayer('./tiles/{z}/{y}/{x}.png').addTo(map);
const urls = [
'./tiles/2/1/1.png',
'./tiles/2/1/2.png',
'./tiles/2/2/1.png',
'./tiles/2/2/2.png'
];
let i = 0;
eachImg(layer, (img) => {
expect(img.src).to.contain(urls[i].slice(1));
i++;
});
});
it('adds OSM attribution if none are provided and is using OSM tiles', () => {
// Uses OSM tiles without providing attribution
const layer = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {}).addTo(map);

View File

@ -95,8 +95,8 @@ export class TileLayer extends GridLayer {
options = Util.setOptions(this, options);
// in case the attribution hasn't been specified, check for known hosts that require attribution
if (options.attribution === null && URL.canParse(url)) {
const urlHostname = new URL(url).hostname;
if (options.attribution === null) {
const urlHostname = new URL(url, location.href).hostname;
// check for Open Street Map hosts
const osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];