-
Notifications
You must be signed in to change notification settings - Fork 982
/
ColorMappingRanges.java
49 lines (42 loc) · 1.44 KB
/
ColorMappingRanges.java
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
package org.osmdroid.views.overlay.advancedpolyline;
import java.util.Map;
import java.util.SortedMap;
/**
* Color mapping to map ranges to specific colors.
*
* @author Matthias Dittmer
*/
public class ColorMappingRanges extends ColorMappingForScalar {
/**
* Using a sorted map to define borders of ranges.
* Borders are sorted from low to high.
*/
private final SortedMap<Float, Integer> mColorRanges;
private final boolean mStrictComparison;
public ColorMappingRanges(final SortedMap<Float, Integer> pColorArray, final boolean pStrictComparison) {
mColorRanges = pColorArray;
mStrictComparison = pStrictComparison;
}
@Override
protected int computeColor(final float pScalar) {
int lastArrayIndexFromLoop = 0;
// iterate over array and sort point in
for (Map.Entry<Float, Integer> entry : mColorRanges.entrySet()) {
if (mStrictComparison) {
if (pScalar < entry.getKey()) {
return entry.getValue();
}
} else {
if (pScalar <= entry.getKey()) {
return entry.getValue();
}
}
lastArrayIndexFromLoop++;
}
// assign last color if scalar is above highest border
if (lastArrayIndexFromLoop == mColorRanges.size()) {
return mColorRanges.get(mColorRanges.lastKey());
}
return 0;
}
}