Implemented resizable map and boundary scaling.
- Map can now be downsized - The boundaries are auto margined and fit in the center of the canvas. #implement
This commit is contained in:
@@ -32,7 +32,8 @@ public class App extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
|
primaryStage.minHeightProperty().setValue(600);
|
||||||
|
primaryStage.minWidthProperty().setValue(780);
|
||||||
//load the first container
|
//load the first container
|
||||||
try {
|
try {
|
||||||
FXMLLoader loader = new FXMLLoader();
|
FXMLLoader loader = new FXMLLoader();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
|
|||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
@@ -31,7 +32,7 @@ import java.util.ResourceBundle;
|
|||||||
*/
|
*/
|
||||||
public class RaceController extends Controller{
|
public class RaceController extends Controller{
|
||||||
@FXML
|
@FXML
|
||||||
AnchorPane canvasBase;
|
GridPane canvasBase;
|
||||||
|
|
||||||
ResizableRaceCanvas raceMap;
|
ResizableRaceCanvas raceMap;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
private RaceController controller;
|
private RaceController controller;
|
||||||
private boolean raceAnno = true;
|
private boolean raceAnno = true;
|
||||||
private ArrayList<GPSCoordinate> raceBoundaries;
|
private ArrayList<GPSCoordinate> raceBoundaries;
|
||||||
|
double[] xpoints = {}, ypoints = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the boats that are to be displayed in this race.
|
* Sets the boats that are to be displayed in this race.
|
||||||
@@ -164,14 +165,11 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawBoundaries(){
|
public void drawBoundaries(){
|
||||||
gc.setFill(Color.AQUA);
|
if (this.raceBoundaries == null){
|
||||||
double xpoints[] = new double[raceBoundaries.size()];
|
return;
|
||||||
double ypoints[] = new double[raceBoundaries.size()];
|
|
||||||
for (int i = 0; i < raceBoundaries.size(); i++){
|
|
||||||
GraphCoordinate coord = map.convertGPS(raceBoundaries.get(i));
|
|
||||||
xpoints[i] = coord.getX();
|
|
||||||
ypoints[i] = coord.getY();
|
|
||||||
}
|
}
|
||||||
|
gc.setFill(Color.AQUA);
|
||||||
|
setRaceBoundCoordinates();
|
||||||
gc.fillPolygon(xpoints, ypoints, xpoints.length);
|
gc.fillPolygon(xpoints, ypoints, xpoints.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +246,21 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRaceBoundaries(ArrayList<GPSCoordinate> boundaries) {
|
public void setRaceBoundaries(ArrayList<GPSCoordinate> boundaries) {
|
||||||
this.raceBoundaries = boundaries;
|
this.raceBoundaries = new ArrayList<>();
|
||||||
|
for (GPSCoordinate bound: boundaries){
|
||||||
|
raceBoundaries.add(bound);
|
||||||
|
}
|
||||||
|
setRaceBoundCoordinates();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRaceBoundCoordinates(){
|
||||||
|
xpoints = new double[this.raceBoundaries.size()];
|
||||||
|
ypoints = new double[this.raceBoundaries.size()];
|
||||||
|
for (int i = 0; i < raceBoundaries.size(); i++){
|
||||||
|
GraphCoordinate coord = map.convertGPS(raceBoundaries.get(i));
|
||||||
|
xpoints[i] = coord.getX();
|
||||||
|
ypoints[i] = coord.getY();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -35,8 +35,16 @@ public class RaceMap {
|
|||||||
* @see GraphCoordinate
|
* @see GraphCoordinate
|
||||||
*/
|
*/
|
||||||
public GraphCoordinate convertGPS(double lat, double lon) {
|
public GraphCoordinate convertGPS(double lat, double lon) {
|
||||||
|
int difference = Math.abs(width - height);
|
||||||
|
int size = width;
|
||||||
|
if (width > height){
|
||||||
|
size = height;
|
||||||
|
return new GraphCoordinate((int) ((size * (lon - x1) / (x2 - x1)) + difference/2), (int) (size - (size * (lat - y1) / (y2 - y1))));
|
||||||
|
}else{
|
||||||
|
return new GraphCoordinate((int) (size * (lon - x1) / (x2 - x1)), (int) ((size - (size * (lat - y1) / (y2 - y1))) + difference/2));
|
||||||
|
}
|
||||||
|
|
||||||
return new GraphCoordinate((int) (width * (lon - x1) / (x2 - x1)), (int) (height - (height * (lat - y1) / (y2 - y1))));
|
//return new GraphCoordinate((int) (width * (lon - x1) / (x2 - x1)), (int) (height - (height * (lat - y1) / (y2 - y1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -103,11 +103,11 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
minLongitude = boundary.get(i).getLongitude();
|
minLongitude = boundary.get(i).getLongitude();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(nBounds.getLength());
|
/*System.out.println(nBounds.getLength());
|
||||||
System.out.println(maxLatitude);
|
System.out.println(maxLatitude);
|
||||||
System.out.println(minLatitude);
|
System.out.println(minLatitude);
|
||||||
System.out.println(maxLongitude);
|
System.out.println(maxLongitude);
|
||||||
System.out.println(minLongitude);
|
System.out.println(minLongitude);*/
|
||||||
|
|
||||||
double difference = 0;//this will hold the largest difference so we can make the map square.
|
double difference = 0;//this will hold the largest difference so we can make the map square.
|
||||||
double latitudeDiff = Math.abs(Math.abs(boundary.get(maxLatitudeIndex).getLatitude()) - Math.abs(boundary.get(minLatitudeIndex).getLatitude()));
|
double latitudeDiff = Math.abs(Math.abs(boundary.get(maxLatitudeIndex).getLatitude()) - Math.abs(boundary.get(minLatitudeIndex).getLatitude()));
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.*?>
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.geometry.*?>
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
@@ -61,11 +62,18 @@
|
|||||||
</GridPane>
|
</GridPane>
|
||||||
<SplitPane fx:id="ongoingRacePane" dividerPositions="0.7" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<SplitPane fx:id="ongoingRacePane" dividerPositions="0.7" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<items>
|
<items>
|
||||||
<AnchorPane fx:id="canvasBase" prefHeight="581.0" prefWidth="537.0">
|
<GridPane fx:id="canvasBase">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="FPS" text="FPS: 0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" />
|
<Label fx:id="timer" layoutX="45.0" layoutY="146.0" text="0:0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" GridPane.halignment="RIGHT" GridPane.valignment="BOTTOM" />
|
||||||
<Label fx:id="timer" layoutX="45.0" layoutY="146.0" text="0:0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" />
|
<Pane prefWidth="300.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
||||||
<TitledPane fx:id="userControl" animated="false" text="User Control" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<children>
|
||||||
|
<TitledPane fx:id="userControl" animated="false" prefWidth="300.0" text="User Control" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
||||||
<content>
|
<content>
|
||||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
@@ -76,7 +84,10 @@
|
|||||||
</content>
|
</content>
|
||||||
</TitledPane>
|
</TitledPane>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</Pane>
|
||||||
|
<Label fx:id="FPS" text="FPS: 0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" GridPane.halignment="LEFT" GridPane.valignment="BOTTOM" />
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
<AnchorPane layoutX="450.0" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="200.0" GridPane.columnIndex="1">
|
<AnchorPane layoutX="450.0" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="200.0" GridPane.columnIndex="1">
|
||||||
<children>
|
<children>
|
||||||
<TableView fx:id="boatInfoTable" layoutX="-2.0" prefHeight="600.0" prefWidth="264.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="-62.0" AnchorPane.topAnchor="0.0">
|
<TableView fx:id="boatInfoTable" layoutX="-2.0" prefHeight="600.0" prefWidth="264.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="-62.0" AnchorPane.topAnchor="0.0">
|
||||||
|
|||||||
Reference in New Issue
Block a user