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

5610 android runtime styling api #5734

Merged
merged 1 commit into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ idocument:
ANDROID_ENV = platform/android/scripts/toolchain.sh
ANDROID_ABIS = arm-v5 arm-v7 arm-v8 x86 x86-64 mips

style-code-android:
node platform/android/scripts/generate-style-code.js

define ANDROID_RULES
build/android-$1/config.gypi: platform/android/scripts/configure.sh $(CONFIG_DEPENDENCIES)
$$(shell $(ANDROID_ENV) $1) ./configure $$< $$@ android $1
Expand All @@ -178,7 +181,7 @@ build/android-$1/Makefile: platform/android/platform.gyp build/android-$1/config
android-lib-$1: build/android-$1/Makefile
$$(shell $(ANDROID_ENV) $1) $(MAKE) -j$(JOBS) -C build/android-$1 all

android-$1: android-lib-$1
android-$1: android-lib-$1 style-code-android
cd platform/android && ./gradlew --parallel --max-workers=$(JOBS) assemble$(BUILDTYPE)

apackage: android-lib-$1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,10 @@ MyLocationView getUserLocationView() {
return mMyLocationView;
}

NativeMapView getNativeMapView() {
return mNativeMapView;
}

@UiThread
void snapshot(@NonNull final MapboxMap.SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) {
TextureView textureView = (TextureView) findViewById(R.id.textureView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
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;
import com.mapbox.mapboxsdk.style.sources.Source;

import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
Expand Down Expand Up @@ -103,6 +106,39 @@ public class MapboxMap {
mMarkerViewManager = new MarkerViewManager(this, mapView);
}

// Style

@Nullable
@UiThread
public Layer getLayer(@NonNull String layerId) {
return getMapView().getNativeMapView().getLayer(layerId);
}

@UiThread
public void addLayer(@NonNull Layer layer) {
addLayer(layer, null);
}

@UiThread
public void addLayer(@NonNull Layer layer, String before) {
getMapView().getNativeMapView().addLayer(layer, before);
}

@UiThread
public void removeLayer(@NonNull String layerId) throws NoSuchLayerException {
getMapView().getNativeMapView().removeLayer(layerId);
}

@UiThread
public void addSource(@NonNull Source source) {
getMapView().getNativeMapView().addSource(source);
}

@UiThread
public void removeSource(@NonNull String sourceId) {
getMapView().getNativeMapView().removeSource(sourceId);
}

//
// MinZoom
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Surface;

import com.mapbox.mapboxsdk.annotations.Icon;
Expand All @@ -16,6 +18,9 @@
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;
import com.mapbox.mapboxsdk.style.sources.Source;

import java.util.List;

Expand Down Expand Up @@ -470,6 +475,28 @@ public double[] getCameraValues() {
return nativeGetCameraValues(mNativeMapViewPtr);
}

// Runtime style Api

public Layer getLayer(String layerId) {
return nativeGetLayer(mNativeMapViewPtr, layerId);
}

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

public void removeLayer(@NonNull String layerId) throws NoSuchLayerException {
nativeRemoveLayer(mNativeMapViewPtr, layerId);
}

public void addSource(@NonNull Source source) {
nativeAddSource(mNativeMapViewPtr, source.getId(), source);
}

public void removeSource(@NonNull String sourceId) {
nativeRemoveSource(mNativeMapViewPtr, sourceId);
}

//
// Callbacks
//
Expand Down Expand Up @@ -633,7 +660,7 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat
private native LatLng nativeLatLngForPixel(long nativeMapViewPtr, float x, float y);

private native double nativeGetTopOffsetPixelsForAnnotationSymbol(long nativeMapViewPtr, String symbolName);

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

private native void nativeEaseTo(long nativeMapViewPtr, double angle, double latitude, double longitude, long duration, double pitch, double zoom, boolean easingInterpolator);
Expand All @@ -645,4 +672,14 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat
private native void nativeRemoveCustomLayer(long nativeMapViewPtr, String id);

private native double[] nativeGetCameraValues(long mNativeMapViewPtr);

private native Layer nativeGetLayer(long nativeMapViewPtr, String layerId);

private native void nativeAddLayer(long nativeMapViewPtr, long layerPtr, String before);

private native void nativeRemoveLayer(long nativeMapViewPtr, String layerId) throws NoSuchLayerException;

private native void nativeAddSource(long mNativeMapViewPtr, String id, Source source);

private native void nativeRemoveSource(long mNativeMapViewPtr, String sourceId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;

/**
* Background Layer
*/
public class BackgroundLayer extends Layer {

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

public BackgroundLayer(String layerId) {
initialize(layerId);
}

protected native void initialize(String layerId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;

/**
* Circle Layer
*/
public class CircleLayer extends Layer {

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

public CircleLayer(String layerId, String sourceId) {
initialize(layerId, sourceId);
}

protected native void initialize(String layerId, String sourceId);

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

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;

/**
* Fill Layer
*/
public class FillLayer extends Layer {

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

public FillLayer(String layerId, String sourceId) {
initialize(layerId, sourceId);
}

protected native void initialize(String layerId, String sourceId);

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

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

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

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

import java.util.ArrayList;
import java.util.Arrays;

/**
* Utility to build filter expressions more easily:
*
* @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#types-filter">Style spec</a>
*/
public class Filter {

public abstract static class Statement {
protected final String operator;

public Statement(String operator) {
this.operator = operator;
}

public abstract Object[] toArray();
}

public static class SimpleStatement extends Statement {
private final String key;
private final Object[] values;

public SimpleStatement(String operator, String key, Object... values) {
super(operator);
this.key = key;
this.values = values;
}


@Override
public Object[] toArray() {
ArrayList<Object> array = new ArrayList<>(2 + values.length);
array.add(operator);
array.add(key);
array.addAll(Arrays.asList(values));
return array.toArray();
}
}

public static class CompoundStatement extends Statement {
private final Statement[] statements;

public CompoundStatement(String operator, Statement... statements) {
super(operator);
this.statements = statements;
}

@Override
public Object[] toArray() {
ArrayList<Object> array = new ArrayList<>(1 + statements.length);
array.add(operator);
for (Statement statement : statements) {
array.add(statement.toArray());
}
return array.toArray();
}
}

public static Statement all(Statement... statements) {
return new CompoundStatement("all", statements);
}

public static Statement any(Statement... statements) {
return new CompoundStatement("any", statements);
}

public static Statement none(Statement... statements) {
return new CompoundStatement("none", statements);
}

public static Statement has(String key) {
return new SimpleStatement("has", key);
}

public static Statement notHas(String key) {
return new SimpleStatement("!has", key);
}

public static Statement eq(String key, Object value) {
return new SimpleStatement("==", key, value);
}

public static Statement neq(String key, Object value) {
return new SimpleStatement("!=", key, value);
}

public static Statement gt(String key, Object value) {
return new SimpleStatement(">", key, value);
}

public static Statement gte(String key, Object value) {
return new SimpleStatement(">=", key, value);
}

public static Statement lt(String key, Object value) {
return new SimpleStatement("<", key, value);
}

public static Statement lte(String key, Object value) {
return new SimpleStatement("<=", key, value);
}

public static Statement in(String key, Object... values) {
return new SimpleStatement("in", key, values);
}

public static Statement notIn(String key, Object... values) {
return new SimpleStatement("!in", key, values);
}

}
Loading