@ -19,7 +19,9 @@ public class RaceXMLReader extends XMLReader{
private Color [ ] colors = { Color . BLUEVIOLET , Color . BLACK , Color . RED , Color . ORANGE , Color . DARKOLIVEGREEN , Color . LIMEGREEN } ; //TODO make this established in xml or come up with a better system.
private Color [ ] colors = { Color . BLUEVIOLET , Color . BLACK , Color . RED , Color . ORANGE , Color . DARKOLIVEGREEN , Color . LIMEGREEN } ; //TODO make this established in xml or come up with a better system.
private ArrayList < Leg > legs = new ArrayList < > ( ) ;
private ArrayList < Leg > legs = new ArrayList < > ( ) ;
private GPSCoordinate mark , startPt1 , startPt2 , finishPt1 , finishPt2 , leewardPt1 , leewardPt2 , windwardPt1 , windwardPt2 ;
private GPSCoordinate mark , startPt1 , startPt2 , finishPt1 , finishPt2 , leewardPt1 , leewardPt2 , windwardPt1 , windwardPt2 ;
private GPSCoordinate mapTopLeft , mapBottomRight ;
private ArrayList < GPSCoordinate > boundary = new ArrayList < > ( ) ;
private ArrayList < GPSCoordinate > boundary = new ArrayList < > ( ) ;
private static double COORDINATEPADDING = 0.0005 ;
public RaceXMLReader ( String filePath ) throws IOException , SAXException , ParserConfigurationException {
public RaceXMLReader ( String filePath ) throws IOException , SAXException , ParserConfigurationException {
@ -73,9 +75,61 @@ public class RaceXMLReader extends XMLReader{
NodeList nCourse = doc . getElementsByTagName ( "course" ) ;
NodeList nCourse = doc . getElementsByTagName ( "course" ) ;
NodeList nBounds = ( ( Element ) nCourse . item ( 0 ) ) . getElementsByTagName ( "boundaries" ) ;
NodeList nBounds = ( ( Element ) nCourse . item ( 0 ) ) . getElementsByTagName ( "boundaries" ) ;
nBounds = ( ( Element ) nBounds . item ( 0 ) ) . getElementsByTagName ( "coordinate" ) ;
int maxLatitudeIndex = 0 ;
double maxLatitude = - Double . MIN_VALUE ;
int maxLongitudeIndex = 0 ;
double maxLongitude = - 180 ;
int minLatitudeIndex = 0 ;
double minLatitude = Double . MAX_VALUE ;
int minLongitudeIndex = 0 ;
double minLongitude = Double . MAX_VALUE ;
for ( int i = 0 ; i < nBounds . getLength ( ) ; i + + ) {
for ( int i = 0 ; i < nBounds . getLength ( ) ; i + + ) {
boundary . add ( getCoordinates ( nBounds , i ) ) ;
boundary . add ( getCoordinates ( ( Element ) nBounds . item ( i ) ) ) ;
if ( boundary . get ( i ) . getLatitude ( ) > maxLatitude ) {
maxLatitudeIndex = i ;
maxLatitude = boundary . get ( i ) . getLatitude ( ) ;
}
if ( boundary . get ( i ) . getLatitude ( ) < minLatitude ) {
minLatitudeIndex = i ;
minLatitude = boundary . get ( i ) . getLatitude ( ) ;
}
if ( boundary . get ( i ) . getLongitude ( ) > maxLongitude ) {
maxLongitudeIndex = i ;
maxLongitude = boundary . get ( i ) . getLongitude ( ) ;
}
if ( boundary . get ( i ) . getLongitude ( ) < minLongitude ) {
minLongitudeIndex = i ;
minLongitude = boundary . get ( i ) . getLongitude ( ) ;
}
}
}
System . out . println ( nBounds . getLength ( ) ) ;
System . out . println ( maxLatitude ) ;
System . out . println ( minLatitude ) ;
System . out . println ( maxLongitude ) ;
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 ( ) ) ) ;
double longitudeDiff = Math . abs ( Math . abs ( boundary . get ( maxLongitudeIndex ) . getLongitude ( ) ) - Math . abs ( boundary . get ( minLongitudeIndex ) . getLongitude ( ) ) ) ;
if ( latitudeDiff > = longitudeDiff ) {
difference = latitudeDiff - longitudeDiff ;
maxLongitude + = difference / 2 ;
minLongitude - = difference / 2 ;
} else {
difference = longitudeDiff - latitudeDiff ;
maxLatitude + = difference / 2 ;
minLatitude - = difference / 2 ;
}
maxLatitude + = COORDINATEPADDING ;
minLatitude - = COORDINATEPADDING ;
maxLongitude + = COORDINATEPADDING ;
minLongitude - = COORDINATEPADDING ;
//now create map boundaries
//top left canvas point is min logitude, max latitude
//bottom right of canvas point is min longitude, max latitude.
mapTopLeft = new GPSCoordinate ( minLatitude , minLongitude ) ;
mapBottomRight = new GPSCoordinate ( maxLatitude , maxLongitude ) ;
NodeList nMarks = ( ( Element ) nCourse . item ( 0 ) ) . getElementsByTagName ( "marker" ) ;
NodeList nMarks = ( ( Element ) nCourse . item ( 0 ) ) . getElementsByTagName ( "marker" ) ;
startPt1 = getCoordinates ( nMarks , 0 ) ;
startPt1 = getCoordinates ( nMarks , 0 ) ;
@ -162,4 +216,12 @@ public class RaceXMLReader extends XMLReader{
public ArrayList < GPSCoordinate > getBoundary ( ) {
public ArrayList < GPSCoordinate > getBoundary ( ) {
return boundary ;
return boundary ;
}
}
public GPSCoordinate getMapTopLeft ( ) {
return mapTopLeft ;
}
public GPSCoordinate getMapBottomRight ( ) {
return mapBottomRight ;
}
}
}