Style JSON configuration on map snapshotter (#11976)

* [core, android, darwin] - add style JSON configuration on MapSnapshotter
This commit is contained in:
Tobrun
2018-05-23 10:52:22 +02:00
committed by GitHub
parent acd8bb3ef8
commit 671fe37b1e
11 changed files with 120 additions and 12 deletions

View File

@@ -344,6 +344,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.snapshot.MapSnapshotterLocalStyleActivity"
android:description="@string/description_map_snapshotter_local_style"
android:label="@string/activity_map_snapshotter_local_style">
<meta-data
android:name="@string/category"
android:value="@string/category_imagegenerator" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.maplayout.DoubleMapActivity"
android:description="@string/description_doublemap"

View File

@@ -0,0 +1,71 @@
package com.mapbox.mapboxsdk.testapp.activity.snapshot;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.snapshotter.MapSnapshot;
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
import timber.log.Timber;
import java.io.IOException;
/**
* Test activity showing how to use a the MapSnapshotter with a local style
*/
public class MapSnapshotterLocalStyleActivity extends AppCompatActivity
implements MapSnapshotter.SnapshotReadyCallback {
private MapSnapshotter mapSnapshotter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_snapshotter_marker);
final View container = findViewById(R.id.container);
container.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//noinspection deprecation
container.getViewTreeObserver().removeGlobalOnLayoutListener(this);
String styleJson;
try {
styleJson = ResourceUtils.readRawResource(MapSnapshotterLocalStyleActivity.this, R.raw.sat_style);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
Timber.i("Starting snapshot");
mapSnapshotter = new MapSnapshotter(
getApplicationContext(),
new MapSnapshotter
.Options(Math.min(container.getMeasuredWidth(), 1024), Math.min(container.getMeasuredHeight(), 1024))
.withStyleJson(styleJson)
.withCameraPosition(new CameraPosition.Builder().target(new LatLng(52.090737, 5.121420)).zoom(18).build())
);
mapSnapshotter.start(MapSnapshotterLocalStyleActivity.this, error -> Timber.e(error));
}
});
}
@Override
protected void onStop() {
super.onStop();
mapSnapshotter.cancel();
}
@Override
public void onSnapshotReady(MapSnapshot snapshot) {
Timber.i("Snapshot ready");
ImageView imageView = (ImageView) findViewById(R.id.snapshot_image);
imageView.setImageBitmap(snapshot.getBitmap());
}
}

View File

@@ -57,6 +57,7 @@
<string name="description_map_snapshotter">Show a static bitmap taken with the MapSnapshotter</string>
<string name="description_map_snapshotter_reuse">Show how to reuse a MapSnapshotter instance</string>
<string name="description_map_snapshotter_marker">Show how to add a marker to a Snapshot</string>
<string name="description_map_snapshotter_local_style">Show how to load a local style with a Snapshot</string>
<string name="description_camera_animator">Use Android SDK Animators to animate camera position changes</string>
<string name="description_symbol_generator">Use Android SDK Views as symbols</string>
<string name="description_textureview_debug">Use TextureView to render the map</string>

View File

@@ -57,6 +57,7 @@
<string name="activity_map_snapshotter">Map Snapshotter</string>
<string name="activity_map_snapshotter_reuse">Map Snapshotter Reuse</string>
<string name="activity_map_snapshotter_marker">Map Snapshot with marker</string>
<string name="activity_map_snapshotter_local_style">Map Snapshot with local style</string>
<string name="activity_camera_animator">Animator animation</string>
<string name="activity_symbol_generator">SymbolGenerator</string>
<string name="activity_textureview_debug">TextureView debug</string>