Skip to content

Commit

Permalink
fetch tile add headers
Browse files Browse the repository at this point in the history
  • Loading branch information
deyihu committed Nov 4, 2024
1 parent 3dea7a3 commit e0328b4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tileget.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit e0328b4

Please sign in to comment.