Commit ed1a01ae authored by Sharp Hall's avatar Sharp Hall

Allow overriding with underground trolley locations

parent 0b307b5d
<html>
<head>
<title>wheresepta</title>
<link rel="stylesheet" href="style.css?1.1.2" type="text/css" />
<link rel="stylesheet" href="style.css?1.2.0" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="app"><div class="notice">Please wait! Loading!</div>
<script src="bundle.js?1.1.2"></script>
<script src="bundle.js?1.2.0"></script>
</body>
</html>
......@@ -20,7 +20,48 @@ var DATA_WEIRDNESS_CLUES = _.sortBy(["MIDVALE", "FRONTIER", "SOUTHERN", "VICTORY
"CALLOWHILL RAIL", "FRANKFORD", "FRANKFORD RAIL",
"COMLY", "ALLEGHENY"]);
var septaRoutes = {};
var SELECTABLE_STOPS = [
{
"n": "13th St Trolley Station",
"r": ["11", "13", "34", "36", "10"],
"x": -75.162559, "y": 39.952532
},
{
"n": "15th St Trolley Station",
"r": ["11", "13", "34", "36", "10"],
"x": -75.165369, "y": 39.952502
},
{
"n": "19th St Trolley Station",
"r": ["11", "13", "34", "36", "10"],
"x": -75.171483, "y": 39.953425
},
{
"n": "22nd St Trolley Station",
"r": ["11", "13", "34", "36", "10"],
"x": -75.176571, "y": 39.954051
},
{
"n": "30th St Trolley Station",
"r": ["11", "13", "34", "36", "10"],
"x": -75.1835, "y": 39.954815
},
{
"n": "33rd St Trolley Station",
"r": ["11", "13", "34", "36", "10"],
"x": -75.1897, "y": 39.954773
},
{
"n": "36th St Trolley Station",
"r": ["11", "13", "34", "36"],
"x": -75.194722, "y": 39.95389
},
{
"n": "37th St Trolley Station",
"r": ["11", "13", "34", "36"],
"x": -75.196586, "y": 39.950993
}
]
function milesFromObj(ref, septaObj) {
return haversine(ref, {latitude: parseFloat(septaObj.lat),
......@@ -126,7 +167,8 @@ class WhereSepta extends React.Component {
location: null,
loaded: false,
detours: [],
dataWeirdness: 0
dataWeirdness: 0,
override: null
};
this.handleVisibilityChange = this.handleVisibilityChange.bind(this);
}
......@@ -197,6 +239,7 @@ class WhereSepta extends React.Component {
routeInfo: stopData.routes,
stops: stopData.stops
});
console.log(stopData.stops);
}
});
this.refresh();
......@@ -217,25 +260,46 @@ class WhereSepta extends React.Component {
render() {
var location = this.state.location;
if (location === null) {
return(<LocationSharingNotice />);
return(
<div>
<LocationSharingNotice />
</div>
);
}
if (!this.state.loaded) {
return(<div className="notice">Please wait! Loading!</div>);
}
var here = point([location.longitude, location.latitude]);
// find close stops
var selectedRoutes = _.chain(this.state.stops)
var closestStops = _.chain(this.state.stops)
.map(stop => {
stop.distance = haversine(location, {latitude: stop.y,
longitude: stop.x});
return stop;
})
.filter(stop => stop.distance < STOP_DISTANCE_THRESHOLD)
.sortBy(stop => stop.distance)
.value();
var stopName = null;
if(closestStops[0]) {
stopName = closestStops[0].n;
}
if (this.state.override) {
closestStops = [this.state.override];
location = {longitude: this.state.override.x,
latitude: this.state.override.y};
here = point([location.longitude, location.latitude]);
}
var selectedRoutes = _.chain(closestStops)
.map(stop => stop.r)
.flatten()
.uniq()
.value();
var vehicles = _.chain(this.state.vehicles)
.filter((routes, key) => selectedRoutes.includes(key))
.values()
......@@ -290,7 +354,58 @@ class WhereSepta extends React.Component {
DATA_WEIRDNESS_CLUES.join(', '));
}
return(
<VehicleList notices={notices} detours={detours} vehicleList={vehicles} routeList={selectedRoutes} />
<div>
<LocationOverride onChange={loc => this.setState({ override: loc })}
stopName={stopName} override={this.state.override} />
<VehicleList notices={notices} detours={detours} vehicleList={vehicles} routeList={selectedRoutes} />
</div>
);
}
}
class LocationOverride extends React.Component {
constructor(props) {
super(props);
this.state = {
open: false
};
}
setLocation(stop) {
this.props.onChange(stop);
this.setState({ open: false });
}
render() {
var locationOptions = SELECTABLE_STOPS;
if (this.state.open) {
return (
<div>
<div className="location-override head">Change Location</div>
{this.props.stopName ?
<div className="sub location-option" onClick={() => this.setLocation(null)}>
{this.props.stopName + ' '} (Device location)
</div>
:
<div className="sub location-option" onClick={() => this.setLocation(null)}>
Device location
</div>
}
{locationOptions.map(loc => (
<div className="sub location-option" onClick={() => this.setLocation(loc)} key={loc.n}>
{loc.n}
</div>
))}
</div>
);
}
return (
<div>
<div className="location-override" onClick={() => this.setState({ open: true })}>
{(this.props.override ? this.props.override.n : this.props.stopName || 'Unknown') + ' '}
<span>(Change Location?)</span>
</div>
</div>
);
}
}
......
......@@ -5,7 +5,7 @@ body {
font-family: 'Montserrat', sans-serif;
}
.vehicle, .locationSharingNotice, .notice {
.vehicle, .locationSharingNotice, .notice, .location-override, .location-option {
margin: 4px;
padding: 4px;
background: #cccccc;
......@@ -13,6 +13,14 @@ body {
overflow:auto;
}
.location-override>span {
font-weight: bold;
}
.sub {
margin-left:24px;
padding:12px;
font-weight: bold;
}
#route-list, #footer-menu {
padding:6px;
padding-left:0;
......@@ -78,3 +86,6 @@ body {
.detour-data-header {
font-weight: bold;
}
.head {
font-weight:bold;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment