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

Add expression accessors #10790

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.annotation.Nullable;

import com.mapbox.mapboxsdk.exceptions.ConversionException;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.functions.Function;
import com.mapbox.mapboxsdk.utils.ColorUtils;

Expand Down Expand Up @@ -57,6 +58,31 @@ public boolean isValue() {
return !isNull() && !isFunction();
}

/**
* Returns if this is a expression.
*
* @return true if is a expression, false if not
*/
public boolean isExpression() {
return !isNull() && value instanceof Expression;
}

/**
* Get the expression of the property.
*
* @return the expression value
*/
@Nullable
public Expression<T> getExpression() {
if (isExpression()) {
// noinspection unchecked
return (Expression<T>) value;
} else {
Timber.e("not an expression, try value");
return null;
}
}

@Nullable
public Function<?, T> getFunction() {
if (isFunction()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ public void onDataLoaded(@NonNull FeatureCollection featureCollection) {
)
);

// debug log getters
SymbolLayer symbolLayer = mapboxMap.getLayerAs(LAYER_ID);
Timber.e("Property value for %s: %s","iconImage", symbolLayer.getIconImage().getExpression());
Timber.e("Property value for %s: %s","iconAllowOverlap", symbolLayer.getIconAllowOverlap().getValue());

new GenerateSymbolTask(mapboxMap, this).execute(featureCollection);
}

Expand Down
6 changes: 5 additions & 1 deletion platform/android/src/style/conversion/property_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class PropertyValueEvaluator {
}

jni::jobject* operator()(const mbgl::style::CompositeFunction<T> &value) const {
return *convert<jni::jobject*, mbgl::style::CompositeFunction<T>>(env, value);
return *convert<jni::jobject*, mbgl::style::CompositeFunction<T>>(env, value);
}

jni::jobject*operator()(const mbgl::style::expression::Expression &value) const {
return *convert<jni::jobject*, mbgl::style::expression::Expression>(env, value);
}

private:
Expand Down