Commit 246db87e authored by Sharp Hall's avatar Sharp Hall

Initial commit

parents
<html>
<head>
<title>SEPTA</title>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js" integrity="sha256-VeNaFBVDhoX3H+gJ37DpT/nTuZTdjYro9yBruHjVmoQ=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/haversine@1.1.1/haversine.min.js"></script>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script type="text/babel" src="main.js"></script>
</head>
<body>
<div id="routelist"></div>
</body>
</html>
var septaRoutes = {};
var flatDistanceSorted = [];
var currentLocation = {latitude: 39.949362, longitude: -75.223623};
function milesFromObj(ref, septaObj) {
return haversine(ref, {latitude: parseFloat(septaObj.lat),
longitude: parseFloat(septaObj.lng)},
{unit: "mile"});
}
function markRoutes(routes) {
_.forEach(routes, function(value, key) {
_.forEach(value, function(route) {
route.route = key;
});
});
return routes;
}
function calcDistances() {
// update distance in septa route objects according to currentLocation
_.forEach(septaRoutes, function(route) {
_.forEach(route, function(vehicle) {
vehicle.distance = milesFromObj(currentLocation, vehicle);
});
});
flatDistanceSorted = _.sortBy(_.flatten(_.values(septaRoutes)), function (vehicle) {
return vehicle.distance;
});
}
function getSeptaTransitView() {
$.ajax({
url: "https://www3.septa.org/hackathon/TransitViewAll/",
jsonp: "callback",
dataType: "jsonp",
success: function (newData) {
septaRoutes = markRoutes(newData.routes[0]);
calcDistances();
ReactDOM.render(<VehicleList vehicleList={flatDistanceSorted} />,
document.getElementById('routelist'));
}
});
}
$(function () {
console.log("Hello world!")
getSeptaTransitView();
});
class Vehicle extends React.Component {
render() {
console.log(this.props.vehicleData);
return (
<div>
{this.props.vehicleData.Direction} {this.props.vehicleData.route} {this.props.vehicleData.distance} mi away
</div>
);
}
}
class VehicleList extends React.Component {
render() {
return (
<div>
{this.props.vehicleList.map(vehicle => (
<Vehicle vehicleData={vehicle} />
))}
</div>
);
}
}
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