UrlTileSource: customize api key name #49
This commit is contained in:
parent
8bb63c875f
commit
2555fea5da
@ -31,6 +31,7 @@ public class MapzenGeojsonTileSource extends GeojsonTileSource {
|
|||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
super(DEFAULT_URL, DEFAULT_PATH, 1, 17);
|
super(DEFAULT_URL, DEFAULT_PATH, 1, 17);
|
||||||
|
keyName("api_key");
|
||||||
}
|
}
|
||||||
|
|
||||||
public T locale(String locale) {
|
public T locale(String locale) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 devemux86
|
* Copyright 2013 Hannes Janetzek
|
||||||
|
* Copyright 2016-2017 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -34,7 +35,7 @@ public class UrlTileSourceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void setApiKey_shouldAppendApiKey() throws Exception {
|
public void setApiKey_shouldAppendApiKey() throws Exception {
|
||||||
tileSource.setApiKey("testkey");
|
tileSource.setApiKey("testkey");
|
||||||
assertThat(tileSource.getTileUrl(new Tile(0, 0, (byte) 0))).endsWith("?api_key=testkey");
|
assertThat(tileSource.getTileUrl(new Tile(0, 0, (byte) 0))).endsWith("?key=testkey");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
* Copyright 2016 devemux86
|
* Copyright 2016-2017 devemux86
|
||||||
* Copyright 2016 Izumi Kawashima
|
* Copyright 2016 Izumi Kawashima
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
@ -33,10 +33,10 @@ public abstract class UrlTileSource extends TileSource {
|
|||||||
protected String tilePath;
|
protected String tilePath;
|
||||||
protected String url;
|
protected String url;
|
||||||
private HttpEngine.Factory engineFactory;
|
private HttpEngine.Factory engineFactory;
|
||||||
|
private String keyName = "key";
|
||||||
private String apiKey;
|
private String apiKey;
|
||||||
|
|
||||||
protected Builder() {
|
protected Builder() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Builder(String url, String tilePath, int zoomMin, int zoomMax) {
|
protected Builder(String url, String tilePath, int zoomMin, int zoomMax) {
|
||||||
@ -46,6 +46,11 @@ public abstract class UrlTileSource extends TileSource {
|
|||||||
this.zoomMax = zoomMax;
|
this.zoomMax = zoomMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T keyName(String keyName) {
|
||||||
|
this.keyName = keyName;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
public T apiKey(String apiKey) {
|
public T apiKey(String apiKey) {
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
return self();
|
return self();
|
||||||
@ -75,6 +80,7 @@ public abstract class UrlTileSource extends TileSource {
|
|||||||
private HttpEngine.Factory mHttpFactory;
|
private HttpEngine.Factory mHttpFactory;
|
||||||
private Map<String, String> mRequestHeaders = Collections.emptyMap();
|
private Map<String, String> mRequestHeaders = Collections.emptyMap();
|
||||||
private TileUrlFormatter mTileUrlFormatter = URL_FORMATTER;
|
private TileUrlFormatter mTileUrlFormatter = URL_FORMATTER;
|
||||||
|
private String mKeyName = "key";
|
||||||
private String mApiKey;
|
private String mApiKey;
|
||||||
|
|
||||||
public interface TileUrlFormatter {
|
public interface TileUrlFormatter {
|
||||||
@ -83,6 +89,7 @@ public abstract class UrlTileSource extends TileSource {
|
|||||||
|
|
||||||
protected UrlTileSource(Builder<?> builder) {
|
protected UrlTileSource(Builder<?> builder) {
|
||||||
super(builder);
|
super(builder);
|
||||||
|
mKeyName = builder.keyName;
|
||||||
mApiKey = builder.apiKey;
|
mApiKey = builder.apiKey;
|
||||||
mUrl = makeUrl(builder.url);
|
mUrl = makeUrl(builder.url);
|
||||||
mTilePath = builder.tilePath.split("\\{|\\}");
|
mTilePath = builder.tilePath.split("\\{|\\}");
|
||||||
@ -138,7 +145,7 @@ public abstract class UrlTileSource extends TileSource {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(mUrl).append(mTileUrlFormatter.formatTilePath(this, tile));
|
sb.append(mUrl).append(mTileUrlFormatter.formatTilePath(this, tile));
|
||||||
if (mApiKey != null) {
|
if (mApiKey != null) {
|
||||||
sb.append("?api_key=").append(mApiKey);
|
sb.append("?").append(mKeyName).append("=").append(mApiKey);
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public class MapzenMvtTileSource extends UrlTileSource {
|
|||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
super(DEFAULT_URL, DEFAULT_PATH, 1, 17);
|
super(DEFAULT_URL, DEFAULT_PATH, 1, 17);
|
||||||
|
keyName("api_key");
|
||||||
}
|
}
|
||||||
|
|
||||||
public T locale(String locale) {
|
public T locale(String locale) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user