'use strict'; var TrainlineOverlay = AbstractGeoJsonOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "train"); }, createGeoJson: function(objects){ var self = this; var geoJsonLayer = L.geoJSON([], { onEachFeature: function(feature, layer){ if (feature.properties && feature.properties.popupContent) { layer.bindPopup(feature.properties.popupContent); } }, pointToLayer: function (feature, latlng) { return L.circleMarker(latlng, geojsonMarkerOptions); } }); var lines = {}; // { "A1":[] } //Sort and add lines objects.forEach(function(obj){ if (!obj.attributes.line) return var line = lines[obj.attributes.line]; if (!line){ line = []; lines[obj.attributes.line] = line; } line.push(obj); }); //Order by index and display Object.keys(lines).forEach(function(linename){ lines[linename].sort(function(a,b){ return parseInt(a.attributes.index) - parseInt(b.attributes.index); }); var coords = []; var stations = []; //Add stations lines[linename].forEach(function(entry){ coords.push([entry.x, entry.z]); if (entry.attributes.station) { stations.push({ "type": "Feature", "properties": { "name": entry.attributes.station, "popupContent": "Train-station (Line " + entry.attributes.line + ")