Skip to content

Commit

Permalink
VTM Style: allow adding dropDistance directly (related to #1082) (#1085)
Browse files Browse the repository at this point in the history
* VTM Style: allow adding dropDistance directly

* correct code review findings

* Formatting improvements

---------

Co-authored-by: eddiemuc <[email protected]>
Co-authored-by: Emux <[email protected]>
  • Loading branch information
3 people committed Dec 18, 2023
1 parent 9d68bdb commit 31646b3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
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;
}

Expand Down

0 comments on commit 31646b3

Please sign in to comment.