Skip to content

Commit

Permalink
set color selections
Browse files Browse the repository at this point in the history
  • Loading branch information
EOVN committed Jun 26, 2023
1 parent 874f7e9 commit 05aff26
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,13 @@ protected void applyWayProperties(
public float getBikeSafetyValue(OSMWithTags way, WayProperties wayData, boolean forward) {
String bst = way.getTag(BIKESAFETY_TAG);

if (bst == null) return (float) (
forward
? wayData.getBicycleSafetyFeatures().forward()
: wayData.getBicycleSafetyFeatures().back()
);
if (bst == null) return 100;

try {
return (float) Double.parseDouble(bst);
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
return bestBikeSafety;
return 100;
}
}

Expand All @@ -339,6 +335,22 @@ public int getBikeSafetyOpacityValue(OSMWithTags way) {
}
}

private double limitBikeSafetyFactor(double factor) {
if (factor > 100.0) return 100.0;

if (factor <= 0) return bestBikeSafety;

return factor;
}

private int limitBikeSafetyFactorOpacity(int factor) {
if (factor > 255) return 255;

if (factor < 0) return 0;

return factor;
}

public void setBikeSafetyProperties(
StreetEdge street,
WayProperties wayData,
Expand All @@ -348,9 +360,9 @@ public void setBikeSafetyProperties(
double bicycleSafety = getBikeSafetyValue(way, wayData, forward);
int bicycleSafetyOpacity = getBikeSafetyOpacityValue(way);

if (bicycleSafety < bestBikeSafety) {
bestBikeSafety = (float) bicycleSafety;
}
bicycleSafety = limitBikeSafetyFactor(bicycleSafety);
bicycleSafetyOpacity = limitBikeSafetyFactorOpacity(bicycleSafetyOpacity);

street.setBicycleSafetyFactorOpacity(bicycleSafetyOpacity);
street.setBicycleSafetyFactor((float) bicycleSafety);
}
Expand Down Expand Up @@ -887,7 +899,7 @@ private void applySafetyFactors(Graph graph) {

if (!seenEdges.contains(e)) {
seenEdges.add(e);
pse.setBicycleSafetyFactor(pse.getBicycleSafetyFactor() / bestBikeSafety);
//pse.setBicycleSafetyFactor(pse.getBicycleSafetyFactor() / bestBikeSafety);
pse.setWalkSafetyFactor(pse.getWalkSafetyFactor() / bestWalkSafety);
}
}
Expand All @@ -899,7 +911,7 @@ private void applySafetyFactors(Graph graph) {

if (!seenEdges.contains(e)) {
seenEdges.add(e);
pse.setBicycleSafetyFactor(pse.getBicycleSafetyFactor() / bestBikeSafety);
//pse.setBicycleSafetyFactor(pse.getBicycleSafetyFactor() / bestBikeSafety);
pse.setWalkSafetyFactor(pse.getWalkSafetyFactor() / bestWalkSafety);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public class BikeSafetyEdgeRenderer implements EdgeVertexRenderer {

private static final Color VEHICLE_RENTAL_COLOR_VERTEX = new Color(0.0f, 0.7f, 0.0f);
private final ScalarColorPalette palette = new DefaultScalarColorPalette(1.0, 3.0, 10.0);
private final ScalarColorPalette customPalette = new DefaultScalarColorPalette(0.0, 100.0, 200.0);

public BikeSafetyEdgeRenderer() {
}

public Color getSafetyColor(double bikeSafety, int bikeSafetyOpacity) {
Color bsc = palette.getColor(bikeSafety);
int rgba = (bikeSafetyOpacity << 24) | (bsc.getRGB() & 0xFFFFFF);
return new Color(rgba, true);
int red = (int) (2.55 * bikeSafety);
return new Color(red, 255 - red, 0, bikeSafetyOpacity);
}

public String buildLabel(double bikeSafety, int bikeSafetyOpacity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ public void renderTile(TileRenderContext context) {
context.graphics.setColor(evAttrs.color);
context.graphics.draw(offsetShape);
}
if (evAttrs.label != null && lineWidth > 8.0f) {
context.graphics.setColor(Color.BLACK);
context.graphics.setStroke(
new TextStroke(
" " + evAttrs.label + " ",
font,
false,
true
)
);
context.graphics.draw(offsetShape);
}
}

// Render all vertices
Expand Down

0 comments on commit 05aff26

Please sign in to comment.