use AreaBuilder in XmlThemeBuilder:
- docs - better Area field naming
This commit is contained in:
parent
ff7c74bc70
commit
f80b4ee2b1
@ -194,10 +194,10 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
GLState.blend(true);
|
GLState.blend(true);
|
||||||
a.texture.bind();
|
a.texture.bind();
|
||||||
|
|
||||||
} else if (a.fade >= zoom) {
|
} else if (a.fadeScale >= zoom) {
|
||||||
float f = 1.0f;
|
float f = 1.0f;
|
||||||
/* fade in/out */
|
/* fade in/out */
|
||||||
if (a.fade >= zoom) {
|
if (a.fadeScale >= zoom) {
|
||||||
if (scale > FADE_START)
|
if (scale > FADE_START)
|
||||||
f = scale - 1;
|
f = scale - 1;
|
||||||
else
|
else
|
||||||
@ -207,11 +207,11 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
|
|
||||||
GLUtils.setColor(hPolygonColor[shader], a.color, f);
|
GLUtils.setColor(hPolygonColor[shader], a.color, f);
|
||||||
|
|
||||||
} else if (a.blend > 0 && a.blend <= zoom) {
|
} else if (a.blendScale > 0 && a.blendScale <= zoom) {
|
||||||
/* blend colors (not alpha) */
|
/* blend colors (not alpha) */
|
||||||
GLState.blend(false);
|
GLState.blend(false);
|
||||||
|
|
||||||
if (a.blend == zoom)
|
if (a.blendScale == zoom)
|
||||||
GLUtils.setColorBlend(hPolygonColor[shader],
|
GLUtils.setColorBlend(hPolygonColor[shader],
|
||||||
a.color, a.blendColor, scale - 1.0f);
|
a.color, a.blendColor, scale - 1.0f);
|
||||||
else
|
else
|
||||||
@ -301,7 +301,7 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
PolygonLayer pl = (PolygonLayer) l;
|
PolygonLayer pl = (PolygonLayer) l;
|
||||||
|
|
||||||
// fade out polygon layers (set in RenderTheme)
|
// fade out polygon layers (set in RenderTheme)
|
||||||
if (pl.area.fade > 0 && pl.area.fade > zoom)
|
if (pl.area.fadeScale > 0 && pl.area.fadeScale > zoom)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cur == start) {
|
if (cur == start) {
|
||||||
|
@ -38,6 +38,7 @@ import org.oscim.theme.IRenderTheme.ThemeException;
|
|||||||
import org.oscim.theme.rule.Rule;
|
import org.oscim.theme.rule.Rule;
|
||||||
import org.oscim.theme.rule.RuleBuilder;
|
import org.oscim.theme.rule.RuleBuilder;
|
||||||
import org.oscim.theme.styles.Area;
|
import org.oscim.theme.styles.Area;
|
||||||
|
import org.oscim.theme.styles.Area.AreaBuilder;
|
||||||
import org.oscim.theme.styles.Circle;
|
import org.oscim.theme.styles.Circle;
|
||||||
import org.oscim.theme.styles.Extrusion;
|
import org.oscim.theme.styles.Extrusion;
|
||||||
import org.oscim.theme.styles.Line;
|
import org.oscim.theme.styles.Line;
|
||||||
@ -127,6 +128,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
|||||||
new HashMap<String, RenderStyle>(10);
|
new HashMap<String, RenderStyle>(10);
|
||||||
|
|
||||||
private final TextBuilder mTextBuilder = new TextBuilder();
|
private final TextBuilder mTextBuilder = new TextBuilder();
|
||||||
|
private final AreaBuilder mAreaBuilder = new AreaBuilder();
|
||||||
|
|
||||||
private RuleBuilder mCurrentRule;
|
private RuleBuilder mCurrentRule;
|
||||||
private TextureAtlas mTextureAtlas;
|
private TextureAtlas mTextureAtlas;
|
||||||
@ -329,7 +331,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
|||||||
* is outline layer
|
* is outline layer
|
||||||
* @return a new Line with the given rendering attributes.
|
* @return a new Line with the given rendering attributes.
|
||||||
*/
|
*/
|
||||||
private static Line createLine(Line line, String elementName, Attributes attributes,
|
private Line createLine(Line line, String elementName, Attributes attributes,
|
||||||
int level, boolean isOutline) {
|
int level, boolean isOutline) {
|
||||||
|
|
||||||
// Style name
|
// Style name
|
||||||
@ -352,7 +354,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
|||||||
if (line != null) {
|
if (line != null) {
|
||||||
color = line.color;
|
color = line.color;
|
||||||
fixed = line.fixed;
|
fixed = line.fixed;
|
||||||
fade = line.fade;
|
fade = line.fadeScale;
|
||||||
cap = line.cap;
|
cap = line.cap;
|
||||||
blur = line.blur;
|
blur = line.blur;
|
||||||
stipple = line.stipple;
|
stipple = line.stipple;
|
||||||
@ -459,37 +461,18 @@ public class XmlThemeBuilder extends DefaultHandler {
|
|||||||
/**
|
/**
|
||||||
* @return a new Area with the given rendering attributes.
|
* @return a new Area with the given rendering attributes.
|
||||||
*/
|
*/
|
||||||
private static Area createArea(Area area, String elementName, Attributes attributes, int level) {
|
private Area createArea(Area area, String elementName, Attributes attributes, int level) {
|
||||||
|
AreaBuilder b = mAreaBuilder.set(area);
|
||||||
|
b.level(level);
|
||||||
|
|
||||||
String src = null;
|
String src = null;
|
||||||
int fill = Color.BLACK;
|
|
||||||
int stroke = Color.TRANSPARENT;
|
|
||||||
float strokeWidth = 1;
|
|
||||||
int fade = -1;
|
|
||||||
int blend = -1;
|
|
||||||
int blendFill = Color.TRANSPARENT;
|
|
||||||
String style = null;
|
|
||||||
|
|
||||||
TextureItem texture = null;
|
|
||||||
|
|
||||||
if (area != null) {
|
|
||||||
fill = area.color;
|
|
||||||
blend = area.blend;
|
|
||||||
blendFill = area.blendColor;
|
|
||||||
fade = area.fade;
|
|
||||||
// TODO texture = area.texture
|
|
||||||
|
|
||||||
if (area.outline != null) {
|
|
||||||
stroke = area.outline.color;
|
|
||||||
strokeWidth = area.outline.width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < attributes.getLength(); ++i) {
|
for (int i = 0; i < attributes.getLength(); ++i) {
|
||||||
String name = attributes.getLocalName(i);
|
String name = attributes.getLocalName(i);
|
||||||
String value = attributes.getValue(i);
|
String value = attributes.getValue(i);
|
||||||
|
|
||||||
if ("id".equals(name))
|
if ("id".equals(name))
|
||||||
style = value;
|
b.style = value;
|
||||||
|
|
||||||
else if ("use".equals(name))
|
else if ("use".equals(name))
|
||||||
;// ignore
|
;// ignore
|
||||||
@ -498,39 +481,39 @@ public class XmlThemeBuilder extends DefaultHandler {
|
|||||||
src = value;
|
src = value;
|
||||||
|
|
||||||
else if ("fill".equals(name))
|
else if ("fill".equals(name))
|
||||||
fill = Color.parseColor(value);
|
b.color(value);
|
||||||
|
|
||||||
else if ("stroke".equals(name))
|
else if ("stroke".equals(name))
|
||||||
stroke = Color.parseColor(value);
|
b.outlineColor(value);
|
||||||
|
|
||||||
else if ("stroke-width".equals(name))
|
else if ("stroke-width".equals(name)) {
|
||||||
strokeWidth = Float.parseFloat(value);
|
float strokeWidth = Float.parseFloat(value);
|
||||||
|
validateNonNegative("stroke-width", strokeWidth);
|
||||||
|
b.outlineWidth = strokeWidth;
|
||||||
|
|
||||||
else if ("fade".equals(name))
|
} else if ("fade".equals(name))
|
||||||
fade = Integer.parseInt(value);
|
b.fadeScale = Integer.parseInt(value);
|
||||||
|
|
||||||
else if ("blend".equals(name))
|
else if ("blend".equals(name))
|
||||||
blend = Integer.parseInt(value);
|
b.blendScale = Integer.parseInt(value);
|
||||||
|
|
||||||
else if ("blend-fill".equals(name))
|
else if ("blend-fill".equals(name))
|
||||||
blendFill = Color.parseColor(value);
|
b.blendColor(value);
|
||||||
|
|
||||||
else
|
else
|
||||||
logUnknownAttribute(elementName, name, value, i);
|
logUnknownAttribute(elementName, name, value, i);
|
||||||
}
|
}
|
||||||
validateNonNegative("stroke-width", strokeWidth);
|
|
||||||
|
|
||||||
if (src != null) {
|
if (src != null) {
|
||||||
try {
|
try {
|
||||||
Bitmap b = CanvasAdapter.g.loadBitmapAsset(src);
|
Bitmap bitmap = CanvasAdapter.g.loadBitmapAsset(src);
|
||||||
if (b != null)
|
if (bitmap != null)
|
||||||
texture = new TextureItem(b, true);
|
b.texture = new TextureItem(bitmap, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Area(style, fill, stroke, strokeWidth, fade, level, blend,
|
return b.build();
|
||||||
blendFill, texture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addOutline(String style) {
|
private void addOutline(String style) {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
@ -17,61 +16,37 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.theme.styles;
|
package org.oscim.theme.styles;
|
||||||
|
|
||||||
|
import static org.oscim.backend.canvas.Color.parseColor;
|
||||||
|
|
||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
import org.oscim.renderer.elements.TextureItem;
|
import org.oscim.renderer.elements.TextureItem;
|
||||||
import org.oscim.theme.IRenderTheme.Callback;
|
import org.oscim.theme.IRenderTheme.Callback;
|
||||||
|
|
||||||
/**
|
public class Area extends RenderStyle {
|
||||||
* Represents a closed polygon on the map.
|
|
||||||
*/
|
|
||||||
public final class Area extends RenderStyle {
|
|
||||||
|
|
||||||
public static class AreaBuilder {
|
/** Drawing order level */
|
||||||
public int level;
|
private final int level;
|
||||||
public String style;
|
|
||||||
public Line outline;
|
|
||||||
public int color;
|
|
||||||
public int fade;
|
|
||||||
public int blendColor;
|
|
||||||
public int blend;
|
|
||||||
public TextureItem texture;
|
|
||||||
|
|
||||||
public AreaBuilder set(Area area) {
|
/** Style name */
|
||||||
this.level = area.level;
|
public final String style;
|
||||||
this.style = area.style;
|
|
||||||
this.fade = area.fade;
|
|
||||||
this.blendColor = area.blendColor;
|
|
||||||
this.blend = area.blend;
|
|
||||||
this.color = area.color;
|
|
||||||
this.texture = area.texture;
|
|
||||||
this.outline = area.outline;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaBuilder setColor(int color) {
|
/** Fill color */
|
||||||
this.color = color;
|
public final int color;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaBuilder setColor(String color) {
|
/** Fade-out zoom-level */
|
||||||
this.color = Color.parseColor(color);
|
public final int fadeScale;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaBuilder setBlendColor(int color) {
|
/** Fade to blendColor zoom-level */
|
||||||
this.blendColor = color;
|
public final int blendColor;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaBuilder setBlendColor(String color) {
|
/** Blend fill color */
|
||||||
this.blendColor = Color.parseColor(color);
|
public final int blendScale;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Area build() {
|
/** Pattern texture */
|
||||||
return new Area(this);
|
public final TextureItem texture;
|
||||||
}
|
|
||||||
}
|
/** Outline */
|
||||||
|
public final Line outline;
|
||||||
|
|
||||||
public Area(int color) {
|
public Area(int color) {
|
||||||
this(0, color);
|
this(0, color);
|
||||||
@ -80,42 +55,44 @@ public final class Area extends RenderStyle {
|
|||||||
public Area(int level, int color) {
|
public Area(int level, int color) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.style = "";
|
this.style = "";
|
||||||
this.fade = -1;
|
this.fadeScale = -1;
|
||||||
this.blendColor = 0;
|
this.blendColor = 0;
|
||||||
this.blend = -1;
|
this.blendScale = -1;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.texture = null;
|
this.texture = null;
|
||||||
this.outline = null;
|
this.outline = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Area(String style, int color, int stroke, float strokeWidth,
|
public Area(AreaBuilder b) {
|
||||||
int fade, int level, int blend, int blendColor, TextureItem texture) {
|
this.level = b.level;
|
||||||
|
this.style = b.style;
|
||||||
|
this.fadeScale = b.fadeScale;
|
||||||
|
this.blendColor = b.blendColor;
|
||||||
|
this.blendScale = b.blendScale;
|
||||||
|
this.color = b.color;
|
||||||
|
this.texture = b.texture;
|
||||||
|
|
||||||
this.style = style;
|
if (b.outline != null &&
|
||||||
this.color = color;
|
b.outlineColor == b.outline.color &&
|
||||||
this.blendColor = blendColor;
|
b.outlineWidth == b.outline.width) {
|
||||||
this.blend = blend;
|
this.outline = b.outline;
|
||||||
this.fade = fade;
|
} else if (b.outlineColor != Color.TRANSPARENT) {
|
||||||
this.level = level;
|
this.outline = new Line(-1, b.outlineColor, b.outlineWidth);
|
||||||
this.texture = texture;
|
} else {
|
||||||
|
|
||||||
if (stroke == Color.TRANSPARENT) {
|
|
||||||
this.outline = null;
|
this.outline = null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.outline = new Line(level + 1, stroke, strokeWidth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Area(AreaBuilder areaBuilder) {
|
@Override
|
||||||
this.level = areaBuilder.level;
|
public void update() {
|
||||||
this.style = areaBuilder.style;
|
super.update();
|
||||||
this.fade = areaBuilder.fade;
|
|
||||||
this.blendColor = areaBuilder.blendColor;
|
if (outline != null)
|
||||||
this.blend = areaBuilder.blend;
|
outline.update();
|
||||||
this.color = areaBuilder.color;
|
}
|
||||||
this.texture = areaBuilder.texture;
|
|
||||||
this.outline = areaBuilder.outline;
|
public Area current() {
|
||||||
|
return (Area) (mCurrent == null ? this : mCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,19 +103,125 @@ public final class Area extends RenderStyle {
|
|||||||
renderCallback.renderWay(outline, level + 1);
|
renderCallback.renderWay(outline, level + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int level;
|
public static class AreaBuilder {
|
||||||
public final String style;
|
public int level;
|
||||||
public final Line outline;
|
public String style;
|
||||||
public final int color;
|
public Line outline;
|
||||||
public final int fade;
|
public int color;
|
||||||
public final int blendColor;
|
public int fadeScale;
|
||||||
public final int blend;
|
public int blendColor;
|
||||||
public final TextureItem texture;
|
public int blendScale;
|
||||||
|
|
||||||
public void update() {
|
public int outlineColor;
|
||||||
super.update();
|
public float outlineWidth;
|
||||||
|
|
||||||
if (outline != null)
|
public TextureItem texture;
|
||||||
outline.update();
|
|
||||||
|
public AreaBuilder set(Area area) {
|
||||||
|
if (area == null)
|
||||||
|
return reset();
|
||||||
|
|
||||||
|
this.level = area.level;
|
||||||
|
this.style = area.style;
|
||||||
|
this.fadeScale = area.fadeScale;
|
||||||
|
this.blendColor = area.blendColor;
|
||||||
|
this.blendScale = area.blendScale;
|
||||||
|
this.color = area.color;
|
||||||
|
this.texture = area.texture;
|
||||||
|
this.outline = area.outline;
|
||||||
|
if (area.outline != null) {
|
||||||
|
this.outlineColor = outline.color;
|
||||||
|
this.outlineWidth = outline.width;
|
||||||
|
} else {
|
||||||
|
outlineColor = Color.TRANSPARENT;
|
||||||
|
outlineWidth = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder style(String name) {
|
||||||
|
this.style = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder level(int level) {
|
||||||
|
this.level = level;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder outline(int color, float width) {
|
||||||
|
this.outlineColor = color;
|
||||||
|
this.outlineWidth = width;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder outlineColor(int color) {
|
||||||
|
this.outlineColor = color;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder outlineColor(String color) {
|
||||||
|
this.outlineColor = parseColor(color);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder outlineWidth(float width) {
|
||||||
|
this.outlineWidth = width;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder color(int color) {
|
||||||
|
this.color = color;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder color(String color) {
|
||||||
|
this.color = parseColor(color);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder blendScale(int zoom) {
|
||||||
|
this.blendScale = zoom;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder blendColor(int color) {
|
||||||
|
this.blendColor = color;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder blendColor(String color) {
|
||||||
|
this.blendColor = parseColor(color);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder texture(TextureItem texture) {
|
||||||
|
this.texture = texture;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder fadeScale(int zoom) {
|
||||||
|
this.fadeScale = zoom;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AreaBuilder reset() {
|
||||||
|
color = Color.BLACK;
|
||||||
|
|
||||||
|
outlineColor = Color.TRANSPARENT;
|
||||||
|
outlineWidth = 1;
|
||||||
|
|
||||||
|
fadeScale = -1;
|
||||||
|
blendScale = -1;
|
||||||
|
blendColor = Color.TRANSPARENT;
|
||||||
|
style = null;
|
||||||
|
texture = null;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Area build() {
|
||||||
|
return new Area(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user