Skip to content

Commit d9b5aba

Browse files
committed
Add tile origin attribute to level set.
1 parent 8f023bb commit d9b5aba

6 files changed

Lines changed: 35 additions & 7 deletions

File tree

worldwind/src/main/java/gov/nasa/worldwind/globe/BasicTessellator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

1818
import gov.nasa.worldwind.draw.BasicDrawableTerrain;
19+
import gov.nasa.worldwind.geom.Location;
1920
import gov.nasa.worldwind.geom.Range;
2021
import gov.nasa.worldwind.geom.Sector;
2122
import gov.nasa.worldwind.geom.Vec3;
@@ -32,7 +33,7 @@
3233
public class BasicTessellator implements Tessellator, TileFactory {
3334

3435
// ~0.6 meter resolution
35-
protected LevelSet levelSet = new LevelSet(new Sector().setFullSphere(), 90, 20, 32, 32);
36+
protected LevelSet levelSet = new LevelSet(new Sector().setFullSphere(), new Location(-90, -180), 90, 20, 32, 32);
3637

3738
protected double detailControl = 80;
3839

worldwind/src/main/java/gov/nasa/worldwind/layer/LayerFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.RejectedExecutionException;
2323

2424
import gov.nasa.worldwind.WorldWind;
25+
import gov.nasa.worldwind.geom.Location;
2526
import gov.nasa.worldwind.geom.Sector;
2627
import gov.nasa.worldwind.ogc.WmsLayerConfig;
2728
import gov.nasa.worldwind.ogc.WmsTileFactory;
@@ -670,7 +671,7 @@ protected LevelSet createWmtsLevelSet(WmtsLayer wmtsLayer, CompatibleTileMatrixS
670671
}
671672
int imageSize = tileMatrixSet.getTileMatrices().get(0).getTileHeight();
672673

673-
return new LevelSet(boundingBox, 90.0, compatibleTileMatrixSet.tileMatrices.size(), imageSize, imageSize);
674+
return new LevelSet(boundingBox, new Location(-90, -180), 90, compatibleTileMatrixSet.tileMatrices.size(), imageSize, imageSize);
674675
}
675676

