PathLayer(s) scaled width, fix #594

This commit is contained in:
Emux 2018-09-21 13:03:25 +03:00
parent 596679d1f9
commit 34f4432818
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3
6 changed files with 43 additions and 14 deletions

View File

@ -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)

View File

@ -65,6 +65,8 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
public static final Logger log = LoggerFactory.getLogger(VectorLayer.class);
private static final int STROKE_MIN_ZOOM = 12;
//private final SpatialIndex<Drawable> mDrawables = new RTree<Drawable>();
protected final SpatialIndex<Drawable> mDrawables = new QuadTree<Drawable>(1 << 30, 18);
@ -263,21 +265,25 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> 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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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<LineStyle> {
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<LineStyle> {
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<LineStyle> {
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<LineStyle> {
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<LineStyle> {
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<LineStyle> {
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<LineStyle> {
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<LineStyle> {
outline = false;
strokeWidth = 1;
fixed = false;
strokeIncrease = 1;
fadeScale = -1;
blur = 0;