summaryrefslogtreecommitdiff
path: root/web/js
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2013-12-22 10:52:52 +0100
committerChristian Franke <nobody@nowhere.ws>2013-12-22 10:52:52 +0100
commit80fd2820f13861c5cc80d08e4e13a1b238cd4cdf (patch)
treea3fa7fd19d6c61140e10523370b66fd69ae169d1 /web/js
parent358e0a63bd2e4deec99a05d5b1bda4955fde2e7f (diff)
Add some more error handling to JS
Diffstat (limited to 'web/js')
-rw-r--r--web/js/eventmap.js36
1 files changed, 30 insertions, 6 deletions
diff --git a/web/js/eventmap.js b/web/js/eventmap.js
index ac83f74..7302da9 100644
--- a/web/js/eventmap.js
+++ b/web/js/eventmap.js
@@ -33,11 +33,17 @@ function eventmap_send_update() {
});
}
+function LoadingException(message) {
+ this.message = message;
+ this.name = "LoadingException";
+}
+
function eventmap_process_update(data) {
if (typeof data == "string")
data = JSON.parse(data);
marker_store_sync_id = data['sync-id'];
- $.each(data['markers'], function(marker_name, marker_info) {
+ if (data['markers'] !== undefined)
+ $.each(data['markers'], function(marker_name, marker_info) {
if (marker_name in marker_store) {
var marker = marker_store[marker_name];
var marker_pos = marker.getLatLng();
@@ -61,7 +67,8 @@ function eventmap_process_update(data) {
console.log("Kept marker '" + marker_name + "'.");
} else {
var marker = L.marker([marker_info.lat, marker_info.lng]);
-
+ var target_layer_group;
+
marker.bindLabel('', {
noHide: marker_labels_no_hide
});
@@ -72,8 +79,14 @@ function eventmap_process_update(data) {
marker.updateLabelContent(marker.options.label_text);
marker_store[marker_name] = marker;
- marker.options.layer_name = marker_info.layer
- layers[marker_info.layer].getLayers()[1].addLayer(marker);
+ marker.options.layer_name = marker_info.layer;
+ target_layer_group = layers[marker_info.layer];
+ if (target_layer_group === undefined) {
+ throw new LoadingException("Don't know about layer '"
+ + marker_info.layer + "'!");
+ }
+
+ target_layer_group.getLayers()[1].addLayer(marker);
marker.options.sync_id = marker_store_sync_id;
console.log("Added marker '" + marker_name + "'.");
}
@@ -362,13 +375,24 @@ $(function() {
url: 'api/markers/get'
}).done(function(data) {
$("#progress").html("Processing marker info...");
- eventmap_process_update(data);
+ try {
+ eventmap_process_update(data);
+ } catch (e) {
+ if (e instanceof LoadingException) {
+ $("#progress").html("Error: " + e.message);
+ } else {
+ $("#progress").html("Unknown error while "
+ + "loading marker info.");
+ throw e;
+ }
+ return;
+ }
$("#progress").html("Loading complete.");
setTimeout(function() {
$("#overlay").hide();
}, 300);
}).fail(function() {
- $("#progress").html("Error loading marker info," +
+ $("#progress").html("Error retrieving marker info," +
" please retry.");
});
});