fix js crash if advtrains wagons not present

This commit is contained in:
Thomas Rudin 2019-05-20 22:23:42 +02:00
parent be20dff27e
commit 1dd8d52639

View File

@ -48,12 +48,14 @@ var TrainOverlay = L.LayerGroup.extend({
//search for wagin in front (whatever "front" is...) //search for wagin in front (whatever "front" is...)
var type; var type;
var lowest_pos = 100; var lowest_pos = 100;
if (train.wagons){
train.wagons.forEach(function(w){ train.wagons.forEach(function(w){
if (w.pos_in_train < lowest_pos){ if (w.pos_in_train < lowest_pos){
lowest_pos = w.pos_in_train; lowest_pos = w.pos_in_train;
type = w.type; type = w.type;
} }
}); });
}
var Icon = L.icon({ var Icon = L.icon({
iconUrl: getTrainImageUrlForType(type), iconUrl: getTrainImageUrlForType(type),
@ -71,11 +73,13 @@ var TrainOverlay = L.LayerGroup.extend({
html += "<b>Line:</b> " + train.line + "<br>"; html += "<b>Line:</b> " + train.line + "<br>";
html += "<b>Velocity:</b> "+ Math.floor(train.velocity*10)/10 + "<br>"; html += "<b>Velocity:</b> "+ Math.floor(train.velocity*10)/10 + "<br>";
if (train.wagons){
html += "<b>Composition: </b>"; html += "<b>Composition: </b>";
train.wagons.forEach(function(w){ train.wagons.forEach(function(w){
var iconUrl = getTrainImageUrlForType(w.type); var iconUrl = getTrainImageUrlForType(w.type);
html += "<img src='"+iconUrl+"'>"; html += "<img src='"+iconUrl+"'>";
}); });
}
marker.bindPopup(html); marker.bindPopup(html);