Skip to content

Commit

Permalink
fetch referrer
Browse files Browse the repository at this point in the history
  • Loading branch information
deyihu committed Nov 19, 2024
1 parent 2b034a1 commit 8907791
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TileActor extends worker.Actor {

getTile(options = {}) {
return new Promise((resolve, reject) => {
options.referrer = options.referrer || document.location.href;
this.send(Object.assign({}, { _type: 'getTile' }, options), null, (error, image) => {
if (error) {
reject(error);
Expand All @@ -24,6 +25,7 @@ class TileActor extends worker.Actor {

getTileWithMaxZoom(options = {}) {
return new Promise((resolve, reject) => {
options.referrer = options.referrer || document.location.href;
this.send(Object.assign({}, { _type: 'getTileWithMaxZoom' }, options), null, (error, image) => {
if (error) {
reject(error);
Expand Down
9 changes: 5 additions & 4 deletions src/tileget.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const tileCache = new LRUCache(200, (image) => {
}
});

function fetchTile(url, headers = {}) {
function fetchTile(url, headers = {}, options) {
return new Promise((resolve, reject) => {
const copyImageBitMap = (image) => {
createImageBitmap(image).then(imagebit => {
Expand All @@ -32,7 +32,8 @@ function fetchTile(url, headers = {}) {
copyImageBitMap(image);
} else {
fetch(url, {
headers
headers,
referrer: options.referrer
}).then(res => res.blob()).then(blob => createImageBitmap(blob)).then(image => {
tileCache.add(url, image);
copyImageBitMap(image);
Expand All @@ -50,7 +51,7 @@ export function getTile(url, options = {}) {
return;
}
const headers = Object.assign({}, HEADERS, options.headers || {});
fetchTile(url, headers).then(imagebit => {
fetchTile(url, headers, options).then(imagebit => {
const filter = options.filter;
if (filter) {
const canvas = getCanvas();
Expand Down Expand Up @@ -123,7 +124,7 @@ export function getTileWithMaxZoom(options = {}) {
const url = urlTemplate.replace('{x}', tileX).replace('{y}', tileY).replace('{z}', tileZ);
const headers = Object.assign({}, HEADERS, options.headers || {});

fetchTile(url, headers).then(imagebit => {
fetchTile(url, headers, options).then(imagebit => {
let image;
const filter = options.filter;
if (filter) {
Expand Down

0 comments on commit 8907791

Please sign in to comment.