diff options
author | Tobrun <tobrun@mapbox.com> | 2018-05-23 10:52:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-23 10:52:22 +0200 |
commit | 671fe37b1e6cde56c3edec76ce62542e4c8e57b7 (patch) | |
tree | 28d30fe67943a8ca258b4a57ebd435b947afdf82 /platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp | |
parent | acd8bb3ef8df8611e4507225358b0a9ab7dc48a5 (diff) | |
download | qtlocation-mapboxgl-671fe37b1e6cde56c3edec76ce62542e4c8e57b7.tar.gz |
Style JSON configuration on map snapshotter (#11976)
* [core, android, darwin] - add style JSON configuration on MapSnapshotter
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterLocalStyleActivity.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterLocalStyleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterLocalStyleActivity.java new file mode 100644 index 0000000000..32c340b2ce --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterLocalStyleActivity.java @@ -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()); + } +} |