diff --git a/res/userdb.db b/res/userdb.db index f4fd463..242a755 100644 Binary files a/res/userdb.db and b/res/userdb.db differ diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index 578b92b..a9d64ec 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() + @@ -1076,7 +1076,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 36b82dc..d72b4f6 100644 --- a/src/main/java/seng202/group9/Core/FlightPath.java +++ b/src/main/java/seng202/group9/Core/FlightPath.java @@ -7,7 +7,7 @@ public class FlightPath { private ArrayList flightPoints; private String departureAirport; private String arrivalAirport; - private RoutePath routePath; + final private RoutePath routePath = new RoutePath(); /** * @@ -91,8 +91,7 @@ public class FlightPath { } public RoutePath getRoutePath(){ - if (routePath == null){ - routePath = new RoutePath(); + if (routePath.getRoute().size() == 0){ for (FlightPoint point: flightPoints){ routePath.addPosition(new Position(point.getLatitude(), point.getLongitude())); } diff --git a/src/main/java/seng202/group9/Core/RoutePath.java b/src/main/java/seng202/group9/Core/RoutePath.java index 38bc193..e8bf10b 100644 --- a/src/main/java/seng202/group9/Core/RoutePath.java +++ b/src/main/java/seng202/group9/Core/RoutePath.java @@ -22,6 +22,10 @@ public class RoutePath { route.add(position); } + public ArrayList getRoute() { + return route; + } + public String toJSONArray() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("["); @@ -32,4 +36,5 @@ public class RoutePath { 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 74815a7..7acf4ee 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.fxml.FXML; @@ -11,6 +13,7 @@ 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 java.net.URL; @@ -68,7 +71,16 @@ public class FlightSummaryController extends Controller { } catch (Exception e) { e.printStackTrace(); } - map = new Map(mapView); + 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 index 16fb220..8e65120 100644 --- a/src/main/java/seng202/group9/Map/Map.java +++ b/src/main/java/seng202/group9/Map/Map.java @@ -15,25 +15,29 @@ public class Map { private WebEngine webEngine; private WebView webView; + private boolean canLoad = false; - public Map(WebView webView){ + 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(final RoutePath newRoute) { - webEngine.getLoadWorker().stateProperty().addListener( - new ChangeListener(){ - public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState){ - String scriptToExecute = "displayRoute(" + newRoute.toJSONArray() + ");"; - webEngine.executeScript(scriptToExecute); - } - }); + public void displayRoute(RoutePath newRoute) { + String scriptToExecute = "displayRoute(" + newRoute.toJSONArray() + ");"; + webEngine.executeScript(scriptToExecute); } } diff --git a/src/main/resources/map.html b/src/main/resources/map.html index a79ccfa..f02dc65 100644 --- a/src/main/resources/map.html +++ b/src/main/resources/map.html @@ -36,6 +36,19 @@ }); } + function displayAirport(position){ + map = new google.maps.Map(document.getElementById('map'), { + center: position[0], + zoom: 15 + }); + + new google.maps.Marker({ + position: position[0], + map: map, + title: '\u0048\u0061\u0072\u0061\u006d\u0062\u0065' + }); + } + function displayRoute(flightPath) { // CLEAR EXISTING MARKERS if (marker1 !== undefined && marker2 !== undefined && path !== undefined) {