diff --git a/docs/Changelog.md b/docs/Changelog.md index 433271d5..46ca2cd5 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -2,6 +2,7 @@ ## New since 0.10.0 +- PathLayer(s) scaled width [#594](https://github.com/mapsforge/vtm/issues/594) - vtm-models module [#580](https://github.com/mapsforge/vtm/issues/580) - Many other minor improvements and bug fixes - [Solved issues](https://github.com/mapsforge/vtm/issues?q=is%3Aclosed+milestone%3A0.11.0) diff --git a/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java b/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java index 6a304393..0ebbc89a 100644 --- a/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java +++ b/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java @@ -65,6 +65,8 @@ public class VectorLayer extends AbstractVectorLayer implements Gestur public static final Logger log = LoggerFactory.getLogger(VectorLayer.class); + private static final int STROKE_MIN_ZOOM = 12; + //private final SpatialIndex mDrawables = new RTree(); protected final SpatialIndex mDrawables = new QuadTree(1 << 30, 18); @@ -263,21 +265,25 @@ public class VectorLayer extends AbstractVectorLayer implements Gestur if (ll.line == null) { ll.line = LineStyle.builder() .reset() + .blur(style.blur) .cap(style.cap) .color(style.strokeColor) .fixed(style.fixed) - .blur(style.blur) .heightOffset(style.heightOffset) .level(0) .randomOffset(style.randomOffset) .stipple(style.stipple) .stippleColor(style.stippleColor) .stippleWidth(style.stippleWidth) + .strokeIncrease(style.strokeIncrease) .strokeWidth(style.strokeWidth) .texture(style.texture) .build(); } + if (!style.fixed && style.strokeIncrease > 1) + ll.scale = (float) Math.pow(style.strokeIncrease, Math.max(t.position.getZoom() - STROKE_MIN_ZOOM, 0)); + if (style.generalization != Style.GENERALIZATION_NONE) { line = DouglasPeuckerSimplifier.simplify(line, mMinX * style.generalization); } diff --git a/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java b/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java index 426bf62c..0609efe0 100644 --- a/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java +++ b/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java @@ -46,6 +46,7 @@ public class Style { public final Paint.Cap cap; public final boolean fixed; + public final double strokeIncrease; public final float blur; public final int stipple; public final int stippleColor; @@ -69,6 +70,7 @@ public class Style { cap = builder.cap; fixed = builder.fixed; + strokeIncrease = builder.strokeIncrease; blur = builder.blur; stipple = builder.stipple; stippleColor = builder.stippleColor; @@ -103,6 +105,7 @@ public class Style { public Paint.Cap cap = Paint.Cap.ROUND; public boolean fixed = false; + public double strokeIncrease = 1; public float blur = 0; public int stipple = 0; public int stippleColor = Color.GRAY; @@ -210,6 +213,11 @@ public class Style { return this; } + public Builder strokeIncrease(double strokeIncrease) { + this.strokeIncrease = strokeIncrease; + return this; + } + public Builder blur(float blur) { this.blur = blur; return this; diff --git a/vtm-playground/src/org/oscim/test/LineRenderTest.java b/vtm-playground/src/org/oscim/test/LineRenderTest.java index eff0915a..36e67560 100644 --- a/vtm-playground/src/org/oscim/test/LineRenderTest.java +++ b/vtm-playground/src/org/oscim/test/LineRenderTest.java @@ -1,6 +1,6 @@ /* * Copyright 2014 Hannes Janetzek - * Copyright 2016-2017 devemux86 + * Copyright 2016-2018 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -70,9 +70,9 @@ public class LineRenderTest extends GdxMapApp { line2 = new LineStyle(Color.GREEN, 1); line4 = new LineStyle(Color.LTGRAY, 3); } else { - line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); - line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); - line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); } TextureItem tex = null; @@ -93,8 +93,8 @@ public class LineRenderTest extends GdxMapApp { .randomOffset(true) .build(); - LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); - LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 0, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 1f, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 0, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); LineBucket ol = l.buckets.addLineBucket(0, outline); LineBucket ol2 = l.buckets.addLineBucket(5, outline2); diff --git a/vtm/src/org/oscim/layers/PathLayer.java b/vtm/src/org/oscim/layers/PathLayer.java index f07c0abc..b5ede4b6 100644 --- a/vtm/src/org/oscim/layers/PathLayer.java +++ b/vtm/src/org/oscim/layers/PathLayer.java @@ -1,7 +1,7 @@ /* * Copyright 2012 osmdroid authors: Viesturs Zarins, Martin Pearman * Copyright 2012 Hannes Janetzek - * Copyright 2016-2017 devemux86 + * Copyright 2016-2018 devemux86 * Copyright 2016 Bezzu * Copyright 2016 Pedinel * Copyright 2017 Andrey Novikov @@ -54,6 +54,8 @@ import java.util.List; */ public class PathLayer extends Layer implements GestureListener { + private static final int STROKE_MIN_ZOOM = 12; + /** * Stores points, converted to the map projection. */ @@ -338,7 +340,8 @@ public class PathLayer extends Layer implements GestureListener { ll.line = mLineStyle; - //ll.scale = ll.line.width; + if (!mLineStyle.fixed && mLineStyle.strokeIncrease > 1) + ll.scale = (float) Math.pow(mLineStyle.strokeIncrease, Math.max(task.position.getZoom() - STROKE_MIN_ZOOM, 0)); mMap.getMapPosition(task.position); diff --git a/vtm/src/org/oscim/theme/styles/LineStyle.java b/vtm/src/org/oscim/theme/styles/LineStyle.java index 438b2093..e741bdbf 100644 --- a/vtm/src/org/oscim/theme/styles/LineStyle.java +++ b/vtm/src/org/oscim/theme/styles/LineStyle.java @@ -1,7 +1,7 @@ /* * Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2013 Hannes Janetzek - * Copyright 2016-2017 devemux86 + * Copyright 2016-2018 devemux86 * Copyright 2017 Longri * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). @@ -37,6 +37,7 @@ public final class LineStyle extends RenderStyle { public final Cap cap; public final boolean outline; public final boolean fixed; + public final double strokeIncrease; public final int fadeScale; public final float blur; @@ -57,19 +58,19 @@ public final class LineStyle extends RenderStyle { public final float repeatGap; public LineStyle(int stroke, float width) { - this(0, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT); + this(0, "", stroke, width, Cap.BUTT, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT); } public LineStyle(int level, int stroke, float width) { - this(level, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT); + this(level, "", stroke, width, Cap.BUTT, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT); } public LineStyle(int stroke, float width, Cap cap) { - this(0, "", stroke, width, cap, true, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT); + this(0, "", stroke, width, cap, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT); } public LineStyle(int level, String style, int color, float width, - Cap cap, boolean fixed, + Cap cap, boolean fixed, double strokeIncrease, int stipple, int stippleColor, float stippleWidth, int fadeScale, float blur, boolean isOutline, TextureItem texture, boolean randomOffset, float[] dashArray, float repeatStart, float repeatGap) { @@ -82,6 +83,7 @@ public final class LineStyle extends RenderStyle { this.color = color; this.width = width; this.fixed = fixed; + this.strokeIncrease = strokeIncrease; this.stipple = stipple; this.stippleColor = stippleColor; @@ -112,6 +114,7 @@ public final class LineStyle extends RenderStyle { this.cap = b.cap; this.outline = b.outline; this.fixed = b.fixed; + this.strokeIncrease = b.strokeIncrease; this.fadeScale = b.fadeScale; this.blur = b.blur; this.stipple = b.stipple; @@ -146,6 +149,7 @@ public final class LineStyle extends RenderStyle { public Cap cap; public boolean outline; public boolean fixed; + public double strokeIncrease; public int fadeScale; public float blur; @@ -180,6 +184,7 @@ public final class LineStyle extends RenderStyle { this.cap = line.cap; this.outline = line.outline; this.fixed = line.fixed; + this.strokeIncrease = line.strokeIncrease; this.fadeScale = line.fadeScale; this.blur = line.blur; this.stipple = line.stipple; @@ -246,6 +251,11 @@ public final class LineStyle extends RenderStyle { return self(); } + public T strokeIncrease(double strokeIncrease) { + this.strokeIncrease = strokeIncrease; + return self(); + } + public T texture(TextureItem texture) { this.texture = texture; return self(); @@ -300,6 +310,7 @@ public final class LineStyle extends RenderStyle { outline = false; strokeWidth = 1; fixed = false; + strokeIncrease = 1; fadeScale = -1; blur = 0;