diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 1a400afd..4c38a47a 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -13,67 +13,68 @@ public class App extends Application { @Override public void start(Stage primaryStage) throws Exception { - Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml")); +// Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml")); + Parent root = FXMLLoader.load(getClass().getResource("/views/TestMapView.fxml")); primaryStage.setTitle("RaceVision"); primaryStage.setScene(new Scene(root)); - primaryStage.setMaximized(true); +// primaryStage.setMaximized(true); primaryStage.show(); - primaryStage.setOnCloseRequest(e -> { - StreamParser.appClose(); - StreamReceiver.noMoreBytes(); - System.out.println("[CLIENT] Exiting program"); - System.exit(0); - }); +// primaryStage.setOnCloseRequest(e -> { +// StreamParser.appClose(); +// StreamReceiver.noMoreBytes(); +// System.out.println("[CLIENT] Exiting program"); +// System.exit(0); +// }); } - public static void main(String[] args) { - StreamReceiver sr = null; - - new ServerThread("Racevision Test Server"); - - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - if (args.length == 1 && args[0].equals("-standalone")){ - return; - } - - if (args.length == 3 && args[0].equals("-server")){ - - sr = new StreamReceiver(args[1], Integer.valueOf(args[2]), "RaceStream"); - - } else if(args.length == 2 && args[0].equals("-server")){ - switch (args[1]) { - case "internal": - sr = new StreamReceiver("localhost", 4949, "RaceStream"); - break; - case "staffserver": - sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream"); - break; - case "official": - sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); - break; - } - } - //Change the StreamReceiver in this else block to change the default data source. - else{ - sr = new StreamReceiver("localhost", 4949, "RaceStream"); - } - - sr.start(); - StreamParser streamParser = new StreamParser("StreamParser"); - streamParser.start(); - - launch(args); - - - - } +// public static void main(String[] args) { +// StreamReceiver sr = null; +// +// new ServerThread("Racevision Test Server"); +// +// try { +// Thread.sleep(2000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// if (args.length == 1 && args[0].equals("-standalone")){ +// return; +// } +// +// if (args.length == 3 && args[0].equals("-server")){ +// +// sr = new StreamReceiver(args[1], Integer.valueOf(args[2]), "RaceStream"); +// +// } else if(args.length == 2 && args[0].equals("-server")){ +// switch (args[1]) { +// case "internal": +// sr = new StreamReceiver("localhost", 4949, "RaceStream"); +// break; +// case "staffserver": +// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream"); +// break; +// case "official": +// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); +// break; +// } +// } +// //Change the StreamReceiver in this else block to change the default data source. +// else{ +// sr = new StreamReceiver("localhost", 4949, "RaceStream"); +// } +// +// sr.start(); +// StreamParser streamParser = new StreamParser("StreamParser"); +// streamParser.start(); +// +// launch(args); +// +// +// +// } } diff --git a/src/main/java/seng302/models/map/Bound.java b/src/main/java/seng302/models/map/Bound.java new file mode 100644 index 00000000..aa700423 --- /dev/null +++ b/src/main/java/seng302/models/map/Bound.java @@ -0,0 +1,44 @@ +package seng302.models.map; + +/** + * The Bound class is to represent square territorial bounds on a map. It contains + * four extremity double values(N, E, S, W). N and S are represented as latitudes + * in radians. E and W are represented as longitudes in radians. + * + * Created by Haoming on 10/5/17 + */ +public class Bound { + + private double north, east, south, west; + + public Bound(double north, double east, double south, double west) { + this.north = north; + this.east = east; + this.south = south; + this.west = west; + } + + public double getCentreLat() { + return (north + south) / 2; + } + + public double getCentreLng() { + return (east + west) / 2; + } + + public double getNorth() { + return north; + } + + public double getEast() { + return east; + } + + public double getSouth() { + return south; + } + + public double getWest() { + return west; + } +} diff --git a/src/main/java/seng302/models/map/CanvasMap.java b/src/main/java/seng302/models/map/CanvasMap.java new file mode 100644 index 00000000..4a524e49 --- /dev/null +++ b/src/main/java/seng302/models/map/CanvasMap.java @@ -0,0 +1,49 @@ +package seng302.models.map; + +import javafx.scene.image.Image; + +import javax.imageio.ImageIO; +import javax.net.ssl.HttpsURLConnection; +import java.awt.image.BufferedImage; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; + +public class CanvasMap { + + private Bound bound; + private double width, height; // desired image size + private int zoom; + private String KEY = "AIzaSyC-5oOShMCY5Oy_9L7guYMPUPFHDMr37wE"; + + public CanvasMap(Bound bound, double width, double height) { + this.bound = bound; + this.width = width; + this.height = height; + } + + public Image getMapImage() { + + try { + System.out.println(getRequest()); + URL url = new URL(getRequest()); + HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); + + return new Image(connection.getInputStream()); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + private String getRequest() { + zoom = 14; + StringBuilder sb = new StringBuilder(); + sb.append("https://maps.googleapis.com/maps/api/staticmap?"); + sb.append(String.format("center=%f,%f", bound.getCentreLat(), bound.getCentreLng())); + sb.append(String.format("&zoom=%d", zoom)); + sb.append(String.format("&size=%.0fx%.0f&scale=2", width / 2, height / 2)); + sb.append(String.format("&key=%s", KEY)); + return sb.toString(); + } +} diff --git a/src/main/java/seng302/models/map/TestMapController.java b/src/main/java/seng302/models/map/TestMapController.java new file mode 100644 index 00000000..720dd408 --- /dev/null +++ b/src/main/java/seng302/models/map/TestMapController.java @@ -0,0 +1,23 @@ +package seng302.models.map; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.canvas.Canvas; +import javafx.scene.canvas.GraphicsContext; + +import java.net.URL; +import java.util.ResourceBundle; + +public class TestMapController implements Initializable{ + + @FXML + private Canvas mapCanvas; + + @Override + public void initialize(URL location, ResourceBundle resources) { + GraphicsContext gc = mapCanvas.getGraphicsContext2D(); + Bound bound = new Bound(57.662943, 11.848501, 57.673945, 11.824966); + CanvasMap canvasMap = new CanvasMap(bound, 1280, 960); + gc.drawImage(canvasMap.getMapImage(), 0, 0, 1280, 960); + } +} diff --git a/src/main/resources/views/TestMapView.fxml b/src/main/resources/views/TestMapView.fxml new file mode 100644 index 00000000..84df98f3 --- /dev/null +++ b/src/main/resources/views/TestMapView.fxml @@ -0,0 +1,13 @@ + + + + + + + + + + + + +