Implemented race map usage by JavaFX controller

- Renamed Map to RaceMap
- Fixed RaceMap.convertGPS bug
- Defined canvas coordinates in terms of map GPS

#story [9] #pair [cbt24,fwy13,zwu18]
main
cbt24 9 years ago
parent 0729ae719d
commit 6ca26d5bb1

@ -7,6 +7,7 @@ import javafx.scene.control.TableView;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Paint; import javafx.scene.paint.Paint;
import seng302.Coordinate; import seng302.Coordinate;
import seng302.RaceMap;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -19,8 +20,9 @@ public class RaceController extends Controller{
Canvas raceMap; Canvas raceMap;
@FXML @FXML
TableView boatInfoTable; TableView boatInfoTable;
private GraphicsContext gc;
private GraphicsContext gc;
private RaceMap map;
public void displayBoat(Coordinate coordinate, Paint paint){ public void displayBoat(Coordinate coordinate, Paint paint){
gc.setFill(paint); gc.setFill(paint);
@ -31,7 +33,10 @@ public class RaceController extends Controller{
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
this.gc = raceMap.getGraphicsContext2D(); this.gc = raceMap.getGraphicsContext2D();
Coordinate boat1coord = new Coordinate(60, 60); this.map = new RaceMap(32.321989, -64.866142, 32.273089, -64.814987, (int)raceMap.getWidth(), (int)raceMap.getHeight());
Coordinate boat1coord = this.map.convertGPS(32.296577, -64.854304);
System.out.println(boat1coord.getX() + " " + boat1coord.getY());
displayBoat(boat1coord, Color.AQUAMARINE); displayBoat(boat1coord, Color.AQUAMARINE);
} }
} }

@ -1,13 +1,15 @@
package seng302; package seng302;
import java.util.ArrayList;
/** /**
* Created by cbt24 on 15/03/17. * Created by cbt24 on 15/03/17.
*/ */
public class Map { public class RaceMap {
private double x1, x2, y1, y2; private double x1, x2, y1, y2;
private int width, height; private int width, height;
public Map(double x1, double y1, double x2, double y2, int width, int height) { public RaceMap(double x1, double y1, double x2, double y2, int width, int height) {
this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; this.width = width; this.height = height; this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; this.width = width; this.height = height;
} }
@ -19,6 +21,6 @@ public class Map {
* @see seng302.Coordinate * @see seng302.Coordinate
*/ */
public Coordinate convertGPS(double lat, double lon) { public Coordinate convertGPS(double lat, double lon) {
return new Coordinate((int)(width * (lat-x1)/(x2-x1)), (int)(height * (lon-x1)/(x2-x1))); return new Coordinate((int) (width * (lat - x1) / (x2 - x1)), (int) (height * (lon - y1) / (y2 - y1)));
} }
} }
Loading…
Cancel
Save