mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 19:01:08 +00:00
implement cancellation for maplibre fetch [#1]
This commit is contained in:
@@ -206,18 +206,22 @@ export const addProtocol = maplibre_instance => {
|
|||||||
let z = result[2]
|
let z = result[2]
|
||||||
let x = result[3]
|
let x = result[3]
|
||||||
let y = result[4]
|
let y = result[4]
|
||||||
|
var cancel = () => {}
|
||||||
instance.getZxy(+z,+x,+y).then(val => {
|
instance.getZxy(+z,+x,+y).then(val => {
|
||||||
if (val) {
|
if (val) {
|
||||||
let headers = {'Range':'bytes=' + val[0] + '-' + (val[0]+val[1]-1)}
|
let headers = {'Range':'bytes=' + val[0] + '-' + (val[0]+val[1]-1)}
|
||||||
fetch(pmtiles_url,{headers:headers}).then(resp => {
|
const controller = new AbortController()
|
||||||
|
const signal = controller.signal
|
||||||
|
fetch(pmtiles_url,{signal:signal,headers:headers}).then(resp => {
|
||||||
return resp.arrayBuffer()
|
return resp.arrayBuffer()
|
||||||
}).then(arr => {
|
}).then(arr => {
|
||||||
callback(null,arr,null,null)
|
callback(null,arr,null,null)
|
||||||
})
|
})
|
||||||
|
cancel = controller.abort
|
||||||
} else {
|
} else {
|
||||||
callback(null,new Uint8Array(),null,null)
|
callback(null,new Uint8Array(),null,null)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return { cancel: () => { console.log("Cancel not implemented") } }
|
return { cancel: cancel }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user