Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VTM Style: allow adding dropDistance directly (related to #1082) #1085

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
package org.oscim.android.test;

import android.os.Bundle;

import org.oscim.backend.canvas.Color;
import org.oscim.backend.canvas.Paint;
import org.oscim.core.GeoPoint;
import org.oscim.layers.vector.VectorLayer;
import org.oscim.layers.vector.geometries.LineDrawable;
import org.oscim.layers.vector.geometries.PointDrawable;
import org.oscim.layers.vector.geometries.Style;
import org.oscim.utils.ColorUtil;

import java.util.Arrays;
import java.util.List;

public class VectorLayerActivity extends BitmapTileActivity {

@Override
Expand Down Expand Up @@ -67,6 +72,15 @@ public void onCreate(Bundle savedInstanceState) {
// }
// }

addRandomCircles(vectorLayer);
addThickSemitransparentPolyline(vectorLayer);

vectorLayer.update();

mMap.layers().add(vectorLayer);
}

private void addRandomCircles(VectorLayer vectorLayer) {
Style.Builder sb = Style.builder()
.buffer(0.5)
.fillColor(Color.RED)
Expand All @@ -84,9 +98,26 @@ public void onCreate(Bundle savedInstanceState) {
style));

}
vectorLayer.update();
}

mMap.layers().add(vectorLayer);
private void addThickSemitransparentPolyline(VectorLayer vectorLayer) {
final Style style = Style.builder()
.strokeWidth(20f)
.strokeColor(Color.setA(Color.BLUE, 127))
.cap(Paint.Cap.BUTT)
.dropDistance(10f)
.fixed(true)
.build();

//create a polyline in Hamburg, Germany
final List<GeoPoint> points = Arrays.asList(
new GeoPoint(53.5334, 10.069833), new GeoPoint(53.5419, 10.09075), new GeoPoint(53.53745, 10.091017), new GeoPoint(53.54105, 10.0928), new GeoPoint(53.536721, 10.09416),
new GeoPoint(53.5406, 10.08365), new GeoPoint(53.5406, 11.0)
);

final LineDrawable line = new LineDrawable(points, style);

vectorLayer.add(line);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions vtm-jts/src/org/oscim/layers/vector/VectorLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected void drawPoint(Task t, int level, Geometry points, Style style) {
LineBucket ll = t.buckets.getLineBucket(level + 1);
if (ll.line == null) {
ll.line = new LineStyle(2, style.strokeColor, style.strokeWidth);
ll.setDropDistance(style.pointReduction ? LineBucket.MIN_DIST : 0);
ll.setDropDistance(style.dropDistance);
}

for (int i = 0; i < points.getNumGeometries(); i++) {
Expand Down Expand Up @@ -296,7 +296,7 @@ protected void drawLine(Task t, int level, Geometry line, Style style) {
.strokeWidth(style.strokeWidth)
.texture(style.texture)
.build();
ll.setDropDistance(style.pointReduction ? LineBucket.MIN_DIST : 0);
ll.setDropDistance(style.dropDistance);
if (ll instanceof LineTexBucket)
((LineTexBucket) ll).setTexRepeat(style.textureRepeat);
}
Expand Down Expand Up @@ -330,7 +330,7 @@ protected void drawPolygon(Task t, int level, Geometry polygon, Style style) {
LineBucket ll = t.buckets.getLineBucket(level + 1);
if (ll.line == null) {
ll.line = new LineStyle(2, style.strokeColor, style.strokeWidth);
ll.setDropDistance(style.pointReduction ? LineBucket.MIN_DIST : 0);
ll.setDropDistance(style.dropDistance);
}

if (style.generalization != Style.GENERALIZATION_NONE) {
Expand Down
11 changes: 6 additions & 5 deletions vtm-jts/src/org/oscim/layers/vector/geometries/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.oscim.backend.canvas.Color;
import org.oscim.backend.canvas.Paint;
import org.oscim.renderer.bucket.LineBucket;
import org.oscim.renderer.bucket.TextureItem;

import static org.oscim.backend.canvas.Color.parseColor;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class Style {
public final int stippleColor;
public final float stippleWidth;
public final TextureItem texture;
public final boolean pointReduction;
public final float dropDistance;
public final boolean textureRepeat;

public final float heightOffset;
Expand All @@ -78,7 +79,7 @@ private Style(Builder builder) {
stippleColor = builder.stippleColor;
stippleWidth = builder.stippleWidth;
texture = builder.texture;
pointReduction = builder.pointReduction;
dropDistance = builder.dropDistance;
textureRepeat = builder.textureRepeat;

heightOffset = builder.heightOffset;
Expand Down Expand Up @@ -115,7 +116,7 @@ public static class Builder {
public int stippleColor = Color.GRAY;
public float stippleWidth = 1;
public TextureItem texture = null;
public boolean pointReduction = true;
public float dropDistance = LineBucket.MIN_DIST;
public boolean textureRepeat = true;

public float heightOffset = 0;
Expand Down Expand Up @@ -254,8 +255,8 @@ public Builder texture(TextureItem texture) {
return this;
}

public Builder pointReduction(boolean pointReduction) {
this.pointReduction = pointReduction;
public Builder dropDistance(float dropDistance) {
this.dropDistance = dropDistance;
return this;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity we should avoid changing multiple parameters in one setter.

As we add the dropDistance parameter that already exists in LineBucket,
we can remove the pointReduction and simplify the functions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitated to remove the "pointReduction" parameter because I feared that change would be breaking to existing users of the lib. Is this not an issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a common method and we will mention it in changelog.

Please see commit ee602a3, something like that should work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddiemuc you can update the pull request if you like.


Expand Down