/* exported TrainOverlay */ /* globals AbstractIconOverlay: true */ /* jshint unused: false */ function getTrainImageUrlForType(type){ switch(type){ case "advtrains:subway_wagon": return "pics/advtrains/advtrains_subway_wagon_inv.png"; case "advtrains:engine_japan": return "pics/advtrains/advtrains_engine_japan_inv.png"; case "advtrains:wagon_japan": return "pics/advtrains/advtrains_wagon_japan_inv.png"; case "advtrains:engine_steam": return "pics/advtrains/advtrains_engine_steam_inv.png"; case "advtrains:engine_industrial": return "pics/advtrains/advtrains_engine_industrial_inv.png"; case "advtrains:wagon_wood": return "pics/advtrains/advtrains_wagon_wood_inv.png"; case "advtrains:wagon_box": return "pics/advtrains/advtrains_wagon_box_inv.png"; case "advtrains:subway_wagon_blue": return "pics/advtrains/advtrains_subway_wagon_inv_blue.png"; case "advtrains:subway_wagon_red": return "pics/advtrains/advtrains_subway_wagon_inv_red.png"; case "advtrains:subway_wagon_green": return "pics/advtrains/advtrains_subway_wagon_inv_green.png"; default: //TODO: fallback image return "pics/advtrains/advtrains_subway_wagon_inv.png"; } } var TrainOverlay = L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr) { L.LayerGroup.prototype.initialize.call(this); this.layerMgr = layerMgr; this.wsChannel = wsChannel; this.currentObjects = {}; // name => marker this.trains = []; this.reDraw = this.reDraw.bind(this); this.onMinetestUpdate = this.onMinetestUpdate.bind(this); //update players all the time this.wsChannel.addListener("minetest-info", function(info){ this.trains = info.trains || []; }.bind(this)); }, createMarker: function(train){ //search for wagin in front (whatever "front" is...) var type; var lowest_pos = 100; 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), iconSize: [16, 16], iconAnchor: [8, 8], popupAnchor: [0, -16] }); var marker = L.marker([train.pos.z, train.pos.x], {icon: Icon}); var html = "Train