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

Commit

Permalink
[android] test app - add example tor snapshot overlayed with marker
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Oct 9, 2017
1 parent ee6a523 commit 23b471e
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity android:name=".activity.snapshot.MapSnapshotterMarkerActivity"
android:description="@string/description_map_snapshotter_marker"
android:label="@string/activity_map_snapshotter_marker">
<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"
Expand Down
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();
}

}
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>
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<string name="description_bottom_sheet">Show 2 MapView on screen with a bottom sheet</string>
<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_camera_animator">Use Android SDK Animators to animate camera position changes</string>
<string name="description_symbol_generator">Use Android SDK Views as symbols</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<string name="activity_bottom_sheet">Bottom sheet</string>
<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_camera_animator">Animator animation</string>
<string name="activity_symbol_generator">SymbolGenerator</string>
</resources>

0 comments on commit 23b471e

Please sign in to comment.