# Conflicts: # src/main/java/seng202/group9/GUI/FlightSummaryController.javamain
commit
1664a49623
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Google Map Demo</title>
|
||||
<meta name="viewport" content="initial-scale=1.0">
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
#map {
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<script>
|
||||
var map;
|
||||
var marker1;
|
||||
var marker2;
|
||||
var path;
|
||||
|
||||
function initMap() {
|
||||
map = new google.maps.Map(document.getElementById('map'), {
|
||||
center: {lat: 39.144684, lng: -84.510079},
|
||||
zoom: 15
|
||||
});
|
||||
|
||||
new google.maps.Marker({
|
||||
position: {lat: 39.144684, lng: -84.510079},
|
||||
map: map,
|
||||
title: '\u0048\u0061\u0072\u0061\u006d\u0062\u0065'
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
marker1.setMap(null);
|
||||
marker2.setMap(null);
|
||||
path.setMap(null);
|
||||
}
|
||||
|
||||
if (flightPath.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
// CREATE MARKERS AT START AND FINISH
|
||||
marker1 = new google.maps.Marker({
|
||||
position: flightPath[0],
|
||||
map: map
|
||||
});
|
||||
|
||||
marker2 = new google.maps.Marker({
|
||||
position: flightPath[flightPath.length - 1],
|
||||
map: map
|
||||
});
|
||||
|
||||
// DRAW POLYLINE FOR ROUTE
|
||||
path = new google.maps.Polyline({
|
||||
path: flightPath,
|
||||
geodesic: true,
|
||||
strokeColor: '#FF0000',
|
||||
strokeOpacity: 1.0,
|
||||
strokeWeight: 2
|
||||
});
|
||||
|
||||
path.setMap(map);
|
||||
|
||||
repositionMap(flightPath);
|
||||
}
|
||||
|
||||
function repositionMap(flightPath) {
|
||||
var bounds = new google.maps.LatLngBounds();
|
||||
|
||||
for (var i = 0; i < flightPath.length; i++) {
|
||||
bounds.extend(flightPath[i]);
|
||||
}
|
||||
|
||||
map.fitBounds(bounds);
|
||||
}
|
||||
</script>
|
||||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBnt2PJyKZsh-qrsTkbZwSGuUNWPromlLg&callback=initMap" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in new issue