From a4609e446d556f2d0022766682afb4731da1e690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20S=C3=A1nchez=20Ortega?= Date: Fri, 19 Jan 2018 16:40:26 +0100 Subject: [PATCH] Implement tileerror events, on both HTTP errors and FileReader errors. --- src/Leaflet.VectorGrid.Protobuf.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Leaflet.VectorGrid.Protobuf.js b/src/Leaflet.VectorGrid.Protobuf.js index b6f4cda..8c7cc80 100644 --- a/src/Leaflet.VectorGrid.Protobuf.js +++ b/src/Leaflet.VectorGrid.Protobuf.js @@ -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 @@ -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); }); }); @@ -146,6 +150,8 @@ L.VectorGrid.Protobuf = L.VectorGrid.extend({ } return json; + }).catch(function(err){ + this.fire('tileerror', err); }); } });