Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Implement addSource functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin committed Mar 16, 2020
1 parent 2362f62 commit dddb17e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ protected void onDidFinishLoadingStyle() {
return;
}
for (Source source : builder.getSources()) {
// nativeAddSource(source, source.getNativePtr());
nativeAddSource(source, source.getNativePtr());
}

for (Style.Builder.LayerWrapper layerWrapper : builder.getLayers()) {
Expand Down Expand Up @@ -722,12 +722,12 @@ protected native void nativeInitialize(MapSnapshotter mapSnapshotter,
@Keep
private native void nativeAddLayerAt(long layerPtr, int index);

// @NonNull
// @NonNull
// @Keep
// private native Source nativeGetSource(String sourceId);
//
// @Keep
// private native void nativeAddSource(Source source, long sourcePtr);
@Keep
private native void nativeAddSource(Source source, long sourcePtr);

// @Keep
// private native void nativeAddImages(Image[] images);
Expand Down
2 changes: 2 additions & 0 deletions MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
<activity
android:name=".activity.snapshot.MapSnapshotterActivity"
android:description="@string/description_map_snapshotter"
android:exported="true"
android:label="@string/activity_map_snapshotter">
<meta-data
android:name="@string/category"
Expand Down Expand Up @@ -376,6 +377,7 @@
<activity
android:name=".activity.snapshot.MapSnapshotterLocalStyleActivity"
android:description="@string/description_map_snapshotter_local_style"
android:exported="true"
android:label="@string/activity_map_snapshotter_local_style">
<meta-data
android:name="@string/category"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
import com.mapbox.mapboxsdk.style.layers.BackgroundLayer;
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
import com.mapbox.mapboxsdk.style.sources.RasterSource;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.mapboxsdk.testapp.R;

import java.util.ArrayList;
Expand Down Expand Up @@ -99,6 +102,7 @@ private void startSnapShot(final int row, final int column) {
// Optionally the style
Style.Builder builder = new Style.Builder()
.fromUri((column + row) % 2 == 0 ? Style.MAPBOX_STREETS : Style.DARK);

// Define the dimensions
MapSnapshotter.Options options = new MapSnapshotter.Options(
grid.getMeasuredWidth() / grid.getColumnCount(),
Expand All @@ -125,15 +129,20 @@ private void startSnapShot(final int row, final int column) {
: new LatLng(randomInRange(-80, 80), randomInRange(-160, 160)))
.bearing(randomInRange(0, 360))
.tilt(randomInRange(0, 60))
.zoom(randomInRange(0, 20))
.zoom(randomInRange(0, 10))
.padding(1, 1, 1, 1)
.build()
);
}

if (row == 0 && column == 0) {
// Add a source
Source source = new RasterSource("my-raster-source", "mapbox://mapbox.satellite", 512);
builder.withLayerAbove(new RasterLayer("satellite-layer", "my-raster-source"), "country-label");
builder.withSource(source);
}
BackgroundLayer bg = new BackgroundLayer("green_tint");
bg.setProperties(backgroundColor(Color.valueOf(randomInRange(0.0f, 1.0f), randomInRange(0.0f, 1.0f), randomInRange(0.0f, 1.0f), 0.2f).toArgb()));
builder.withLayerAbove(bg,"country-label");
builder.withLayerAbove(bg, "country-label");
options.withStyleBuilder(builder);
MapSnapshotter snapshotter = new MapSnapshotter(MapSnapshotterActivity.this, options, new SnapshotterObserver(this, row, column));
snapshotters.add(snapshotter);
Expand Down

0 comments on commit dddb17e

Please sign in to comment.