From e0328b4750cf31481d9c57a17a95e2727721d49c Mon Sep 17 00:00:00 2001 From: deyihu Date: Mon, 4 Nov 2024 18:42:32 +0800 Subject: [PATCH] fetch tile add headers --- src/tileget.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tileget.js b/src/tileget.js index bdcb968..c1a3bc1 100644 --- a/src/tileget.js +++ b/src/tileget.js @@ -1,12 +1,19 @@ import { getCanvas, imageFilter } from './cavnas'; +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' +}; + export function getTile(url, options = {}) { return new Promise((resolve, reject) => { if (!url) { reject(new Error('url is null')); return; } - fetch(url).then(res => res.blob()).then(blob => createImageBitmap(blob)).then(imagebit => { + fetch(url, { + headers + }).then(res => res.blob()).then(blob => createImageBitmap(blob)).then(imagebit => { const filter = options.filter; if (filter) { const canvas = getCanvas();