[android] - use URI instead of URL to enable asset loading
This commit is contained in:
@@ -10,6 +10,7 @@ import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.geojson.Geometry;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -80,7 +81,7 @@ public class GeoJsonSource extends Source {
|
||||
*/
|
||||
public GeoJsonSource(String id, @Nullable String geoJson, GeoJsonOptions options) {
|
||||
super();
|
||||
if (geoJson == null || geoJson.startsWith("http")) {
|
||||
if (geoJson == null || geoJson.startsWith("http") || geoJson.startsWith("asset") || geoJson.startsWith("file")) {
|
||||
throw new IllegalArgumentException("Expected a raw json body");
|
||||
}
|
||||
initialize(id, options);
|
||||
@@ -92,7 +93,9 @@ public class GeoJsonSource extends Source {
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url remote json file
|
||||
* @deprecated use {@link #GeoJsonSource(String, URI)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public GeoJsonSource(String id, URL url) {
|
||||
super();
|
||||
initialize(id, null);
|
||||
@@ -105,13 +108,40 @@ public class GeoJsonSource extends Source {
|
||||
* @param id the source id
|
||||
* @param url remote json file
|
||||
* @param options options
|
||||
* @deprecated use {@link #GeoJsonSource(String, URI, GeoJsonOptions)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public GeoJsonSource(String id, URL url, GeoJsonOptions options) {
|
||||
super();
|
||||
initialize(id, options);
|
||||
nativeSetUrl(url.toExternalForm());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a GeoJsonSource from a geo json file
|
||||
*
|
||||
* @param id the source id
|
||||
* @param uri unique resource identifier
|
||||
*/
|
||||
public GeoJsonSource(String id, URI uri) {
|
||||
super();
|
||||
initialize(id, null);
|
||||
nativeSetUrl(uri.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a GeoJsonSource from a geo json file and non-default GeoJsonOptions
|
||||
*
|
||||
* @param id the source id
|
||||
* @param uri remote json file
|
||||
* @param options options
|
||||
*/
|
||||
public GeoJsonSource(String id, URI uri, GeoJsonOptions options) {
|
||||
super();
|
||||
initialize(id, options);
|
||||
nativeSetUrl(uri.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a GeoJsonSource from a FeatureCollection.
|
||||
*
|
||||
@@ -247,22 +277,46 @@ public class GeoJsonSource extends Source {
|
||||
* Updates the url
|
||||
*
|
||||
* @param url the GeoJSON FeatureCollection url
|
||||
* @deprecated use {@link #setUri(URI)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setUrl(@NonNull URL url) {
|
||||
checkThread();
|
||||
setUrl(url.toExternalForm());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the uri
|
||||
*
|
||||
* @param url the GeoJSON FeatureCollection uri
|
||||
*/
|
||||
public void setUri(@NonNull URI url) {
|
||||
checkThread();
|
||||
setUrl(url.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the url
|
||||
*
|
||||
* @param url the GeoJSON FeatureCollection url
|
||||
* @deprecated use {@link #setUri(String)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setUrl(String url) {
|
||||
checkThread();
|
||||
nativeSetUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the url
|
||||
*
|
||||
* @param uri the GeoJSON FeatureCollection uri
|
||||
*/
|
||||
public void setUri(String uri) {
|
||||
checkThread();
|
||||
nativeSetUrl(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The url or null
|
||||
*/
|
||||
|
||||
@@ -9,11 +9,11 @@ import android.support.annotation.Keep;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngQuad;
|
||||
import com.mapbox.mapboxsdk.utils.BitmapUtils;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
@@ -45,13 +45,28 @@ public class ImageSource extends Source {
|
||||
* @param id The source id
|
||||
* @param coordinates The Latitude and Longitude of the four corners of the image
|
||||
* @param url remote json file
|
||||
* @deprecated use {@link ImageSource#ImageSource(String, LatLngQuad, URI)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public ImageSource(String id, LatLngQuad coordinates, @NonNull URL url) {
|
||||
super();
|
||||
initialize(id, coordinates);
|
||||
setUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an ImageSource from coordinates and an image URL
|
||||
*
|
||||
* @param id The source id
|
||||
* @param coordinates The Latitude and Longitude of the four corners of the image
|
||||
* @param uri json file uri
|
||||
*/
|
||||
public ImageSource(String id, LatLngQuad coordinates, @NonNull URI uri) {
|
||||
super();
|
||||
initialize(id, coordinates);
|
||||
setUri(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an ImageSource from coordinates and a bitmap image
|
||||
*
|
||||
@@ -82,7 +97,9 @@ public class ImageSource extends Source {
|
||||
* Updates the source image url
|
||||
*
|
||||
* @param url An Image url
|
||||
* @deprecated use {@link #setUri(URI)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setUrl(@NonNull URL url) {
|
||||
setUrl(url.toExternalForm());
|
||||
}
|
||||
@@ -91,12 +108,33 @@ public class ImageSource extends Source {
|
||||
* Updates the source image url
|
||||
*
|
||||
* @param url An image url
|
||||
* @deprecated use {@link #setUri(String)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setUrl(String url) {
|
||||
checkThread();
|
||||
nativeSetUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the source image uri
|
||||
*
|
||||
* @param uri An Image url
|
||||
*/
|
||||
public void setUri(@NonNull URI uri) {
|
||||
setUrl(uri.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the source image uri
|
||||
*
|
||||
* @param uri An image uri
|
||||
*/
|
||||
public void setUri(String uri) {
|
||||
checkThread();
|
||||
nativeSetUrl(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the source image to a bitmap
|
||||
*
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
@@ -31,32 +32,44 @@ public class RasterDemSource extends Source {
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url the source url
|
||||
* @deprecated use {@link #RasterDemSource(String, URI)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public RasterDemSource(String id, URL url) {
|
||||
this(id, url.toExternalForm());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the raster dem source from an URL
|
||||
* Create the raster dem source from an URI
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url the source url
|
||||
* @param uri the source uri
|
||||
*/
|
||||
public RasterDemSource(String id, String url) {
|
||||
public RasterDemSource(String id, URI uri) {
|
||||
this(id, uri.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the raster dem source from an URI
|
||||
*
|
||||
* @param id the source id
|
||||
* @param uri the source uri
|
||||
*/
|
||||
public RasterDemSource(String id, String uri) {
|
||||
super();
|
||||
initialize(id, url, DEFAULT_TILE_SIZE);
|
||||
initialize(id, uri, DEFAULT_TILE_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the raster source from an URL with a specific tile size
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url the source url
|
||||
* @param uri the source url
|
||||
* @param tileSize the tile size
|
||||
*/
|
||||
public RasterDemSource(String id, String url, int tileSize) {
|
||||
public RasterDemSource(String id, String uri, int tileSize) {
|
||||
super();
|
||||
initialize(id, url, tileSize);
|
||||
initialize(id, uri, tileSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,13 +97,24 @@ public class RasterDemSource extends Source {
|
||||
|
||||
/**
|
||||
* @return The url or null
|
||||
* @deprecated use {@link #getUri()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public String getUrl() {
|
||||
checkThread();
|
||||
return nativeGetUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The uri or null
|
||||
*/
|
||||
@Nullable
|
||||
public String getUri() {
|
||||
checkThread();
|
||||
return nativeGetUrl();
|
||||
}
|
||||
|
||||
@Keep
|
||||
protected native void initialize(String layerId, Object payload, int tileSize);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.support.annotation.Keep;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
@@ -29,33 +30,43 @@ public class RasterSource extends Source {
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url the source url
|
||||
* @deprecated use {@link #RasterSource(String, URI)} instead
|
||||
*/
|
||||
public RasterSource(String id, URL url) {
|
||||
this(id, url.toExternalForm());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the raster source from an URL
|
||||
* Create the raster source from an URI
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url the source url
|
||||
* @param uri the source uri
|
||||
*/
|
||||
public RasterSource(String id, String url) {
|
||||
public RasterSource(String id, URI uri) {
|
||||
this(id, uri.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the raster source from an URI
|
||||
*
|
||||
* @param id the source id
|
||||
* @param uri the source uri
|
||||
*/
|
||||
public RasterSource(String id, String uri) {
|
||||
super();
|
||||
initialize(id, url, DEFAULT_TILE_SIZE);
|
||||
initialize(id, uri, DEFAULT_TILE_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the raster source from an URL with a specific tile size
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url the source url
|
||||
* @param uri the source url
|
||||
* @param tileSize the tile size
|
||||
*/
|
||||
public RasterSource(String id, String url, int tileSize) {
|
||||
public RasterSource(String id, String uri, int tileSize) {
|
||||
super();
|
||||
initialize(id, url, tileSize);
|
||||
initialize(id, uri, tileSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mapbox.mapboxsdk.style.sources;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Keep;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -37,20 +38,32 @@ public class VectorSource extends Source {
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url the TileJSON resource url
|
||||
* @deprecated use {@link #VectorSource(String, Uri)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public VectorSource(String id, URL url) {
|
||||
this(id, url.toExternalForm());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a vector source from a remote url
|
||||
* Create a vector source from a uri pointing to a TileJSON resource
|
||||
*
|
||||
* @param id the source id
|
||||
* @param url the url
|
||||
* @param uri the TileJSON resource url
|
||||
*/
|
||||
public VectorSource(String id, String url) {
|
||||
public VectorSource(String id, Uri uri) {
|
||||
this(id, uri.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a vector source from a uri
|
||||
*
|
||||
* @param id the source id
|
||||
* @param uri the uri
|
||||
*/
|
||||
public VectorSource(String id, String uri) {
|
||||
super();
|
||||
initialize(id, url);
|
||||
initialize(id, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,13 +96,24 @@ public class VectorSource extends Source {
|
||||
|
||||
/**
|
||||
* @return The url or null
|
||||
* @deprecated use {@link #getUri()} instead
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public String getUrl() {
|
||||
checkThread();
|
||||
return nativeGetUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The uri or null
|
||||
*/
|
||||
@Nullable
|
||||
public String getUri() {
|
||||
checkThread();
|
||||
return nativeGetUrl();
|
||||
}
|
||||
|
||||
@Keep
|
||||
protected native void initialize(String layerId, Object payload);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user