676677
protected String buildWmtsKvpTemplate(String kvpServiceAddress, String layer, String format, String styleIdentifier, String tileMatrixSet) {

worldwind/src/main/java/gov/nasa/worldwind/layer/mercator/MercatorTiledImageLayer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gov.nasa.worldwind.layer.mercator;
22

33
import gov.nasa.worldwind.WorldWind;
4+
import gov.nasa.worldwind.geom.Location;
45
import gov.nasa.worldwind.geom.Sector;
56
import gov.nasa.worldwind.layer.RenderableLayer;
67
import gov.nasa.worldwind.render.ImageOptions;
@@ -23,7 +24,7 @@ public MercatorTiledImageLayer(String name, int numLevels, int firstLevelOffset,
2324

2425
MercatorTiledSurfaceImage surfaceImage = new MercatorTiledSurfaceImage();
2526
surfaceImage.setLevelSet(new LevelSet(
26-
MercatorSector.fromDegrees(-1.0, 1.0, - FULL_SPHERE / 2, FULL_SPHERE / 2),
27+
MercatorSector.fromDegrees(-1.0, 1.0, - FULL_SPHERE / 2, FULL_SPHERE / 2), new Location(-90, -180),
2728
FULL_SPHERE / (1 << firstLevelOffset), numLevels - firstLevelOffset, tileSize, tileSize));
2829
surfaceImage.setTileFactory(this);
2930
if(!overlay) {

worldwind/src/main/java/gov/nasa/worldwind/util/LevelSet.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package gov.nasa.worldwind.util;
77

8+
import gov.nasa.worldwind.geom.Location;
89
import gov.nasa.worldwind.geom.Sector;
910

1011
/**
@@ -18,6 +19,11 @@ public class LevelSet {
1819
*/
1920
public final Sector sector = new Sector();
2021

22+
/**
23+
* Tile origin for this level set
24+
*/
25+
public final Location tileOrigin = new Location();
26+
2127
/**
2228
* The geographic width and height in degrees of tiles in the first level (lowest resolution) of this level set.
2329
*/
@@ -55,6 +61,7 @@ public LevelSet() {
5561
* Constructs a level set with specified parameters.
5662
*
5763
* @param sector the sector spanned by this level set
64+
* @param tileOrigin the origin for this level set
5865
* @param firstLevelDelta the geographic width and height in degrees of tiles in the first level (lowest resolution)
5966
* of the level set
6067
* @param numLevels the number of levels in the level set
@@ -67,12 +74,17 @@ public LevelSet() {
6774
*
6875
* @throws IllegalArgumentException If any argument is null, or if any dimension is zero
6976
*/
70-
public LevelSet(Sector sector, double firstLevelDelta, int numLevels, int tileWidth, int tileHeight) {
77+
public LevelSet(Sector sector, Location tileOrigin, double firstLevelDelta, int numLevels, int tileWidth, int tileHeight) {
7178
if (sector == null) {
7279
throw new IllegalArgumentException(
7380
Logger.logMessage(Logger.ERROR, "LevelSet", "constructor", "missingSector"));
7481
}
7582

83+
if (tileOrigin == null) {
84+
throw new IllegalArgumentException(
85+
Logger.logMessage(Logger.ERROR, "LevelSet", "constructor", "missingTileOrigin"));
86+
}
87+
7688
if (firstLevelDelta <= 0) {
7789
throw new IllegalArgumentException(
7890
Logger.logMessage(Logger.ERROR, "LevelSet", "constructor", "invalidTileDelta"));
@@ -89,6 +101,7 @@ public LevelSet(Sector sector, double firstLevelDelta, int numLevels, int tileWi
89101
}
90102

91103
this.sector.set(sector);
104+
this.tileOrigin.set(tileOrigin);
92105
this.firstLevelDelta = firstLevelDelta;
93106
this.tileWidth = tileWidth;
94107
this.tileHeight = tileHeight;
@@ -116,6 +129,11 @@ public LevelSet(LevelSetConfig config) {
116129
Logger.logMessage(Logger.ERROR, "LevelSet", "constructor", "missingSector"));
117130
}
118131

132+
if (config.tileOrigin == null) {
133+
throw new IllegalArgumentException(
134+
Logger.logMessage(Logger.ERROR, "LevelSet", "constructor", "missingTileOrigin"));
135+
}
136+
119137
if (config.firstLevelDelta <= 0) {
120138
throw new IllegalArgumentException(
121139
Logger.logMessage(Logger.ERROR, "LevelSet", "constructor", "invalidTileDelta"));
@@ -132,6 +150,7 @@ public LevelSet(LevelSetConfig config) {
132150
}
133151

134152
this.sector.set(config.sector);
153+
this.tileOrigin.set(config.tileOrigin);
135154
this.firstLevelDelta = config.firstLevelDelta;
136155
this.tileWidth = config.tileWidth;
137156
this.tileHeight = config.tileHeight;
@@ -141,8 +160,7 @@ public LevelSet(LevelSetConfig config) {
141160

142161
protected void assembleLevels() {
143162
for (int i = 0, len = this.levels.length; i < len; i++) {
144-
double n = Math.pow(2, i);
145-
double delta = firstLevelDelta / n;
163+
double delta = firstLevelDelta / (1 << i);
146164
this.levels[i] = new Level(this, i, delta);
147165
}
148166
}

worldwind/src/main/java/gov/nasa/worldwind/util/LevelSetConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package gov.nasa.worldwind.util;
77

8+
import gov.nasa.worldwind.geom.Location;
89
import gov.nasa.worldwind.geom.Sector;
910

1011
/**
@@ -18,6 +19,11 @@ public class LevelSetConfig {
1819
*/
1920
public final Sector sector = new Sector().setFullSphere();
2021

22+
/**
23+
* Tile origin for level set
24+
*/
25+
public final Location tileOrigin = new Location(-90, -180);
26+
2127
/**
2228
* The geographic width and height in degrees of tiles in the first level (lowest resolution) of the level set.
2329
*/

worldwind/src/test/java/gov/nasa/worldwind/globe/BasicTerrainTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.powermock.modules.junit4.PowerMockRunner;
1515

1616
import gov.nasa.worldwind.WorldWind;
17+
import gov.nasa.worldwind.geom.Location;
1718
import gov.nasa.worldwind.geom.Sector;
1819
import gov.nasa.worldwind.geom.Vec3;
1920
import gov.nasa.worldwind.util.LevelSet;
@@ -81,7 +82,7 @@ public void setUp() {
8182
this.terrain = new BasicTerrain();
8283

8384
// Add a terrain tile used to the mocked terrain
84-
LevelSet levelSet = new LevelSet(new Sector().setFullSphere(), 1.0, 1, 5, 5); // tiles with 5x5 vertices
85+
LevelSet levelSet = new LevelSet(new Sector().setFullSphere(), new Location(-90, -180), 1.0, 1, 5, 5); // tiles with 5x5 vertices
8586
TerrainTile tile = new TerrainTile(new Sector(0, 0, 1, 1), levelSet.firstLevel(), 90, 180);
8687
((BasicTerrain) this.terrain).addTile(tile);
8788

0 commit comments

Comments
 (0)