-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModisTileMapLayer.java
executable file
·220 lines (193 loc) · 7.49 KB
/
ModisTileMapLayer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// ModisTileMapLayer.java implements the class for displaying the boundaries
// of the MODIS tiles on the display.
//--------------------------------------------------------------------------
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
public class ModisTileMapLayer extends MapLayer
{
private imgViewer applet;
private Point[] horizontalLines; // array of horizontal lines to draw
private Point[] verticalLines; // array of vertical lines to draw
private LatLongToModisTile tileConv; // object to convert between tile
// numbers and projection cocrds
private Dimension dispSize; // saved display size
// track where the edge of the MODIS grid has been reached so the lines
// are only drawn to that point
private boolean limitLeft;
private boolean limitRight;
private boolean limitTop;
private boolean limitBottom;
// constructor for the MapLayer class
//-----------------------------------
public ModisTileMapLayer(imgViewer applet, Color layerColor,
int menuShortcut)
{
super(applet.imgArea, "MODIS Tiles", layerColor, menuShortcut, true);
this.applet = applet;
// create the object to convert between tile numbers and projection
// coordinates
tileConv = new LatLongToModisTile();
}
// method to configure the map layer for the displayed area.
// Returns: number of files that will need to be loaded
//----------------------------------------------------------
public int setDisplayAreaUsingLatLong(
LatLong minboxULdeg, LatLong minboxLRdeg, int projCode)
{
// nothing to do for this class, but required to implement
// return 0 since no files to load
return 0;
}
// method to configure the map layer for the displayed area in
// projection coordinates.
// Returns: number of files that will need to be loaded
//----------------------------------------------------------
public int setDisplayAreaUsingProjCoords(
Point ulCoord, Point lrCoord, int projCode)
{
// nothing to do for this class
// return 0 since no files to load
return 0;
}
// method to read the map layer file
//----------------------------------
public void read(CancelLoad isLoadCancelled, Point ulMeters, int projCode,
MapLayerLoadingCallback fileReadCallback)
{
// nothing to read
}
// method to clip the map layer components to the display
//-------------------------------------------------------
public void clip(Point upperLeft, int pixelSize, Dimension dispSize,
ProjectionTransformation proj)
{
double actualPixelSize = applet.imgArea.md.actualPixelSize;
// save the display size
this.dispSize = new Dimension(dispSize);
// calculate the lower right projection coordinate of the display
Point lowerRight =
new Point((int)(upperLeft.x + dispSize.width * actualPixelSize),
(int)(upperLeft.y - dispSize.height * actualPixelSize));
// get the tiles visible on the display
ModisTile ulTile = tileConv.coordinateToTile(upperLeft.x, upperLeft.y);
ModisTile lrTile = tileConv.coordinateToTile(lowerRight.x,lowerRight.y);
// make sure the upper left tile's upper left corner is visible
Point coord = tileConv.tileToCoordinate(ulTile, false);
if (coord.x < upperLeft.x)
ulTile.h++;
if (coord.y > upperLeft.y)
ulTile.v++;
// assume MODIS grid limits have not been reached at any side
limitLeft = false;
limitRight = false;
limitTop = false;
limitBottom = false;
// only display the real tiles and update the limit flags as needed
if (ulTile.h <= 0)
{
ulTile.h = 0;
limitLeft = true;
}
else if (ulTile.h > 36)
ulTile.h = 36;
if (ulTile.v <= 0)
{
ulTile.v = 0;
limitTop = true;
}
else if (ulTile.v > 18)
ulTile.v = 18;
if (lrTile.h < 0)
lrTile.h = 0;
else if (lrTile.h >= 36)
{
lrTile.h = 36;
limitRight = true;
}
if (lrTile.v < 0)
lrTile.v = 0;
else if (lrTile.v >= 18)
{
lrTile.v = 18;
limitBottom = true;
}
// set up the arrays for the visible tile boundaries
horizontalLines = new Point[lrTile.v - ulTile.v + 1];
verticalLines = new Point[lrTile.h - ulTile.h + 1];
// get the coordinates for each horizontal line
ModisTile tempTile = new ModisTile(ulTile.h, ulTile.v);
for (int i = ulTile.v; i <= lrTile.v; i++)
{
tempTile.v = i;
horizontalLines[i - ulTile.v]
= tileConv.tileToCoordinate(tempTile, false);
}
// get the coordinates for each vertical line
tempTile.v = ulTile.v;
for (int i = ulTile.h; i <= lrTile.h; i++)
{
tempTile.h = i;
verticalLines[i - ulTile.h]
= tileConv.tileToCoordinate(tempTile, false);
}
// convert the lines to pixels on the display
for (int i = 0; i < horizontalLines.length; i++)
{
horizontalLines[i].x = (int)((horizontalLines[i].x - upperLeft.x)
/ actualPixelSize);
horizontalLines[i].y = (int)((upperLeft.y - horizontalLines[i].y)
/ actualPixelSize);
}
for (int i = 0; i < verticalLines.length; i++)
{
verticalLines[i].x = (int)((verticalLines[i].x - upperLeft.x)
/ actualPixelSize);
verticalLines[i].y = (int)((upperLeft.y - verticalLines[i].y)
/ actualPixelSize);
}
}
// method to draw the map layer on the display
//--------------------------------------------
public void draw(Graphics g)
{
// if dispSize is null, clipping hasn't happened yet, so nothing to
// draw
if (dispSize == null)
return;
// set the starting and stopping points for the horizontal lines,
// factoring in whether the limit of the MODIS grid has been reached
// at the left and right.
int x1 = 0;
int x2 = dispSize.width;
if (limitLeft)
x1 = verticalLines[0].x;
if (limitRight)
x2 = verticalLines[verticalLines.length - 1].x;
// draw the horizontal lines on the display
for (int i = 0; i < horizontalLines.length; i++)
{
int y = horizontalLines[i].y;
g.setColor(color);
g.drawLine(x1,y,x2,y);
}
// set the starting and stopping points for the vertical lines,
// factoring in whether the limit of the MODIS grid has been reached
// at the top and bottom.
int y1 = 0;
int y2 = dispSize.height;
if (limitTop)
y1 = horizontalLines[0].y;
if (limitBottom)
y2 = horizontalLines[horizontalLines.length - 1].y;
// draw the vertical lines on the display
for (int i = 0; i < verticalLines.length; i++)
{
int x = verticalLines[i].x;
g.setColor(color);
g.drawLine(x,y1,x,y2);
}
}
}