* could be there, too, but then we wouldn't do anything.
*/
protected OMGraphicList constructGraticuleLines(float up, float down,
float left, float right,
int showWhichLines) {
OMGraphicList lines = new OMGraphicList();
// Set the line limits for the lat/lon lines...
int north = (int) Math.ceil(up);
if (north > 80)
north = 80;
int south = (int) Math.floor(down);
south -= (south % 10); // Push down to the lowest 10 degree
// line.
// for neg numbers, Mod raised it, lower it again. Also
// handle straddling the equator.
if ((south < 0 && south > -80) || south == 0)
south -= 10;
int west = (int) Math.floor(left);
west -= (west % 10);
// for neg numbers, Mod raised it, lower it again. Also
// handle straddling the prime meridian.
if ((west < 0 && west > -180) || west == 0)
west -= 10;
int east = (int) Math.ceil(right);
if (east > 180)
east = 180;
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);
}
}
if (Debug.debugging("graticule")) {
Debug.output("GraticuleLayer.constructTenDegreeLines(): "
+ "constructed " + lines.size() + " graticule lines");
}
lines.generate(projection);
return lines;
}