Skip to content

Commit

Permalink
Render themes: line symbol, fix opensciencemap#124
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Sep 23, 2017
1 parent 7865867 commit 0046f5c
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 99 deletions.
23 changes: 3 additions & 20 deletions resources/rendertheme.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
<xs:attribute name="fade" default="-1" type="xs:integer" use="optional" />
<xs:attribute name="blur" default="-1" type="xs:float" use="optional" />
<xs:attribute name="fix" default="false" type="xs:boolean" use="optional" />
<xs:attribute name="repeat-gap" default="200" type="xs:float" use="optional" />
<xs:attribute name="repeat-start" default="30" type="xs:float" use="optional" />

<!-- stipple repeat in 'pixel' -->
<xs:attribute name="stipple" default="0" type="xs:integer" use="optional" />
Expand All @@ -200,25 +202,6 @@

</xs:complexType>

<!--<xs:complexType name="outline">
<xs:attribute name="cat" type="xs:string" use="optional" />
<xs:attribute name="name" default="0" type="xs:string" use="optional" />
<xs:attribute name="src" type="tns:src" use="optional" />
<xs:attribute name="symbol-width" type="xs:positiveInteger" use="optional" />
<xs:attribute name="symbol-height" type="xs:positiveInteger" use="optional" />
<xs:attribute name="symbol-percent" type="xs:positiveInteger" use="optional" />
<xs:attribute name="stroke" default="#000000" type="tns:color" use="optional" />
<xs:attribute name="stroke-width" default="0" type="tns:nonNegativeFloat" use="optional" />
</xs:complexType>-->

<xs:complexType name="lineSymbol">
<xs:attribute name="cat" type="xs:string" use="optional" />
<xs:attribute name="src" type="tns:src" use="required" />
<xs:attribute name="symbol-width" type="xs:positiveInteger" use="optional" />
<xs:attribute name="symbol-height" type="xs:positiveInteger" use="optional" />
<xs:attribute name="symbol-percent" type="xs:positiveInteger" use="optional" />
</xs:complexType>

<xs:complexType name="text">
<xs:attribute name="cat" type="xs:string" use="optional" />

Expand Down Expand Up @@ -266,7 +249,7 @@
<xs:element name="circle" type="tns:circle" />
<xs:element name="line" type="tns:line" />
<xs:element name="outline" type="tns:line" />
<xs:element name="lineSymbol" type="tns:lineSymbol" />
<xs:element name="lineSymbol" type="tns:line" />
<xs:element name="text" type="tns:text" />
<xs:element name="extrusion" type="tns:extrusion" />
<xs:element name="symbol" type="tns:symbol" />
Expand Down
13 changes: 7 additions & 6 deletions vtm-playground/src/org/oscim/test/LineRenderTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2016 devemux86
* Copyright 2014 Hannes Janetzek
* Copyright 2016-2017 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand Down Expand Up @@ -72,9 +73,9 @@ void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) {
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);
line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true, null);
line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null, true, null);
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);
}

TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/dot.png"));
Expand All @@ -90,8 +91,8 @@ void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) {
.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 outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 0, true, null, true, null);
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);

LineBucket ol = l.buckets.addLineBucket(0, outline);
LineBucket ol2 = l.buckets.addLineBucket(5, outline2);
Expand Down
7 changes: 0 additions & 7 deletions vtm-themes/resources/assets/patterns/oneway.svg

This file was deleted.

