[android] Custom layer bindings

This commit is contained in:
John Firebaugh
2015-12-11 16:04:40 -08:00
parent e304033552
commit 8a17d30c50
12 changed files with 272 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
package com.mapbox.mapboxsdk.layers;
public class CustomLayer {
public CustomLayer(String id,
long context,
long initializeFunction,
long renderFunction,
long deinitializeFunction) {
this.mID = id;
this.mContext = context;
this.mInitializeFunction = initializeFunction;
this.mRenderFunction = renderFunction;
this.mDeinitializeFunction = deinitializeFunction;
}
public String mID;
public long mContext;
public long mInitializeFunction;
public long mRenderFunction;
public long mDeinitializeFunction;
}

View File

@@ -0,0 +1,4 @@
/**
* This package contains classes to add and manage layers in your map.
*/
package com.mapbox.mapboxsdk.layers;

View File

@@ -74,6 +74,7 @@ import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import java.lang.annotation.Retention;
@@ -3782,6 +3783,11 @@ public final class MapView extends FrameLayout {
mAttributionsView.setVisibility(visibility);
}
@UiThread
public void addCustomLayer(CustomLayer customLayer, String before) {
mNativeMapView.addCustomLayer(customLayer, before);
}
private void setWidgetGravity(@NonNull final View view, int gravity) {
LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
layoutParams.gravity = gravity;

View File

@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import java.lang.ref.WeakReference;
import java.util.List;
@@ -449,6 +450,10 @@ final class NativeMapView {
return nativeGetTopOffsetPixelsForAnnotationSymbol(mNativeMapViewPtr, symbolName);
}
public void addCustomLayer(CustomLayer customLayer, String before) {
nativeAddCustomLayer(mNativeMapViewPtr, customLayer, before);
}
//
// Callbacks
//
@@ -629,4 +634,6 @@ final class NativeMapView {
private native LatLng nativeLatLngForPixel(long nativeMapViewPtr, PointF pixel);
private native double nativeGetTopOffsetPixelsForAnnotationSymbol(long nativeMapViewPtr, String symbolName);
private native void nativeAddCustomLayer(long nativeMapViewPtr, CustomLayer customLayer, String before);
}

View File

@@ -0,0 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
public class ExampleCustomLayer {
static {
System.loadLibrary("example-custom-layer");
}
public native static long createContext();
public static long InitializeFunction;
public static long RenderFunction;
public static long DeinitializeFunction;
}

View File

@@ -34,6 +34,7 @@ import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
@@ -395,6 +396,10 @@ public class MainActivity extends AppCompatActivity {
startActivity(new Intent(getApplicationContext(), PolylineActivity.class));
return true;
case R.id.action_custom_layer:
addCustomLayer();
return true;
default:
return changeMapStyle(menuItem.getItemId());
}
@@ -570,6 +575,16 @@ public class MainActivity extends AppCompatActivity {
mMapView.removeAllAnnotations();
}
private void addCustomLayer() {
mMapView.addCustomLayer(
new CustomLayer("custom",
ExampleCustomLayer.createContext(),
ExampleCustomLayer.InitializeFunction,
ExampleCustomLayer.RenderFunction,
ExampleCustomLayer.DeinitializeFunction),
null);
}
// Called when FPS changes
private class MyOnFpsChangedListener implements MapView.OnFpsChangedListener {

View File

@@ -138,6 +138,12 @@
android:icon="@drawable/ic_trending_up_24dp"
android:title="@string/activity_polyline" />
<item
android:id="@+id/action_custom_layer"
android:checkable="false"
android:icon="@drawable/ic_trending_up_24dp"
android:title="@string/activity_custom_layer" />
</menu>
</item>

View File

@@ -16,6 +16,7 @@
<string name="activity_user_tracking_mode">User tracking mode</string>
<string name="activity_polyline">Polyline Activity</string>
<string name="activity_animate_coordinate_change">Animate Coordinate Change</string>
<string name="activity_custom_layer">Custom Layer</string>
<string name="navdrawer_menu_title_mainactivity_controls">Main Activity Controls</string>
<string name="navdrawer_menu_title_mainactivity_styles">Main Activity Styles</string>