Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tileerror events, on both HTTP errors and FileReader errors. #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Leaflet.VectorGrid.Protobuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ L.VectorGrid.Protobuf = L.VectorGrid.extend({
return fetch(tileUrl, this.options.fetchOptions).then(function(response){

if (!response.ok) {
return {layers:[]};
throw new Error('Failed to fetch tile: HTTP response ' + response.status +
' ' + response.statusText);
}

return response.blob().then( function (blob) {
// console.log(blob);

var reader = new FileReader();
return new Promise(function(resolve){
return new Promise(function(resolve, reject){
reader.addEventListener("loadend", function() {
// reader.result contains the contents of blob as a typed array

Expand All @@ -124,6 +125,9 @@ L.VectorGrid.Protobuf = L.VectorGrid.extend({
return resolve(new VectorTile( pbf ));

});
reader.addEventListener("error", reject);
reader.addEventListener("abort", reject);

reader.readAsArrayBuffer(blob);
});
});
Expand All @@ -146,6 +150,8 @@ L.VectorGrid.Protobuf = L.VectorGrid.extend({
}

return json;
}).catch(function(err){
this.fire('tileerror', err);
});
}
});
Expand Down