diff --git a/vtm/src/org/oscim/renderer/elements/LineLayer.java b/vtm/src/org/oscim/renderer/elements/LineLayer.java index 197944f1..3671cd5b 100644 --- a/vtm/src/org/oscim/renderer/elements/LineLayer.java +++ b/vtm/src/org/oscim/renderer/elements/LineLayer.java @@ -758,9 +758,9 @@ public final class LineLayer extends RenderElement { MercatorProjection.groundResolution(v.pos)); } - if (line.fade < v.pos.zoomLevel) { + if (line.fadeScale < v.pos.zoomLevel) { GLUtils.setColor(uLineColor, line.color, 1); - } else if (line.fade > v.pos.zoomLevel) { + } else if (line.fadeScale > v.pos.zoomLevel) { continue; } else { float alpha = (float) (scale > 1.2 ? scale : 1.2) - 1; diff --git a/vtm/src/org/oscim/theme/XmlThemeBuilder.java b/vtm/src/org/oscim/theme/XmlThemeBuilder.java index 7a496197..4bedbc00 100644 --- a/vtm/src/org/oscim/theme/XmlThemeBuilder.java +++ b/vtm/src/org/oscim/theme/XmlThemeBuilder.java @@ -17,6 +17,10 @@ */ package org.oscim.theme; +import static java.lang.Boolean.parseBoolean; +import static java.lang.Float.parseFloat; +import static java.lang.Integer.parseInt; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -42,6 +46,7 @@ import org.oscim.theme.styles.Area.AreaBuilder; import org.oscim.theme.styles.Circle; import org.oscim.theme.styles.Extrusion; import org.oscim.theme.styles.Line; +import org.oscim.theme.styles.Line.LineBuilder; import org.oscim.theme.styles.LineSymbol; import org.oscim.theme.styles.RenderStyle; import org.oscim.theme.styles.Symbol; @@ -129,6 +134,7 @@ public class XmlThemeBuilder extends DefaultHandler { private final TextBuilder mTextBuilder = new TextBuilder(); private final AreaBuilder mAreaBuilder = new AreaBuilder(); + private final LineBuilder mLineBuilder = new LineBuilder(); private RuleBuilder mCurrentRule; private TextureAtlas mTextureAtlas; @@ -333,41 +339,16 @@ public class XmlThemeBuilder extends DefaultHandler { */ private Line createLine(Line line, String elementName, Attributes attributes, int level, boolean isOutline) { - - // Style name - String style = null; - float width = 0; - Cap cap = Cap.ROUND; - - // Extras - int fade = -1; - boolean fixed = false; - float blur = 0; - - // Stipple - int stipple = 0; - float stippleWidth = 1; - - int color = Color.TRANSPARENT; - int stippleColor = Color.BLACK; - - if (line != null) { - color = line.color; - fixed = line.fixed; - fade = line.fadeScale; - cap = line.cap; - blur = line.blur; - stipple = line.stipple; - stippleColor = line.stippleColor; - stippleWidth = line.stippleWidth; - } + LineBuilder b = mLineBuilder.set(line); + b.isOutline(isOutline); + b.level(level); for (int i = 0; i < attributes.getLength(); ++i) { String name = attributes.getLocalName(i); String value = attributes.getValue(i); if ("id".equals(name)) - style = value; + b.style = value; else if ("src".equals(name)) ;// src = value; @@ -379,34 +360,43 @@ public class XmlThemeBuilder extends DefaultHandler { ;// ignore else if ("stroke".equals(name)) - color = Color.parseColor(value); - - else if ("width".equals(name) || "stroke-width".equals(name)) - width = Float.parseFloat(value); + b.color(value); + else if ("width".equals(name) || "stroke-width".equals(name)) { + float width = parseFloat(value); + if (line == null) { + validateNonNegative("width", width); + } else { + /* use stroke width relative to 'line' */ + width += line.width; + if (width <= 0) + width = 1; + } + b.width = width; + } else if ("cap".equals(name) || "stroke-linecap".equals(name)) - cap = Cap.valueOf(value.toUpperCase()); + b.cap = Cap.valueOf(value.toUpperCase()); else if ("fix".equals(name)) - fixed = Boolean.parseBoolean(value); + b.fixed = parseBoolean(value); else if ("stipple".equals(name)) - stipple = Integer.parseInt(value); + b.stipple = parseInt(value); else if ("stipple-stroke".equals(name)) - stippleColor = Color.parseColor(value); + b.stippleColor(value); else if ("stipple-width".equals(name)) - stippleWidth = Float.parseFloat(value); + b.stippleWidth = parseFloat(value); else if ("fade".equals(name)) - fade = Integer.parseInt(value); + b.fadeScale = Integer.parseInt(value); else if ("min".equals(name)) ; //min = Float.parseFloat(value); else if ("blur".equals(name)) - blur = Float.parseFloat(value); + b.blur = parseFloat(value); else if ("style".equals(name)) ; // ignore @@ -417,21 +407,7 @@ public class XmlThemeBuilder extends DefaultHandler { else logUnknownAttribute(elementName, name, value, i); } - - // inherit properties from 'line' - if (line != null) { - // use stroke width relative to 'line' - width = line.width + width; - if (width <= 0) - width = 1; - - } else if (!isOutline) { - validateNonNegative("width", width); - } - - return new Line(level, style, color, width, cap, fixed, - stipple, stippleColor, stippleWidth, - fade, blur, isOutline); + return b.build(); } private void handleAreaElement(String localName, Attributes attributes, boolean isStyle) diff --git a/vtm/src/org/oscim/theme/styles/Line.java b/vtm/src/org/oscim/theme/styles/Line.java index e405b0dd..1a8ce392 100644 --- a/vtm/src/org/oscim/theme/styles/Line.java +++ b/vtm/src/org/oscim/theme/styles/Line.java @@ -17,76 +17,22 @@ */ package org.oscim.theme.styles; +import static org.oscim.backend.canvas.Color.parseColor; + import org.oscim.backend.canvas.Color; import org.oscim.backend.canvas.Paint.Cap; import org.oscim.theme.IRenderTheme.Callback; -/** - * Represents a polyline on the map. - */ public final class Line extends RenderStyle { - public final static class LineBuilder { - public int level; - - public String style; - public float width; - public int color; - public Cap cap; - public boolean outline; - public boolean fixed; - public int fade; - public float blur; - - public int stipple; - public int stippleColor; - public float stippleWidth; - - public LineBuilder set(Line line) { - this.level = line.level; - this.style = line.style; - this.width = line.width; - this.color = line.color; - this.cap = line.cap; - this.outline = line.outline; - this.fixed = line.fixed; - this.fade = line.fade; - this.blur = line.blur; - this.stipple = line.stipple; - this.stippleColor = line.stippleColor; - this.stippleWidth = line.stippleWidth; - return this; - } - - public LineBuilder setColor(int color) { - this.color = color; - return this; - } - - public LineBuilder setStippleColor(int color) { - this.stippleColor = color; - return this; - } - - public LineBuilder setColor(String color) { - this.color = Color.parseColor(color); - return this; - } - - public Line build() { - return new Line(this); - } - } - final int level; - public final String style; public final float width; public final int color; public final Cap cap; public final boolean outline; public final boolean fixed; - public final int fade; + public final int fadeScale; public final float blur; public final int stipple; @@ -101,7 +47,7 @@ public final class Line extends RenderStyle { this.cap = builer.cap; this.outline = builer.outline; this.fixed = builer.fixed; - this.fade = builer.fade; + this.fadeScale = builer.fadeScale; this.blur = builer.blur; this.stipple = builer.stipple; this.stippleColor = builer.stippleColor; @@ -111,27 +57,12 @@ public final class Line extends RenderStyle { public Line(int level, String style, int color, float width, Cap cap, boolean fixed, int stipple, int stippleColor, float stippleWidth, - int fade, float blur, boolean isOutline) { + int fadeScale, float blur, boolean isOutline) { this.level = level; this.style = style; this.outline = isOutline; - // paint = new Paint(Paint.ANTI_ALIAS_FLAG); - // - // if (src != null) { - // Shader shader = BitmapUtils.createBitmapShader(src); - // paint.setShader(shader); - // } - // - // paint.setStyle(Style.STROKE); - // paint.setColor(stroke); - // if (strokeDasharray != null) { - // paint.setPathEffect(new DashPathEffect(strokeDasharray, 0)); - // } - - //GlUtils.changeSaturation(color, 1.02f); - this.cap = cap; this.color = color; this.width = width; @@ -142,7 +73,7 @@ public final class Line extends RenderStyle { this.stippleWidth = stippleWidth; this.blur = blur; - this.fade = fade; + this.fadeScale = fadeScale; } public Line(int stroke, float width) { @@ -161,4 +92,111 @@ public final class Line extends RenderStyle { public void renderWay(Callback renderCallback) { renderCallback.renderWay(this, level); } + + public final static class LineBuilder { + public int level; + + public String style; + public float width; + public int color; + public Cap cap; + public boolean outline; + public boolean fixed; + public int fadeScale; + public float blur; + + public int stipple; + public int stippleColor; + public float stippleWidth; + + public LineBuilder set(Line line) { + if (line == null) + return reset(); + this.level = line.level; + this.style = line.style; + this.width = line.width; + this.color = line.color; + this.cap = line.cap; + this.outline = line.outline; + this.fixed = line.fixed; + this.fadeScale = line.fadeScale; + this.blur = line.blur; + this.stipple = line.stipple; + this.stippleColor = line.stippleColor; + this.stippleWidth = line.stippleWidth; + return this; + } + + public LineBuilder reset() { + level = -1; + style = null; + color = Color.BLACK; + cap = Cap.ROUND; + width = 1; + fixed = false; + + fadeScale = -1; + blur = 0; + + stipple = 0; + stippleWidth = 1; + stippleColor = Color.BLACK; + + return this; + } + + public LineBuilder style(String name) { + this.style = name; + return this; + } + + public LineBuilder level(int level) { + this.level = level; + return this; + } + + public LineBuilder color(int color) { + this.color = color; + return this; + } + + public LineBuilder width(float width) { + this.width = width; + return this; + } + + public LineBuilder blur(float blur) { + this.blur = blur; + return this; + } + + public LineBuilder fadeScale(int zoom) { + this.fadeScale = zoom; + return this; + } + + public LineBuilder stippleColor(int color) { + this.stippleColor = color; + return this; + } + + public LineBuilder color(String color) { + this.color = parseColor(color); + return this; + } + + public LineBuilder stippleColor(String color) { + this.stippleColor = parseColor(color); + return this; + } + + public LineBuilder isOutline(boolean outline) { + this.outline = outline; + return this; + } + + public Line build() { + return new Line(this); + } + } }