fix: UrlTileSource.Builder was hiding zoom values from TileSource.Builder
- values set thorugh builder.minZoom()/maxZoom() were ignored should fix: #120
This commit is contained in:
parent
f4ffac44d2
commit
4c78f8652b
@ -5,6 +5,7 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.oscim.layers.tile.bitmap.BitmapTileLayer.FadeStep;
|
||||||
import org.oscim.tiling.ITileDataSource;
|
import org.oscim.tiling.ITileDataSource;
|
||||||
import org.oscim.tiling.source.HttpEngine;
|
import org.oscim.tiling.source.HttpEngine;
|
||||||
import org.oscim.tiling.source.LwHttp;
|
import org.oscim.tiling.source.LwHttp;
|
||||||
@ -43,6 +44,21 @@ public class BitmapTileSourceTest {
|
|||||||
Mockito.verify(okHttp).close();
|
Mockito.verify(okHttp).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldUseBuilderConfig() {
|
||||||
|
BitmapTileSource ts = BitmapTileSource.builder()
|
||||||
|
.url("http://example.com")
|
||||||
|
.zoomMax(42)
|
||||||
|
.zoomMin(23)
|
||||||
|
.fadeSteps(new FadeStep[] { new FadeStep(0, 10, 0.5f, 1.0f) })
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertThat(ts.getUrl().getHost()).isEqualTo("example.com");
|
||||||
|
assertThat(ts.getZoomLevelMin()).isEqualTo(23);
|
||||||
|
assertThat(ts.getZoomLevelMax()).isEqualTo(42);
|
||||||
|
assertThat(ts.getFadeSteps()).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test factory that allows the specific {@link HttpEngine} instance to be
|
* Test factory that allows the specific {@link HttpEngine} instance to be
|
||||||
* set.
|
* set.
|
||||||
|
@ -23,16 +23,16 @@ import org.oscim.layers.tile.bitmap.BitmapTileLayer.FadeStep;
|
|||||||
public abstract class TileSource {
|
public abstract class TileSource {
|
||||||
|
|
||||||
public abstract static class Builder<T extends Builder<T>> {
|
public abstract static class Builder<T extends Builder<T>> {
|
||||||
int minZoom, maxZoom;
|
protected int zoomMin, zoomMax;
|
||||||
FadeStep[] fadeSteps;
|
protected FadeStep[] fadeSteps;
|
||||||
|
|
||||||
public T zoomMin(int zoom) {
|
public T zoomMin(int zoom) {
|
||||||
minZoom = zoom;
|
zoomMin = zoom;
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T zoomMax(int zoom) {
|
public T zoomMax(int zoom) {
|
||||||
maxZoom = zoom;
|
zoomMax = zoom;
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +60,12 @@ public abstract class TileSource {
|
|||||||
mZoomMax = zoomMax;
|
mZoomMax = zoomMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileSource(Builder<?> builder) {
|
||||||
|
mZoomMin = builder.zoomMin;
|
||||||
|
mZoomMax = builder.zoomMax;
|
||||||
|
mFadeSteps = builder.fadeSteps;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract ITileDataSource getDataSource();
|
public abstract ITileDataSource getDataSource();
|
||||||
|
|
||||||
public abstract OpenResult open();
|
public abstract OpenResult open();
|
||||||
|
@ -28,7 +28,6 @@ import org.oscim.tiling.source.LwHttp.LwHttpFactory;
|
|||||||
public abstract class UrlTileSource extends TileSource {
|
public abstract class UrlTileSource extends TileSource {
|
||||||
|
|
||||||
public abstract static class Builder<T extends Builder<T>> extends TileSource.Builder<T> {
|
public abstract static class Builder<T extends Builder<T>> extends TileSource.Builder<T> {
|
||||||
protected int zoomMin, zoomMax;
|
|
||||||
protected String tilePath;
|
protected String tilePath;
|
||||||
protected String url;
|
protected String url;
|
||||||
private HttpEngine.Factory engineFactory;
|
private HttpEngine.Factory engineFactory;
|
||||||
@ -74,7 +73,9 @@ public abstract class UrlTileSource extends TileSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected UrlTileSource(Builder<?> builder) {
|
protected UrlTileSource(Builder<?> builder) {
|
||||||
this(builder.url, builder.tilePath, builder.zoomMin, builder.zoomMax);
|
super(builder);
|
||||||
|
mUrl = makeUrl(builder.url);
|
||||||
|
mTilePath = builder.tilePath.split("\\{|\\}");
|
||||||
mHttpFactory = builder.engineFactory;
|
mHttpFactory = builder.engineFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,17 +85,25 @@ public abstract class UrlTileSource extends TileSource {
|
|||||||
|
|
||||||
protected UrlTileSource(String urlString, String tilePath, int zoomMin, int zoomMax) {
|
protected UrlTileSource(String urlString, String tilePath, int zoomMin, int zoomMax) {
|
||||||
super(zoomMin, zoomMax);
|
super(zoomMin, zoomMax);
|
||||||
|
mUrl = makeUrl(urlString);
|
||||||
|
mTilePath = makeTilePath(tilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] makeTilePath(String tilePath) {
|
||||||
if (tilePath == null)
|
if (tilePath == null)
|
||||||
throw new IllegalArgumentException("tilePath cannot be null.");
|
throw new IllegalArgumentException("tilePath cannot be null.");
|
||||||
|
|
||||||
|
return tilePath.split("\\{|\\}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private URL makeUrl(String urlString) {
|
||||||
URL url = null;
|
URL url = null;
|
||||||
try {
|
try {
|
||||||
url = new URL(urlString);
|
url = new URL(urlString);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
mUrl = url;
|
return url;
|
||||||
mTilePath = tilePath.split("\\{|\\}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user