int stepSize;
// Choose how far apart the lines will be.
stepSize = ((showWhichLines == SHOW_ONES) ? 1 : 5);
float[] llp;
OMPoly currentLine;
OMText currentText;
// For calculating text locations
java.awt.Point point;
LatLonPoint llpoint;
Projection projection = getProjection();
// generate other parallels of latitude be creating series
// of polylines
for (int i = south; i < north; i += stepSize) {
float lat = (float) i;
// generate parallel of latitude North/South of the
// equator
if (west < 0 && east > 0) {
llp = new float[6];
llp[2] = lat;
llp[3] = 0f;
llp[4] = lat;
llp[5] = east;
} else {
llp = new float[4];
llp[2] = lat;
llp[3] = east;
}
llp[0] = lat;
llp[1] = west;
// Do not duplicate the 10 degree line.
if ((lat % 10) != 0) {
currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT
: OMGraphic.LINETYPE_RHUMB);
if ((lat % 5) == 0) {
currentLine.setLinePaint(fiveDegreeColor);
} else {
currentLine.setLinePaint(oneDegreeColor);
}
lines.addOMGraphic(currentLine);
}
if (showRuler && (lat % 2) == 0) {
if (boxy) {
point = projection.forward(lat, west);
point.x = 0;
llpoint = projection.inverse(point);
} else {
llpoint = new LatLonPoint(lat, west);
while (projection.forward(llpoint).x < 0) {
llpoint.setLongitude(llpoint.getLongitude() + stepSize);
}
}
currentText = new OMText(llpoint.getLatitude(), llpoint.getLongitude(),
// Move them up a little
(int) 2, (int) -2, Integer.toString((int) lat), font, OMText.JUSTIFY_LEFT);
currentText.setLinePaint(textColor);
lines.addOMGraphic(currentText);
}
}
// generate lines of longitude
for (int i = west; i < east; i += stepSize) {
float lon = (float) i;
if (north < 0 && south > 0) {
llp = new float[6];
llp[2] = 0f;
llp[3] = lon;
llp[4] = south;
llp[5] = lon;
} else {
llp = new float[4];
llp[2] = south;
llp[3] = lon;
}
llp[0] = north;
llp[1] = lon;
if ((lon % 10) != 0) {
currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT
: OMGraphic.LINETYPE_GREATCIRCLE);
if ((lon % 5) == 0) {
currentLine.setLinePaint(fiveDegreeColor);
} else {
currentLine.setLinePaint(oneDegreeColor);
}
lines.addOMGraphic(currentLine);
}
if (showRuler && (lon % 2) == 0) {
if (boxy) {
point = projection.forward(south, lon);
point.y = projection.getHeight();
llpoint = projection.inverse(point);
} else {
llpoint = new LatLonPoint(south, lon);
while (projection.forward(llpoint).y > projection.getHeight()) {
llpoint.setLatitude(llpoint.getLatitude() + stepSize);
}
}
currentText = new OMText(llpoint.getLatitude(), llpoint.getLongitude(),
// Move them up a little
(int) 2, (int) -5, Integer.toString((int) lon), font, OMText.JUSTIFY_CENTER);
currentText.setLinePaint(textColor);
lines.addOMGraphic(currentText);
}
}