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

Commit

Permalink
[android] #5610 - Runtime style api - part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Aug 2, 2016
1 parent ed821c0 commit 10b2cc6
Show file tree
Hide file tree
Showing 73 changed files with 6,974 additions and 297 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.location.LocationListener;
import com.mapbox.mapboxsdk.location.LocationServices;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
Expand Down Expand Up @@ -2604,34 +2603,6 @@ int getAttributionTintColor() {
return mMapboxMap.getUiSettings().getAttributionTintColor();
}

//
// Custom layer
//

@UiThread
void addCustomLayer(CustomLayer customLayer, String before) {
if (mDestroyed) {
return;
}
mNativeMapView.addCustomLayer(customLayer, before);
}

@UiThread
void removeCustomLayer(String id) {
if (mDestroyed) {
return;
}
mNativeMapView.removeCustomLayer(id);
}

@UiThread
void invalidateCustomLayers() {
if (mDestroyed) {
return;
}
mNativeMapView.update();
}

/**
* Sets a callback object which will be triggered when the {@link MapboxMap} instance is ready to be used.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
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.maps.widgets.MyLocationViewSettings;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
Expand All @@ -59,6 +58,7 @@
* </p>
*/
public class MapboxMap {
private static final String TAG = MapboxMap.class.getSimpleName();

private MapView mMapView;
private UiSettings mUiSettings;
Expand Down Expand Up @@ -114,6 +114,21 @@ public Layer getLayer(@NonNull String layerId) {
return getMapView().getNativeMapView().getLayer(layerId);
}

/**
* Tries to cast the Layer to T, returns null if it's another type
*/
@Nullable
@UiThread
public <T extends Layer> T getLayerAs(@NonNull String layerId) {
try {
//noinspection unchecked
return (T) getMapView().getNativeMapView().getLayer(layerId);
} catch (ClassCastException e) {
Log.e(TAG, String.format("Layer: %s is a different type: %s", layerId, e.getMessage()));
return null;
}
}

@UiThread
public void addLayer(@NonNull Layer layer) {
addLayer(layer, null);
Expand Down Expand Up @@ -1621,34 +1636,6 @@ OnMyBearingTrackingModeChangeListener getOnMyBearingTrackingModeChangeListener()
return mOnMyBearingTrackingModeChangeListener;
}

//
// Custom layer
//

/**
* Do not use this method, experimental feature.
*/
@UiThread
public void addCustomLayer(CustomLayer customLayer, String before) {
mMapView.addCustomLayer(customLayer, before);
}

/**
* Do not use this method, experimental feature.
*/
@UiThread
public void removeCustomLayer(String id) {
mMapView.removeCustomLayer(id);
}

/**
* Do not use this method, experimental feature.
*/
@UiThread
public void invalidateCustomLayers() {
mMapView.invalidateCustomLayers();
}

MapView getMapView() {
return mMapView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.offline.OfflineManager;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
Expand Down Expand Up @@ -463,14 +462,6 @@ public void flyTo(double angle, LatLng center, long duration, double pitch, doub
nativeFlyTo(mNativeMapViewPtr, angle, center.getLatitude(), center.getLongitude(), duration, pitch, zoom);
}

public void addCustomLayer(CustomLayer customLayer, String before) {
nativeAddCustomLayer(mNativeMapViewPtr, customLayer, before);
}

public void removeCustomLayer(String id) {
nativeRemoveCustomLayer(mNativeMapViewPtr, id);
}

public double[] getCameraValues() {
return nativeGetCameraValues(mNativeMapViewPtr);
}
Expand All @@ -483,6 +474,7 @@ public Layer getLayer(String layerId) {

public void addLayer(@NonNull Layer layer, @Nullable String before) {
nativeAddLayer(mNativeMapViewPtr, layer.getNativePtr(), before);
layer.invalidate();
}

public void removeLayer(@NonNull String layerId) throws NoSuchLayerException {
Expand Down Expand Up @@ -667,10 +659,6 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat

private native void nativeFlyTo(long nativeMapViewPtr, double angle, double latitude, double longitude, long duration, double pitch, double zoom);

private native void nativeAddCustomLayer(long nativeMapViewPtr, CustomLayer customLayer, String before);

private native void nativeRemoveCustomLayer(long nativeMapViewPtr, String id);

private native double[] nativeGetCameraValues(long mNativeMapViewPtr);

private native Layer nativeGetLayer(long nativeMapViewPtr, String layerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,31 @@ public BackgroundLayer(String layerId) {

protected native void initialize(String layerId);


// Property getters

@SuppressWarnings("unchecked")
public PropertyValue<String> getBackgroundColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetBackgroundColor());
}

@SuppressWarnings("unchecked")
public PropertyValue<String> getBackgroundPattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetBackgroundPattern());
}

@SuppressWarnings("unchecked")
public PropertyValue<Float> getBackgroundOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetBackgroundOpacity());
}

private native Object nativeGetBackgroundColor();

private native Object nativeGetBackgroundPattern();

private native Object nativeGetBackgroundOpacity();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,77 @@ public CircleLayer(String layerId, String sourceId) {
protected native void initialize(String layerId, String sourceId);

public void setSourceLayer(String sourceLayer) {
checkValidity();
nativeSetSourceLayer(sourceLayer);
}

public void setFilter(Filter.Statement filter) {
checkValidity();
this.setFilter(filter.toArray());
}

public void setFilter(Object[] filter) {
checkValidity();
nativeSetFilter(filter);
}


// Property getters

@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleRadius() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleRadius());
}

@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCircleColor());
}

@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleBlur());
}

@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleOpacity());
}

@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getCircleTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetCircleTranslate());
}

@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCircleTranslateAnchor());
}

@SuppressWarnings("unchecked")
public PropertyValue<String> getCirclePitchScale() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCirclePitchScale());
}

private native Object nativeGetCircleRadius();

private native Object nativeGetCircleColor();

private native Object nativeGetCircleBlur();

private native Object nativeGetCircleOpacity();

private native Object nativeGetCircleTranslate();

private native Object nativeGetCircleTranslateAnchor();

private native Object nativeGetCirclePitchScale();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mapbox.mapboxsdk.style.layers;

/**
* Custom layer.
* <p/>
* Experimental feature. Do not use.
*/
public class CustomLayer extends Layer {

public CustomLayer(String id,
long context,
long initializeFunction,
long renderFunction,
long deinitializeFunction) {
initialize(id, initializeFunction, renderFunction, deinitializeFunction, context);
}

public CustomLayer(long nativePtr) {
super(nativePtr);
}

public void invalidate() {
nativeUpdate();
}

protected native void initialize(String id, long initializeFunction, long renderFunction, long deinitializeFunction, long context);

protected native void nativeUpdate();

}
Loading

0 comments on commit 10b2cc6

Please sign in to comment.