diff --git a/src/main/java/seng202/group9/Controller/Session.java b/src/main/java/seng202/group9/Controller/Session.java index f14787c..8387a48 100644 --- a/src/main/java/seng202/group9/Controller/Session.java +++ b/src/main/java/seng202/group9/Controller/Session.java @@ -34,6 +34,9 @@ public class Session implements Serializable { public Session(){ //blank constructor this.sceneDisplayed = SceneCode.INITIAL; + this.filteredAirlines = new HashMap<>(); + this.filteredAirports = new HashMap<>(); + this.filteredRoutes = new HashMap<>(); } /** diff --git a/src/main/java/seng202/group9/Core/Airport.java b/src/main/java/seng202/group9/Core/Airport.java index 76e00c0..31fca1a 100644 --- a/src/main/java/seng202/group9/Core/Airport.java +++ b/src/main/java/seng202/group9/Core/Airport.java @@ -429,6 +429,10 @@ public class Airport { public int getTotalRoutes(){ return departureRoutes.size() + arrivalRoutes.size(); } + + public RoutePath getRoutePath(){ + return new RoutePath(new Position(latitude, longitude)); + } /** * Information of the airport returned in String format. */ diff --git a/src/main/java/seng202/group9/GUI/AirportRDController.java b/src/main/java/seng202/group9/GUI/AirportRDController.java index d09f22f..36bac1c 100644 --- a/src/main/java/seng202/group9/GUI/AirportRDController.java +++ b/src/main/java/seng202/group9/GUI/AirportRDController.java @@ -63,27 +63,25 @@ public class AirportRDController extends Controller{ return; } theDataSet = getParent().getCurrentDataset(); - if (theDataSet != null) { - //Sets up the table columns to be ready for use for Airport data - airpIDCol.setCellValueFactory(new PropertyValueFactory("ID")); - airpNameCol.setCellValueFactory(new PropertyValueFactory("Name")); - airpCityCol.setCellValueFactory(new PropertyValueFactory("CityName")); - airpCountryCol.setCellValueFactory(new PropertyValueFactory("CountryName")); - airpIATAFFACol.setCellValueFactory(new PropertyValueFactory("IATA_FFA")); - airpICAOCol.setCellValueFactory(new PropertyValueFactory("ICAO")); - airpLatitudeCol.setCellValueFactory(new PropertyValueFactory("Latitude")); - airpLongitudeCol.setCellValueFactory(new PropertyValueFactory("Longitude")); - airpAltitudeCol.setCellValueFactory(new PropertyValueFactory("Altitude")); - airpTimezoneCol.setCellValueFactory(new PropertyValueFactory("Timezone")); - airpDSTCol.setCellValueFactory(new PropertyValueFactory("DST")); - airpTzCol.setCellValueFactory(new PropertyValueFactory("Tz")); + //Sets up the table columns to be ready for use for Airport data + airpIDCol.setCellValueFactory(new PropertyValueFactory("ID")); + airpNameCol.setCellValueFactory(new PropertyValueFactory("Name")); + airpCityCol.setCellValueFactory(new PropertyValueFactory("CityName")); + airpCountryCol.setCellValueFactory(new PropertyValueFactory("CountryName")); + airpIATAFFACol.setCellValueFactory(new PropertyValueFactory("IATA_FFA")); + airpICAOCol.setCellValueFactory(new PropertyValueFactory("ICAO")); + airpLatitudeCol.setCellValueFactory(new PropertyValueFactory("Latitude")); + airpLongitudeCol.setCellValueFactory(new PropertyValueFactory("Longitude")); + airpAltitudeCol.setCellValueFactory(new PropertyValueFactory("Altitude")); + airpTimezoneCol.setCellValueFactory(new PropertyValueFactory("Timezone")); + airpDSTCol.setCellValueFactory(new PropertyValueFactory("DST")); + airpTzCol.setCellValueFactory(new PropertyValueFactory("Tz")); - //Assigning the Dataset to the current Dataset's airports and displaying it in a table - currentSession = getParent().getSession(); + //Assigning the Dataset to the current Dataset's airports and displaying it in a table + currentSession = getParent().getSession(); - tableViewAirportRD.setItems(observableArrayList(theDataSet.getAirports())); - tableViewAirportRD.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - } + tableViewAirportRD.setItems(observableArrayList(theDataSet.getAirports())); + tableViewAirportRD.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); } public void openAdd() { diff --git a/src/main/java/seng202/group9/GUI/FlightSummaryController.java b/src/main/java/seng202/group9/GUI/FlightSummaryController.java index a08b935..231ce42 100644 --- a/src/main/java/seng202/group9/GUI/FlightSummaryController.java +++ b/src/main/java/seng202/group9/GUI/FlightSummaryController.java @@ -195,11 +195,6 @@ 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) { int index = flightPathListView.getSelectionModel().getSelectedIndices().get(0); @@ -208,6 +203,7 @@ public class FlightSummaryController extends Controller { } } }); + map = new Map(mapView, new RoutePath(), flightPathListView); } } diff --git a/src/main/java/seng202/group9/GUI/PopUpMapController.java b/src/main/java/seng202/group9/GUI/PopUpMapController.java new file mode 100644 index 0000000..318e621 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/PopUpMapController.java @@ -0,0 +1,42 @@ +package seng202.group9.GUI; + +import javafx.fxml.FXML; +import javafx.scene.control.TableView; +import javafx.scene.web.WebView; +import seng202.group9.Core.Airport; +import seng202.group9.Core.Position; +import seng202.group9.Core.Route; +import seng202.group9.Core.RoutePath; +import seng202.group9.Map.Map; + +import java.util.ArrayList; + +/** + * Created by fwy13 on 2/10/16. + */ +public class PopUpMapController extends Controller { + @FXML + WebView mapView; + Map map; + + @Override + public void load() { + map = new Map(mapView, new RoutePath()); + } + + public void loadAirports(ArrayList airports){ + ArrayList routePaths = new ArrayList<>(); + for (Airport airport: airports){ + routePaths.add(airport.getRoutePath()); + } + map.displayAirports(routePaths); + } + + public void loadRoutes(ArrayList routes){ + ArrayList routePaths = new ArrayList<>(); + for (Route route: routes){ + routePaths.add(route.getRoutePath()); + } + map.displayRoutes(routePaths); + } +} diff --git a/src/main/java/seng202/group9/Map/Map.java b/src/main/java/seng202/group9/Map/Map.java index 177c11d..d14414c 100644 --- a/src/main/java/seng202/group9/Map/Map.java +++ b/src/main/java/seng202/group9/Map/Map.java @@ -4,6 +4,7 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.concurrent.Worker; import javafx.scene.control.Alert; +import javafx.scene.control.ListView; import javafx.scene.control.TableView; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; @@ -50,6 +51,21 @@ public class Map { }); } + public Map(WebView webView, final RoutePath newRoute, ListView table){ + 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); + table.getSelectionModel().selectFirst(); + } + } + }); + } + public void initMap() { webEngine.load(getClass().getClassLoader().getResource("map.html").toExternalForm()); } @@ -64,6 +80,24 @@ public class Map { webEngine.executeScript(scriptToExecute); } + public void displayAirports(ArrayList airports) { + String airportJSONArray = "["; + int counter = 0; + for (RoutePath airport: airports){ + airportJSONArray += airport.toJSONArray() + ", "; + if (counter++ > 49){ + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Too Many Routes"); + alert.setHeaderText("Too Many Routes to display"); + alert.setContentText("As there are too many routes to display only the first\n50 will be displayed."); + alert.showAndWait(); + break; + } + } + airportJSONArray += "]"; + webEngine.executeScript("displayRoutes("+airportJSONArray+");"); + } + public void displayRoutes(ArrayList routes){ String routeJSONArray = "["; int counter = 0; diff --git a/src/main/resources/map.html b/src/main/resources/map.html index 3acdd74..e579638 100644 --- a/src/main/resources/map.html +++ b/src/main/resources/map.html @@ -49,6 +49,21 @@ }); } + function displayAirports(positions){ + map = new google.maps.Map(document.getElementById('map'), { + center: positions[0], + zoom: 5 + }); + for (var i = 0; i < positions.length; i ++) { + new google.maps.Marker({ + position: positions[i], + map: map, + title: '\u0048\u0061\u0072\u0061\u006d\u0062\u0065' + }); + } + repositionMap(positions); + } + function displayRoute(flightPath) { map = new google.maps.Map(document.getElementById('map'), { center: {lat: 39.144684, lng: -84.510079}, diff --git a/src/main/resources/pop_up_map.fxml b/src/main/resources/pop_up_map.fxml new file mode 100644 index 0000000..6f44ec9 --- /dev/null +++ b/src/main/resources/pop_up_map.fxml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + +