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
|
package tim.prune.gui.map.tile;
import tim.prune.gui.map.MapSource;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
/**
* Definition of a single tile including its source
* and its coordinates
*/
public class TileDef
{
public final MapSource _mapSource;
public final int _layerIdx;
public final int _x;
public final int _y;
public final int _zoom;
public TileDef(MapSource inSource, int layerIdx, int x, int y, int zoom)
{
_mapSource = inSource;
_layerIdx = layerIdx;
_x = x;
_y = y;
_zoom = zoom;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TileDef tileDef = (TileDef) o;
return _layerIdx == tileDef._layerIdx && _x == tileDef._x && _y == tileDef._y
&& _zoom == tileDef._zoom && _mapSource.getName().equals(tileDef._mapSource.getName());
}
@Override
public int hashCode() {
return Objects.hash(_mapSource.getName(), _layerIdx, _x, _y, _zoom);
}
@Override
public String toString() {
return "TileDef{layer=" + _layerIdx +
", x=" + _x + ", y=" + _y + ", zoom=" + _zoom + '}';
}
/**
* @return a new TileDef describing the next zoom level out
*/
public TileDef zoomOut() {
return new TileDef(_mapSource, _layerIdx, _x/2, _y/2, _zoom-1);
}
/**
* @return a new TileDef describing one of the tiles in the next zoom level in
*/
public TileDef zoomIn(int inIndex) {
return new TileDef(_mapSource, _layerIdx, _x*2 + (inIndex%2), _y*2 + (inIndex/2), _zoom+1);
}
/**
* @return a URL with which to get the specified tile
*/
public URL getUrl()
{
try {
return new URL(_mapSource.makeURL(_layerIdx, _zoom, _x, _y));
}
catch (MalformedURLException ignored) {
return null;
}
}
/**
* @return the file path for this tile (assuming it's a single one)
*/
public String getFilePath() {
return _mapSource.makeFilePath(_layerIdx, _zoom, _x, _y);
}
}
|