diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index dac235e..5c878be 100644 --- a/src/main/java/seng202/group9/Controller/Dataset.java +++ b/src/main/java/seng202/group9/Controller/Dataset.java @@ -326,8 +326,8 @@ public class Dataset { "`Heading` TEXT, " + "`Altitude` INTEGER, " + "`Tot_Dist` INTEGER, " + - "`Longitude` REAL, " + "`Latitude` REAL, " + + "`Longitude` REAL, " + "`Leg_Dist` INTEGER, " + "`Order` INTEGER)"; stmt.execute(createFlightPointTable); @@ -689,7 +689,7 @@ public class Dataset { flightPathToAdd.setID(flightPathId); //ADDED String insertFlightPointQuery = "INSERT INTO `" + this.name + "_Flight_Points` (`Index_ID`, `Name`, `Type`," + - " `Altitude`, `Longitude`, `Latitude`) VALUES "; + " `Altitude`, `Latitude`, `Longitude`) VALUES "; int numOfFlights = 0; for (int i = 0; i < flightPointsToImport.size(); i ++){ String flightPointIdentifier = flightPointsToImport.get(i).getType() + flightPointsToImport.get(i).getName() + @@ -1120,7 +1120,7 @@ public class Dataset { stmt = c.createStatement(); String insertFlightPointQuery = "INSERT INTO `" + this.name + "_Flight_Points` (`Index_ID`, `Name`, `Type`," + - " `Altitude`, `Longitude`, `Latitude`, `Heading`, `Tot_Dist`, `Leg_Dist`, `Via`) VALUES "; + " `Altitude`, `Latitude`, `Longitude`, `Heading`, `Tot_Dist`, `Leg_Dist`, `Via`) VALUES "; String flightType = type.replace("\"", "\"\""); String flightName = name.replace("\"", "\"\""); insertFlightPointQuery += "(" + id +", \""+ flightName +"\", \"" + flightType + "\", "+ altitudeVal + ", " + diff --git a/src/main/java/seng202/group9/Core/FlightPath.java b/src/main/java/seng202/group9/Core/FlightPath.java index e0df38a..d72b4f6 100644 --- a/src/main/java/seng202/group9/Core/FlightPath.java +++ b/src/main/java/seng202/group9/Core/FlightPath.java @@ -7,6 +7,7 @@ public class FlightPath { private ArrayList flightPoints; private String departureAirport; private String arrivalAirport; + final private RoutePath routePath = new RoutePath(); /** * @@ -88,4 +89,13 @@ public class FlightPath { this.flightPoints.add(flightPoints.get(i)); } } + + public RoutePath getRoutePath(){ + if (routePath.getRoute().size() == 0){ + for (FlightPoint point: flightPoints){ + routePath.addPosition(new Position(point.getLatitude(), point.getLongitude())); + } + } + return routePath; + } } diff --git a/src/main/java/seng202/group9/Core/Position.java b/src/main/java/seng202/group9/Core/Position.java new file mode 100644 index 0000000..555035d --- /dev/null +++ b/src/main/java/seng202/group9/Core/Position.java @@ -0,0 +1,14 @@ +package seng202.group9.Core; + +/** + * Created by fwy13 on 17/09/16. + */ +public class Position { + public double lat; + public double lng; + + public Position(double lat, double lng) { + this.lat = lat; + this.lng = lng; + } +} \ No newline at end of file diff --git a/src/main/java/seng202/group9/Core/Route.java b/src/main/java/seng202/group9/Core/Route.java index 07b975d..ffff49c 100644 --- a/src/main/java/seng202/group9/Core/Route.java +++ b/src/main/java/seng202/group9/Core/Route.java @@ -18,6 +18,7 @@ public class Route { private Airport sourceAirport; private Airport destinationAirport; private Airline airline = null; + private RoutePath routePath = null; /** * Constructor for pulling from database @@ -246,6 +247,17 @@ public class Route { throw new DataException("This Route already exists."); } } + + public RoutePath getRoutePath(){ + if (routePath == null) { + routePath = new RoutePath( + new Position(getSourceAirport().getLatitude(), getSourceAirport().getLongitude()), + new Position(getDestinationAirport().getLatitude(), getDestinationAirport().getLongitude()) + ); + } + return routePath; + } + @Override public String toString(){ diff --git a/src/main/java/seng202/group9/Core/RoutePath.java b/src/main/java/seng202/group9/Core/RoutePath.java new file mode 100644 index 0000000..e8bf10b --- /dev/null +++ b/src/main/java/seng202/group9/Core/RoutePath.java @@ -0,0 +1,40 @@ +package seng202.group9.Core; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * Created by brad on 9/09/16. + * Edited by fwy13 + */ +public class RoutePath { + private ArrayList route = new ArrayList(); + + public RoutePath(Position ...points) { + Collections.addAll(route, points); + } + + public RoutePath(){ + + } + + public void addPosition(Position position){ + route.add(position); + } + + public ArrayList getRoute() { + return route; + } + + public String toJSONArray() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("["); + for (Position pos : route){ + stringBuilder.append( + String.format("{lat: %f, lng: %f}, ", pos.lat, pos.lng)); + } + stringBuilder.append("]"); + return stringBuilder.toString(); + } + +} \ No newline at end of file diff --git a/src/main/java/seng202/group9/GUI/FlightSummaryController.java b/src/main/java/seng202/group9/GUI/FlightSummaryController.java index 60d2c07..2b19578 100644 --- a/src/main/java/seng202/group9/GUI/FlightSummaryController.java +++ b/src/main/java/seng202/group9/GUI/FlightSummaryController.java @@ -1,5 +1,7 @@ package seng202.group9.GUI; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.EventHandler; @@ -8,10 +10,13 @@ import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.ListView; import javafx.scene.input.MouseEvent; +import javafx.scene.web.WebView; import seng202.group9.Controller.App; import seng202.group9.Controller.Dataset; import seng202.group9.Controller.SceneCode; import seng202.group9.Core.FlightPath; +import seng202.group9.Core.RoutePath; +import seng202.group9.Map.Map; import seng202.group9.Core.FlightPoint; import java.net.URL; @@ -25,6 +30,12 @@ import java.util.ResourceBundle; public class FlightSummaryController extends Controller { private Dataset theDataSet = null; + + @FXML + private Button flightRawData; + private Map map; + @FXML + private WebView mapView; private int currentPathId = 0; private int currentPathIndex = 0; @@ -99,6 +110,16 @@ public class FlightSummaryController extends Controller { } catch (Exception e) { e.printStackTrace(); } + if (theDataSet.getFlightPaths().size() > 0){ + map = new Map(mapView, theDataSet.getFlightPaths().get(0).getRoutePath()); + }else{ + map = new Map(mapView, new RoutePath()); + } + flightPathListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + public void changed(ObservableValue observable, String oldValue, String newValue) { + map.displayRoute(theDataSet.getFlightPaths().get(flightPathListView.getSelectionModel().getSelectedIndices().get(0)).getRoutePath()); + } + }); } /** diff --git a/src/main/java/seng202/group9/Map/Map.java b/src/main/java/seng202/group9/Map/Map.java new file mode 100644 index 0000000..8e65120 --- /dev/null +++ b/src/main/java/seng202/group9/Map/Map.java @@ -0,0 +1,43 @@ +package seng202.group9.Map; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.concurrent.Worker; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebView; +import seng202.group9.Core.Position; +import seng202.group9.Core.RoutePath; + +/** + * Created by fwy13 on 17/09/16. + */ +public class Map { + + private WebEngine webEngine; + private WebView webView; + private boolean canLoad = false; + + public Map(WebView webView, final RoutePath newRoute){ + this.webView = webView; + webEngine = webView.getEngine(); + initMap(); + webEngine.getLoadWorker().stateProperty().addListener( + new ChangeListener() { + public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { + if (newState == Worker.State.SUCCEEDED){ + displayRoute(newRoute); + } + } + }); + } + + public void initMap() { + webEngine.load(getClass().getClassLoader().getResource("map.html").toExternalForm()); + } + + public void displayRoute(RoutePath newRoute) { + String scriptToExecute = "displayRoute(" + newRoute.toJSONArray() + ");"; + webEngine.executeScript(scriptToExecute); + } + +} diff --git a/src/main/resources/airline_summary.fxml b/src/main/resources/airline_summary.fxml index 13a97f9..59bd2a1 100644 --- a/src/main/resources/airline_summary.fxml +++ b/src/main/resources/airline_summary.fxml @@ -9,9 +9,9 @@ - + @@ -83,7 +83,7 @@ - + diff --git a/src/main/resources/airport_summary.fxml b/src/main/resources/airport_summary.fxml index a490896..baf4ad2 100644 --- a/src/main/resources/airport_summary.fxml +++ b/src/main/resources/airport_summary.fxml @@ -9,9 +9,9 @@ - + @@ -83,8 +83,10 @@ + + + - diff --git a/src/main/resources/flight_data_summary.fxml b/src/main/resources/flight_data_summary.fxml index c9ac9bd..05cc66e 100644 --- a/src/main/resources/flight_data_summary.fxml +++ b/src/main/resources/flight_data_summary.fxml @@ -73,8 +73,7 @@ - - + diff --git a/src/main/resources/map.html b/src/main/resources/map.html new file mode 100644 index 0000000..f02dc65 --- /dev/null +++ b/src/main/resources/map.html @@ -0,0 +1,101 @@ + + + + Google Map Demo + + + + + +
+ + + + \ No newline at end of file diff --git a/src/main/resources/routes_summary.fxml b/src/main/resources/routes_summary.fxml index b56fe76..70f78b3 100644 --- a/src/main/resources/routes_summary.fxml +++ b/src/main/resources/routes_summary.fxml @@ -9,9 +9,9 @@ - + @@ -83,8 +83,10 @@ + + +
-