From 1dd8d5263910a1999d07944e4c13d84cb9068ede Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Mon, 20 May 2019 22:23:42 +0200 Subject: [PATCH] fix js crash if advtrains wagons not present --- server/static/js/overlays/TrainOverlay.js | 26 +++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/server/static/js/overlays/TrainOverlay.js b/server/static/js/overlays/TrainOverlay.js index 86fd3f1..4dd7a45 100644 --- a/server/static/js/overlays/TrainOverlay.js +++ b/server/static/js/overlays/TrainOverlay.js @@ -48,12 +48,14 @@ var TrainOverlay = L.LayerGroup.extend({ //search for wagin in front (whatever "front" is...) var type; var lowest_pos = 100; - train.wagons.forEach(function(w){ - if (w.pos_in_train < lowest_pos){ - lowest_pos = w.pos_in_train; - type = w.type; - } - }); + if (train.wagons){ + train.wagons.forEach(function(w){ + if (w.pos_in_train < lowest_pos){ + lowest_pos = w.pos_in_train; + type = w.type; + } + }); + } var Icon = L.icon({ iconUrl: getTrainImageUrlForType(type), @@ -71,11 +73,13 @@ var TrainOverlay = L.LayerGroup.extend({ html += "Line: " + train.line + "
"; html += "Velocity: "+ Math.floor(train.velocity*10)/10 + "
"; - html += "Composition: "; - train.wagons.forEach(function(w){ - var iconUrl = getTrainImageUrlForType(w.type); - html += ""; - }); + if (train.wagons){ + html += "Composition: "; + train.wagons.forEach(function(w){ + var iconUrl = getTrainImageUrlForType(w.type); + html += ""; + }); + } marker.bindPopup(html);