[android] Add ImageSource bindings
This commit is contained in:
@@ -535,6 +535,17 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.AnimatedImageSourceActivity"
|
||||
android:label="@string/activity_animated_image_source"
|
||||
android:description="@string/description_animated_image_source">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_style"/>
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
|
||||
<!-- Features -->
|
||||
<activity
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.style;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngQuad;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.ImageSource;
|
||||
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
* Test activity showing how to use a series of images to create an animation
|
||||
* with an ImageSource
|
||||
* <p>
|
||||
* GL-native equivalent of https://www.mapbox.com/mapbox-gl-js/example/animate-images/
|
||||
* </p>
|
||||
*/
|
||||
public class AnimatedImageSourceActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
private static final String ID_IMAGE_SOURCE = "animated_image_source";
|
||||
private static final String ID_IMAGE_LAYER = "animated_image_layer";
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
private Handler handler;
|
||||
private Runnable runnable;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_animated_image_source);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
// add source
|
||||
LatLngQuad quad = new LatLngQuad(
|
||||
new LatLng(46.437, -80.425),
|
||||
new LatLng(46.437, -71.516),
|
||||
new LatLng(37.936, -71.516),
|
||||
new LatLng(37.936, -80.425));
|
||||
mapboxMap.addSource(new ImageSource(ID_IMAGE_SOURCE, quad, R.drawable.southeast_radar_0));
|
||||
|
||||
// add layer
|
||||
RasterLayer layer = new RasterLayer(ID_IMAGE_LAYER, ID_IMAGE_SOURCE);
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshImageRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
handler.removeCallbacks(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private static class RefreshImageRunnable implements Runnable {
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
private Handler handler;
|
||||
private int[] drawables;
|
||||
private int drawableIndex;
|
||||
|
||||
RefreshImageRunnable(MapboxMap mapboxMap, Handler handler) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
this.handler = handler;
|
||||
drawables = new int[4];
|
||||
drawables[0] = R.drawable.southeast_radar_0;
|
||||
drawables[1] = R.drawable.southeast_radar_1;
|
||||
drawables[2] = R.drawable.southeast_radar_2;
|
||||
drawables[3] = R.drawable.southeast_radar_3;
|
||||
drawableIndex = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
((ImageSource) mapboxMap.getSource(ID_IMAGE_SOURCE)).setImage(drawables[drawableIndex++]);
|
||||
if (drawableIndex > 3) {
|
||||
drawableIndex = 0;
|
||||
}
|
||||
handler.postDelayed(this, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 168 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 173 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 175 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 173 KiB |
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_cameraTargetLat="46.437"
|
||||
app:mapbox_cameraTargetLng="-80.425"
|
||||
app:mapbox_cameraZoom="3"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fabStartStop"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginBottom="@dimen/fab_margin"
|
||||
android:layout_marginRight="@dimen/fab_margin"
|
||||
android:src="@android:drawable/ic_media_play"
|
||||
app:backgroundTint="@color/primary"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -59,6 +59,7 @@
|
||||
<string name="activity_restricted_bounds">Restrict camera to a bounds</string>
|
||||
<string name="activity_fill_extrusion_layer">Fill extrusions</string>
|
||||
<string name="activity_building_fill_extrusion_layer">Building layer</string>
|
||||
<string name="activity_animated_image_source">Animated Image Source</string>
|
||||
|
||||
<!--Description-->
|
||||
<string name="description_user_location_tracking">Tracks the location of the user</string>
|
||||
@@ -117,6 +118,7 @@
|
||||
<string name="description_restricted_bounds">Limit viewport to Iceland</string>
|
||||
<string name="description_fill_extrusion_layer">Shows how to add 3D extruded shapes</string>
|
||||
<string name="description_building_fill_extrusion_layer">Shows how to show 3D extruded buildings</string>
|
||||
<string name="description_animated_image_source">Shows how to animate georeferenced images</string>
|
||||
|
||||
<!--Categories-->
|
||||
<string name="category">category</string>
|
||||
|
||||
Reference in New Issue
Block a user