[android] - use URI instead of URL to enable asset loading
This commit is contained in:
@@ -7,38 +7,36 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.all;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.gte;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.gt;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.lt;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.gt;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.gte;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.has;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.lt;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.toNumber;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textIgnorePlacement;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAllowOverlap;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textIgnorePlacement;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize;
|
||||
|
||||
|
||||
/**
|
||||
@@ -87,8 +85,8 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
|
||||
private void addBusStopSource(Style style) {
|
||||
try {
|
||||
source = new GeoJsonSource(SOURCE_ID, new URL(URL_BUS_ROUTES));
|
||||
} catch (MalformedURLException exception) {
|
||||
source = new GeoJsonSource(SOURCE_ID, new URI(URL_BUS_ROUTES));
|
||||
} catch (URISyntaxException exception) {
|
||||
Timber.e(exception, "That's not an url... ");
|
||||
}
|
||||
style.addSource(source);
|
||||
@@ -140,14 +138,14 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
try {
|
||||
mapboxMap.getStyle().addSource(
|
||||
new GeoJsonSource(SOURCE_ID_CLUSTER,
|
||||
new URL(URL_BUS_ROUTES),
|
||||
new URI(URL_BUS_ROUTES),
|
||||
new GeoJsonOptions()
|
||||
.withCluster(true)
|
||||
.withClusterMaxZoom(14)
|
||||
.withClusterRadius(50)
|
||||
)
|
||||
);
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
} catch (URISyntaxException malformedUrlException) {
|
||||
Timber.e(malformedUrlException, "That's not an url... ");
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
|
||||
import com.mapbox.mapboxsdk.utils.BitmapUtils;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -98,7 +98,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_hearing_black_24dp))), true
|
||||
)
|
||||
);
|
||||
} catch (IOException exception) {
|
||||
} catch (URISyntaxException exception) {
|
||||
Timber.e(exception);
|
||||
}
|
||||
|
||||
@@ -133,10 +133,8 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private GeoJsonSource createClusterSource() throws IOException {
|
||||
String earthQuakes = GeoParseUtil.loadStringFromAssets(this, "earthquakes.geojson");
|
||||
FeatureCollection featureCollection = FeatureCollection.fromJson(earthQuakes);
|
||||
return new GeoJsonSource("earthquakes", featureCollection, new GeoJsonOptions()
|
||||
private GeoJsonSource createClusterSource() throws URISyntaxException {
|
||||
return new GeoJsonSource("earthquakes", new URI("asset://earthquakes.geojson"), new GeoJsonOptions()
|
||||
.withCluster(true)
|
||||
.withClusterMaxZoom(14)
|
||||
.withClusterRadius(50)
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.testapp.activity.style;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
@@ -10,12 +9,11 @@ import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.HeatmapLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.heatmapDensity;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
|
||||
@@ -66,14 +64,14 @@ public class HeatmapLayerActivity extends AppCompatActivity {
|
||||
.withLayerAbove(createHeatmapLayer(), "waterway-label")
|
||||
.withLayerBelow(createCircleLayer(), HEATMAP_LAYER_ID)
|
||||
);
|
||||
} catch (MalformedURLException exception) {
|
||||
} catch (URISyntaxException exception) {
|
||||
Timber.e(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private GeoJsonSource createEarthquakeSource() throws MalformedURLException {
|
||||
return new GeoJsonSource(EARTHQUAKE_SOURCE_ID, new URL(EARTHQUAKE_SOURCE_URL));
|
||||
private GeoJsonSource createEarthquakeSource() throws URISyntaxException {
|
||||
return new GeoJsonSource(EARTHQUAKE_SOURCE_ID, new URI(EARTHQUAKE_SOURCE_URL));
|
||||
}
|
||||
|
||||
private HeatmapLayer createHeatmapLayer() {
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
@@ -12,12 +11,11 @@ import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
|
||||
|
||||
/**
|
||||
@@ -54,12 +52,12 @@ public class RealTimeGeoJsonActivity extends AppCompatActivity implements OnMapR
|
||||
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
|
||||
@Override
|
||||
public void onStyleLoaded(Style style) {
|
||||
public void onStyleLoaded(@NonNull Style style) {
|
||||
// add source
|
||||
try {
|
||||
style.addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(malformedUrlException, "Invalid URL");
|
||||
style.addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URI(URL_GEOJSON_SOURCE)));
|
||||
} catch (URISyntaxException malformedUriException) {
|
||||
Timber.e(malformedUriException, "Invalid URL");
|
||||
}
|
||||
|
||||
// add layer
|
||||
|
||||
Reference in New Issue
Block a user