Skip to content

Commit

Permalink
support custom fetch headers
Browse files Browse the repository at this point in the history
  • Loading branch information
deyihu committed Nov 13, 2024
1 parent df6b257 commit 16ecd04
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tileget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getCanvas, imageFilter, imageTileScale } from './canvas';

const CANVAS_ERROR_MESSAGE = new Error('not find canvas.The current environment does not support OffscreenCanvas');

const headers = {
const HEADERS = {
'accept': 'image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26'
};
Expand All @@ -17,6 +17,7 @@ export function getTile(url, options = {}) {
reject(new Error('url is null'));
return;
}
const headers = Object.assign({}, HEADERS, options.headers || {});
fetch(url, {
headers
}).then(res => res.blob()).then(blob => createImageBitmap(blob)).then(imagebit => {
Expand Down Expand Up @@ -90,6 +91,7 @@ export function getTileWithMaxZoom(options = {}) {
tileZ = maxAvailableZoom;
}
const url = urlTemplate.replace('{x}', tileX).replace('{y}', tileY).replace('{z}', tileZ);
const headers = Object.assign({}, HEADERS, options.headers || {});
fetch(url, {
headers
}).then(res => res.blob()).then(blob => createImageBitmap(blob)).then(imagebit => {
Expand Down

0 comments on commit 16ecd04

Please sign in to comment.