1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package com.mapbox.mapboxsdk.style.functions;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops;
import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops;
import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops;
import com.mapbox.mapboxsdk.style.functions.stops.Stop;
import com.mapbox.mapboxsdk.style.functions.stops.Stops;
import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import java.util.Map;
/**
* Composite functions combine Camera and SourceFunctions.
* <p>
* Composite functions allow the appearance of a map feature to change with both its
* properties and zoom. Each stop is an array with two elements, the first is an object
* with a property input value and a zoom, and the second is a function output value. Note
* that support for property functions is not yet complete.
*
* @param <Z> the zoom type (usually Float)
* @param <I> the input type (the feature property type)
* @param <O> the output type (the property type)
* @see Function#composite
*/
public class CompositeFunction<Z extends Number, I, O> extends Function<Stop.CompositeValue<Z, I>, O> {
private final String property;
private PropertyValue<O> defaultValue;
CompositeFunction(@NonNull String property,
@NonNull CategoricalStops<Stop.CompositeValue<Z, I>, O> stops) {
this(null, property, stops);
}
CompositeFunction(@NonNull String property,
@NonNull ExponentialStops<Stop.CompositeValue<Z, I>, O> stops) {
this(null, property, stops);
}
CompositeFunction(@NonNull String property,
@NonNull IntervalStops<Stop.CompositeValue<Z, I>, O> stops) {
this(null, property, stops);
}
/**
* JNI Constructor
*/
private CompositeFunction(@Nullable O defaultValue, @NonNull String property,
@NonNull Stops<Stop.CompositeValue<Z, I>, O> stops) {
super(stops);
this.defaultValue = new PropertyValue<>(property, defaultValue);
this.property = property;
}
/**
* Set the default value
*
* @param defaultValue the default value to use when no other applies
* @return this (for chaining)
*/
public CompositeFunction<Z, I, O> withDefaultValue(PropertyValue<O> defaultValue) {
this.defaultValue = defaultValue;
return this;
}
/**
* @return the defaultValue
*/
@Nullable
public PropertyValue<O> getDefaultValue() {
return defaultValue;
}
/**
* INTERNAL USAGE ONLY
*
* @return the feature property name
*/
public String getProperty() {
return property;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, Object> toValueObject() {
Map<String, Object> valueObject = super.toValueObject();
valueObject.put(PROPERTY_KEY, property);
if (defaultValue != null) {
valueObject.put(DEFAULT_VALUE_KEY, defaultValue.value);
}
return valueObject;
}
}
|