This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] test app - add example tor snapshot overlayed with marker
- Loading branch information
1 parent
ee6a523
commit 23b471e
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ain/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.mapbox.mapboxsdk.testapp.activity.snapshot; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.Canvas; | ||
import android.graphics.PointF; | ||
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.constants.Style; | ||
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 timber.log.Timber; | ||
|
||
/** | ||
* Test activity showing how to use a the {@link MapSnapshotter} and overlay | ||
* {@link android.graphics.Bitmap}s on top. | ||
*/ | ||
public class MapSnapshotterMarkerActivity extends AppCompatActivity implements MapSnapshotter.SnapshotReadyCallback { | ||
|
||
@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); | ||
|
||
Timber.i("Starting snapshot"); | ||
|
||
MapSnapshotter mapSnapshotter = new MapSnapshotter( | ||
getApplicationContext(), | ||
new MapSnapshotter | ||
.Options(Math.min(container.getMeasuredWidth(), 1024), Math.min(container.getMeasuredHeight(), 1024)) | ||
.withStyle(Style.TRAFFIC_DAY) | ||
.withCameraPosition(new CameraPosition.Builder().target(new LatLng(52.090737, 5.121420)).zoom(15).build()) | ||
); | ||
mapSnapshotter.start(MapSnapshotterMarkerActivity.this); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onSnapshotReady(MapSnapshot snapshot) { | ||
Timber.i("Snapshot ready"); | ||
ImageView imageView = (ImageView) findViewById(R.id.snapshot_image); | ||
Bitmap image = addMarker(snapshot); | ||
imageView.setImageBitmap(image); | ||
} | ||
|
||
private Bitmap addMarker(MapSnapshot snapshot) { | ||
Canvas canvas = new Canvas(snapshot.getBitmap()); | ||
Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default, null); | ||
// Dom toren | ||
PointF markerLocation = snapshot.pixelForLatLng(new LatLng(52.090649433011315, 5.121310651302338)); | ||
canvas.drawBitmap(marker, | ||
markerLocation.x, | ||
/* Subtract height (in dp) so the bottom of the marker aligns correctly */ | ||
markerLocation.y - (marker.getHeight() / getResources().getDisplayMetrics().density), | ||
null | ||
); | ||
return snapshot.getBitmap(); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_marker.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<ImageView | ||
android:id="@+id/snapshot_image" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
android:contentDescription=""/> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters