Added Google Maps API
This commit is contained in:
@@ -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 + ", " +
|
||||
|
||||
@@ -7,6 +7,7 @@ public class FlightPath {
|
||||
private ArrayList<FlightPoint> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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(){
|
||||
|
||||
|
||||
@@ -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<Position> route = new ArrayList<Position>();
|
||||
|
||||
public RoutePath(Position ...points) {
|
||||
Collections.addAll(route, points);
|
||||
}
|
||||
|
||||
public RoutePath(){
|
||||
|
||||
}
|
||||
|
||||
public void addPosition(Position position){
|
||||
route.add(position);
|
||||
}
|
||||
|
||||
public ArrayList<Position> 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +1,20 @@
|
||||
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;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
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 java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@@ -25,7 +30,9 @@ public class FlightSummaryController extends Controller {
|
||||
|
||||
@FXML
|
||||
private Button flightRawData;
|
||||
|
||||
private Map map;
|
||||
@FXML
|
||||
private WebView mapView;
|
||||
@FXML
|
||||
ListView<String> flightPathListView;
|
||||
final ObservableList<String> flightList = FXCollections.observableArrayList();
|
||||
@@ -64,6 +71,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<String>() {
|
||||
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||
map.displayRoute(theDataSet.getFlightPaths().get(flightPathListView.getSelectionModel().getSelectedIndices().get(0)).getRoutePath());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Worker.State>() {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user