8 changes: 4 additions & 4 deletions vtm-themes/resources/assets/symbols/oneway.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions vtm-themes/resources/assets/vtm/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>
Expand Down
3 changes: 1 addition & 2 deletions vtm-themes/resources/assets/vtm/mapzen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,7 @@
<m k="area" v="~|false|no">
<m k="kind_detail">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>
Expand Down
3 changes: 1 addition & 2 deletions vtm-themes/resources/assets/vtm/newtron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>
Expand Down
3 changes: 1 addition & 2 deletions vtm-themes/resources/assets/vtm/openmaptiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>
Expand Down
3 changes: 1 addition & 2 deletions vtm-themes/resources/assets/vtm/osmagray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>
Expand Down
3 changes: 1 addition & 2 deletions vtm-themes/resources/assets/vtm/osmarender.xml
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>
Expand Down
3 changes: 1 addition & 2 deletions vtm-themes/resources/assets/vtm/tronrender.xml
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>
Expand Down
40 changes: 18 additions & 22 deletions vtm/src/org/oscim/theme/XmlMapsforgeThemeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ private enum Element {
private static final String OUTLINE_STYLE = "O";
private static final String AREA_STYLE = "A";

private static final float REPEAT_GAP_DEFAULT = 200f;
private static final float REPEAT_START_DEFAULT = 30f;

/**
* @param theme an input theme containing valid render theme XML data.
* @return a new RenderTheme which is created by parsing the XML data from the input theme.
Expand Down Expand Up @@ -571,6 +568,12 @@ else if ("symbol-percent".equals(name))
else if ("symbol-scaling".equals(name))
; // no-op

else if ("repeat-start".equals(name))
b.repeatStart = Float.parseFloat(value) * mScale;

else if ("repeat-gap".equals(name))
b.repeatGap = Float.parseFloat(value) * mScale;

else
logUnknownAttribute(elementName, name, value, i);
}
Expand Down Expand Up @@ -611,30 +614,23 @@ else if ("symbol-scaling".equals(name))
b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);

if (hasSymbol) {
// We have no way to set a repeat gap for the renderer,
// so we create a texture that already contains this repeat gap.
float repeatGap = REPEAT_GAP_DEFAULT * mScale;
float repeatStart = REPEAT_START_DEFAULT * mScale;
int width = (int) (b.texture.width + repeatGap);
// Line symbol
int width = (int) (b.texture.width + b.repeatGap);
int height = b.texture.height;
Bitmap bmp = CanvasAdapter.newBitmap(width, height, 0);
Bitmap bitmap = CanvasAdapter.newBitmap(width, height, 0);
Canvas canvas = CanvasAdapter.newCanvas();
canvas.setBitmap(bmp);
canvas.drawBitmap(b.texture.bitmap, repeatStart, 0);
b.texture = new TextureItem(bmp);

// We must set stipple values
// The multipliers are determined empirically to
// correspond to the representation at Mapsforge.
b.stipple = b.texture.width * 3;
b.strokeWidth *= 2 * mScale;

// Use texture color
canvas.setBitmap(bitmap);
canvas.drawBitmap(b.texture.bitmap, b.repeatStart, 0);
b.texture = new TextureItem(bitmap);
b.texture.mipmap = true;
b.fixed = true;
b.randomOffset = false;
b.stipple = width;
b.stippleWidth = 1;
b.strokeWidth = height * 0.5f;
b.stippleColor = Color.WHITE;
b.fillColor = Color.TRANSPARENT;
b.strokeColor = Color.TRANSPARENT;

b.fixed = false;
}
}

Expand Down
40 changes: 18 additions & 22 deletions vtm/src/org/oscim/theme/XmlThemeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ private enum Element {
private static final String OUTLINE_STYLE = "O";
private static final String AREA_STYLE = "A";

private static final float REPEAT_GAP_DEFAULT = 200f;
private static final float REPEAT_START_DEFAULT = 30f;

/**
* @param theme an input theme containing valid render theme XML data.
* @return a new RenderTheme which is created by parsing the XML data from the input theme.
Expand Down Expand Up @@ -569,6 +566,12 @@ else if ("symbol-percent".equals(name))
else if ("symbol-scaling".equals(name))
; // no-op

else if ("repeat-start".equals(name))
b.repeatStart = Float.parseFloat(value) * mScale;

else if ("repeat-gap".equals(name))
b.repeatGap = Float.parseFloat(value) * mScale;

else
logUnknownAttribute(elementName, name, value, i);
}
Expand Down Expand Up @@ -609,30 +612,23 @@ else if ("symbol-scaling".equals(name))
b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);

if (hasSymbol) {
// We have no way to set a repeat gap for the renderer,
// so we create a texture that already contains this repeat gap.
float repeatGap = REPEAT_GAP_DEFAULT * mScale;
float repeatStart = REPEAT_START_DEFAULT * mScale;
int width = (int) (b.texture.width + repeatGap);
// Line symbol
int width = (int) (b.texture.width + b.repeatGap);
int height = b.texture.height;
Bitmap bmp = CanvasAdapter.newBitmap(width, height, 0);
Bitmap bitmap = CanvasAdapter.newBitmap(width, height, 0);
Canvas canvas = CanvasAdapter.newCanvas();
canvas.setBitmap(bmp);
canvas.drawBitmap(b.texture.bitmap, repeatStart, 0);
b.texture = new TextureItem(bmp);

// We must set stipple values
// The multipliers are determined empirically to
// correspond to the representation at Mapsforge.
b.stipple = b.texture.width * 3;
b.strokeWidth *= 2 * mScale;

// Use texture color
canvas.setBitmap(bitmap);
canvas.drawBitmap(b.texture.bitmap, b.repeatStart, 0);
b.texture = new TextureItem(bitmap);
b.texture.mipmap = true;
b.fixed = true;
b.randomOffset = false;
b.stipple = width;
b.stippleWidth = 1;
b.strokeWidth = height * 0.5f;
b.stippleColor = Color.WHITE;
b.fillColor = Color.TRANSPARENT;
b.strokeColor = Color.TRANSPARENT;

b.fixed = false;
}
}

Expand Down
Loading

0 comments on commit 0046f5c

Please sign in to comment.