trainline support
This commit is contained in:
parent
0be7492da7
commit
2b6dcccd9a
@ -37,6 +37,7 @@
|
||||
<script src="js/overlays/LabelOverlay.js"></script>
|
||||
<script src="js/overlays/PlayerOverlay.js"></script>
|
||||
<script src="js/overlays/TrainOverlay.js"></script>
|
||||
<script src="js/overlays/TrainlineOverlay.js"></script>
|
||||
<script src="js/overlays/ProtectorOverlay.js"></script>
|
||||
<script src="js/overlays/XPProtectorOverlay.js"></script>
|
||||
<script src="js/overlays/PrivProtectorOverlay.js"></script>
|
||||
|
@ -56,5 +56,6 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
|
||||
|
||||
if (cfg.mapobjects.train) {
|
||||
overlays["Trains"] = new TrainOverlay(wsChannel, layerMgr);
|
||||
overlays["Trainlines"] = new TrainlineOverlay(wsChannel, layerMgr);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({
|
||||
},
|
||||
|
||||
createStyle: function(feature){
|
||||
//TODO: default style
|
||||
//TODO: default style
|
||||
},
|
||||
|
||||
createGeoJson: function(objects){
|
||||
@ -33,7 +33,7 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({
|
||||
layer.bindPopup(feature.properties.popupContent);
|
||||
}
|
||||
},
|
||||
style: self.createStyle.bind(self)
|
||||
style: self.createStyle.bind(self)
|
||||
});
|
||||
|
||||
objects.forEach(function(obj){
|
||||
|
92
server/static/js/overlays/TrainlineOverlay.js
Normal file
92
server/static/js/overlays/TrainlineOverlay.js
Normal file
@ -0,0 +1,92 @@
|
||||
'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": "<b>Train-station (Line " + entry.attributes.line + ")</b><hr>" +
|
||||
entry.attributes.station
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [entry.x, entry.z]
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var feature = {
|
||||
"type":"Feature",
|
||||
"geometry": {
|
||||
"type":"LineString",
|
||||
"coordinates":coords
|
||||
},
|
||||
"properties":{
|
||||
"name": linename,
|
||||
"popupContent": "<b>Train-line (" + linename + ")</b>"
|
||||
}
|
||||
}
|
||||
//line-points
|
||||
geoJsonLayer.addData(feature);
|
||||
|
||||
//stations
|
||||
stations.forEach(function(stationfeature){
|
||||
geoJsonLayer.addData(stationfeature);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
return geoJsonLayer;
|
||||
}
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user