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
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
this.primaryStage = primaryStage;
|
||||
|
||||
primaryStage.minHeightProperty().setValue(600);
|
||||
primaryStage.minWidthProperty().setValue(780);
|
||||
//load the first container
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
|
||||
@@ -12,6 +12,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.util.Callback;
|
||||
@@ -31,7 +32,7 @@ import java.util.ResourceBundle;
|
||||
*/
|
||||
public class RaceController extends Controller{
|
||||
@FXML
|
||||
AnchorPane canvasBase;
|
||||
GridPane canvasBase;
|
||||
|
||||
ResizableRaceCanvas raceMap;
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
private RaceController controller;
|
||||
private boolean raceAnno = true;
|
||||
private ArrayList<GPSCoordinate> raceBoundaries;
|
||||
double[] xpoints = {}, ypoints = {};
|
||||
|
||||
/**
|
||||
* Sets the boats that are to be displayed in this race.
|
||||
@@ -164,14 +165,11 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
|
||||
public void drawBoundaries(){
|
||||
gc.setFill(Color.AQUA);
|
||||
double xpoints[] = new double[raceBoundaries.size()];
|
||||
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();
|
||||
if (this.raceBoundaries == null){
|
||||
return;
|
||||
}
|
||||
gc.setFill(Color.AQUA);
|
||||
setRaceBoundCoordinates();
|
||||
gc.fillPolygon(xpoints, ypoints, xpoints.length);
|
||||
}
|
||||
|
||||
@@ -248,7 +246,21 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
System.out.println(nBounds.getLength());
|
||||
/*System.out.println(nBounds.getLength());
|
||||
System.out.println(maxLatitude);
|
||||
System.out.println(minLatitude);
|
||||
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 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"?>
|
||||
|
||||
<?import javafx.scene.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
@@ -61,22 +62,32 @@
|
||||
</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">
|
||||
<items>
|
||||
<AnchorPane fx:id="canvasBase" prefHeight="581.0" prefWidth="537.0">
|
||||
<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" />
|
||||
<TitledPane fx:id="userControl" animated="false" text="User Control" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<CheckBox fx:id="showAnno" mnemonicParsing="false" selected="true" text="Show Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="25.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<GridPane fx:id="canvasBase">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<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" />
|
||||
<Pane prefWidth="300.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
||||
<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>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<CheckBox fx:id="showAnno" mnemonicParsing="false" selected="true" text="Show Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="25.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
</children>
|
||||
</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">
|
||||
<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">
|
||||
|
||||
Reference in New Issue
Block a user