1313import gov .nasa .worldwind .WorldWind ;
1414import gov .nasa .worldwind .geom .BoundingBox ;
1515import gov .nasa .worldwind .geom .Frustum ;
16+ import gov .nasa .worldwind .geom .Location ;
1617import gov .nasa .worldwind .geom .Sector ;
1718import gov .nasa .worldwind .geom .Vec3 ;
1819import gov .nasa .worldwind .render .RenderContext ;
@@ -116,13 +117,14 @@ public Tile(Sector sector, Level level, int row, int column) {
116117 *
117118 * @param tileDelta the level's tile delta in degrees
118119 * @param latitude the tile's minimum latitude in degrees
120+ * @param origin the origin of the grid
119121 *
120122 * @return the computed row number
121123 */
122- public static int computeRow (double tileDelta , double latitude ) {
123- int row = (int ) Math .floor ((latitude + 90 ) / tileDelta );
124+ public static int computeRow (double tileDelta , double latitude , double origin ) {
125+ int row = (int ) Math .floor ((latitude - origin ) / tileDelta );
124126
125- if (latitude == 90 ) {
127+ if (latitude - origin == 180 ) {
126128 row -= 1 ; // if latitude is at the end of the grid, subtract 1 from the computed row to return the last row
127129 }
128130
@@ -134,13 +136,14 @@ public static int computeRow(double tileDelta, double latitude) {
134136 *
135137 * @param tileDelta the level's tile delta in degrees
136138 * @param longitude the tile's minimum longitude in degrees
139+ * @param origin the origin of the grid
137140 *
138141 * @return The computed column number
139142 */
140- public static int computeColumn (double tileDelta , double longitude ) {
141- int col = (int ) Math .floor ((longitude + 180 ) / tileDelta );
143+ public static int computeColumn (double tileDelta , double longitude , double origin ) {
144+ int col = (int ) Math .floor ((longitude - origin ) / tileDelta );
142145
143- if (longitude == 180 ) {
146+ if (longitude - origin == 360 ) {
144147 col -= 1 ; // if longitude is at the end of the grid, subtract 1 from the computed column to return the last column
145148 }
146149
@@ -152,13 +155,14 @@ public static int computeColumn(double tileDelta, double longitude) {
152155 *
153156 * @param tileDelta the level's tile delta in degrees
154157 * @param maxLatitude the tile's maximum latitude in degrees
158+ * @param origin the origin of the grid
155159 *
156160 * @return the computed row number
157161 */
158- public static int computeLastRow (double tileDelta , double maxLatitude ) {
159- int row = (int ) Math .ceil ((maxLatitude + 90 ) / tileDelta - 1 );
162+ public static int computeLastRow (double tileDelta , double maxLatitude , double origin ) {
163+ int row = (int ) Math .ceil ((maxLatitude - origin ) / tileDelta - 1 );
160164
161- if (maxLatitude + 90 < tileDelta ) {
165+ if (maxLatitude - origin < tileDelta ) {
162166 row = 0 ; // if max latitude is in the first row, set the max row to 0
163167 }
164168
@@ -170,13 +174,14 @@ public static int computeLastRow(double tileDelta, double maxLatitude) {
170174 *
171175 * @param tileDelta the level's tile delta in degrees
172176 * @param maxLongitude the tile's maximum longitude in degrees
177+ * @param origin the origin of the grid
173178 *
174179 * @return The computed column number
175180 */
176- public static int computeLastColumn (double tileDelta , double maxLongitude ) {
177- int col = (int ) Math .ceil ((maxLongitude + 180 ) / tileDelta - 1 );
181+ public static int computeLastColumn (double tileDelta , double maxLongitude , double origin ) {
182+ int col = (int ) Math .ceil ((maxLongitude - origin ) / tileDelta - 1 );
178183
179- if (maxLongitude + 180 < tileDelta ) {
184+ if (maxLongitude - origin < tileDelta ) {
180185 col = 0 ; // if max longitude is in the first column, set the max column to 0
181186 }
182187
@@ -211,15 +216,16 @@ public static Collection<Tile> assembleTilesForLevel(Level level, TileFactory ti
211216 }
212217
213218 Sector sector = level .parent .sector ;
219+ Location tileOrigin = level .parent .tileOrigin ;
214220 double tileDelta = level .tileDelta ;
215221
216- int firstRow = Tile .computeRow (tileDelta , sector .minLatitude ());
217- int lastRow = Tile .computeLastRow (tileDelta , sector .maxLatitude ());
218- int firstCol = Tile .computeColumn (tileDelta , sector .minLongitude ());
219- int lastCol = Tile .computeLastColumn (tileDelta , sector .maxLongitude ());
222+ int firstRow = Tile .computeRow (tileDelta , sector .minLatitude (), tileOrigin . latitude );
223+ int lastRow = Tile .computeLastRow (tileDelta , sector .maxLatitude (), tileOrigin . latitude );
224+ int firstCol = Tile .computeColumn (tileDelta , sector .minLongitude (), tileOrigin . longitude );
225+ int lastCol = Tile .computeLastColumn (tileDelta , sector .maxLongitude (), tileOrigin . longitude );
220226
221- double firstRowLat = - 90 + firstRow * tileDelta ;
222- double firstRowLon = - 180 + firstCol * tileDelta ;
227+ double firstRowLat = tileOrigin . latitude + firstRow * tileDelta ;
228+ double firstRowLon = tileOrigin . longitude + firstCol * tileDelta ;
223229 double lat = firstRowLat ;
224230 double lon ;
225231
0 commit comments