Skip to content

Commit

Permalink
VTM Style: allow adding dropDistance directly
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemuc committed Dec 17, 2023
1 parent 9d68bdb commit 7da1a2a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@

import android.os.Bundle;

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

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;
Expand Down Expand Up @@ -67,26 +73,52 @@ 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)
.fillAlpha(0.2f);
.buffer(0.5)
.fillColor(Color.RED)
.fillAlpha(0.2f);

for (int i = 0; i < 2000; i++) {
Style style = sb.buffer(Math.random() + 0.2)
.fillColor(ColorUtil.setHue(Color.RED,
(int) (Math.random() * 50) / 50.0))
.fillAlpha(0.5f)
.build();
.fillColor(ColorUtil.setHue(Color.RED,
(int) (Math.random() * 50) / 50.0))
.fillAlpha(0.5f)
.build();

vectorLayer.add(new PointDrawable(Math.random() * 180 - 90,
Math.random() * 360 - 180,
style));
Math.random() * 360 - 180,
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)
.pointReduction(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.pointReduction ? LineBucket.MIN_DIST : 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.pointReduction ? LineBucket.MIN_DIST : 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.pointReduction ? LineBucket.MIN_DIST : style.dropDistance);
}

if (style.generalization != Style.GENERALIZATION_NONE) {
Expand Down
9 changes: 9 additions & 0 deletions vtm-jts/src/org/oscim/layers/vector/geometries/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Style {
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 @@ -79,6 +80,7 @@ private Style(Builder builder) {
stippleWidth = builder.stippleWidth;
texture = builder.texture;
pointReduction = builder.pointReduction;
dropDistance = builder.dropDistance;
textureRepeat = builder.textureRepeat;

heightOffset = builder.heightOffset;
Expand Down Expand Up @@ -116,6 +118,7 @@ public static class Builder {
public float stippleWidth = 1;
public TextureItem texture = null;
public boolean pointReduction = true;
public float dropDistance = 0f;
public boolean textureRepeat = true;

public float heightOffset = 0;
Expand Down Expand Up @@ -259,6 +262,12 @@ public Builder pointReduction(boolean pointReduction) {
return this;
}

public Builder pointReduction(float dropDistance) {
this.pointReduction = false;
this.dropDistance = dropDistance;
return this;
}

public Builder textureRepeat(boolean textureRepeat) {
this.textureRepeat = textureRepeat;
return this;
Expand Down

0 comments on commit 7da1a2a

Please sign in to comment.