Skip to content

Commit d0d08ee

Browse files
committed
Catch localstorage parse issues.
1 parent 98f5ef2 commit d0d08ee

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

demos/mcd/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ init_heart = function(){
347347
}
348348

349349
function onClick( event ) {
350+
return
350351
//event.preventDefault();
351352
var mouse = new THREE.Vector2();
352353
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;

src/geography.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,34 @@ THREE.ARMapzenGeography = function(opts){
9696
var load_tile = function(tx, ty, zoom, callback) {
9797
var key = tx + '_' + ty + '_' + zoom
9898
MAP_CACHE[key] = 1;
99-
var cached_data = localStorage['mz_' + key];
100-
if (cached_data) {
101-
setTimeout(function(){
102-
callback(JSON.parse(cached_data));
103-
}, 200);
104-
} else {
105-
var url = "https://tile.mapzen.com/mapzen/vector/v1/all/" + zoom + "/" + tx + "/" + ty + ".json?api_key=" + MAPZEN_API_KEY
106-
fetch(url).then(function(response){
107-
return response.json();
108-
}).then(function(data){
109-
callback(data);
110-
try {
111-
localStorage['mz_' + key] = JSON.stringify(data);
112-
} catch(e) {
113-
if(e.toString().indexOf('QuotaExceededError') > -1) {
114-
localStorage.clear();
115-
}
116-
}
117-
});
99+
try {
100+
var cached_data = localStorage['mz_' + key];
101+
if (cached_data) {
102+
cached_data = JSON.parse(cached_data);
103+
setTimeout(function(){
104+
callback(JSON.parse(cached_data));
105+
}, 200);
106+
return
107+
}
108+
109+
} catch (e) {
110+
118111
}
112+
113+
var url = "https://tile.mapzen.com/mapzen/vector/v1/all/" + zoom + "/" + tx + "/" + ty + ".json?api_key=" + MAPZEN_API_KEY
114+
fetch(url).then(function(response){
115+
return response.json();
116+
}).then(function(data){
117+
callback(data);
118+
try {
119+
localStorage['mz_' + key] = JSON.stringify(data);
120+
} catch(e) {
121+
if(e.toString().indexOf('QuotaExceededError') > -1) {
122+
localStorage.clear();
123+
}
124+
}
125+
});
126+
119127
};
120128

121129

0 commit comments

Comments
 (0)