From f236fa33dee1a121b0a15360a871d48424f365d1 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Sun, 29 Sep 2013 14:46:50 +0200 Subject: [PATCH] add 'Extrusion' RenderInstruction to RenderTheme --- .../layers/tile/vector/VectorTileLoader.java | 27 ++++++++++++++++ vtm/src/org/oscim/theme/IRenderTheme.java | 9 ++++++ .../org/oscim/theme/RenderThemeHandler.java | 31 +++++++++++++++++++ .../theme/renderinstruction/Extrusion.java | 25 +++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 vtm/src/org/oscim/theme/renderinstruction/Extrusion.java diff --git a/vtm/src/org/oscim/layers/tile/vector/VectorTileLoader.java b/vtm/src/org/oscim/layers/tile/vector/VectorTileLoader.java index 9a6751ad..648de91d 100644 --- a/vtm/src/org/oscim/layers/tile/vector/VectorTileLoader.java +++ b/vtm/src/org/oscim/layers/tile/vector/VectorTileLoader.java @@ -33,6 +33,7 @@ import org.oscim.renderer.elements.TextItem; import org.oscim.theme.IRenderTheme; import org.oscim.theme.renderinstruction.Area; import org.oscim.theme.renderinstruction.Circle; +import org.oscim.theme.renderinstruction.Extrusion; import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.LineSymbol; import org.oscim.theme.renderinstruction.RenderInstruction; @@ -391,6 +392,32 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac } + @Override + public void renderExtrusion(Extrusion extrusion, int level) { + + int height = 0; + int minHeight = 0; + + String v = mElement.tags.getValue(Tag.KEY_HEIGHT); + if (v != null) + height = Integer.parseInt(v); + v = mElement.tags.getValue(Tag.KEY_MIN_HEIGHT); + if (v != null) + minHeight = Integer.parseInt(v); + + ExtrusionLayer l = (ExtrusionLayer) mTile.layers.extrusionLayers; + + if (l == null) { + double lat = MercatorProjection.toLatitude(mTile.y); + float groundScale = (float) (Math.cos(lat * (Math.PI / 180)) + * MercatorProjection.EARTH_CIRCUMFERENCE + / ((long) Tile.SIZE << mTile.zoomLevel)); + + mTile.layers.extrusionLayers = l = new ExtrusionLayer(0, groundScale); + } + l.add(mElement, height, minHeight); + } + /** * used for event-driven loading by html backend */ diff --git a/vtm/src/org/oscim/theme/IRenderTheme.java b/vtm/src/org/oscim/theme/IRenderTheme.java index bd47d703..2a1a7c8c 100644 --- a/vtm/src/org/oscim/theme/IRenderTheme.java +++ b/vtm/src/org/oscim/theme/IRenderTheme.java @@ -19,6 +19,7 @@ import org.oscim.core.GeometryBuffer.GeometryType; import org.oscim.core.TagSet; import org.oscim.theme.renderinstruction.Area; import org.oscim.theme.renderinstruction.Circle; +import org.oscim.theme.renderinstruction.Extrusion; import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.LineSymbol; import org.oscim.theme.renderinstruction.RenderInstruction; @@ -81,6 +82,14 @@ public interface IRenderTheme { */ void renderArea(Area area, int level); + /** + * Renders an extrusion with the given parameters. + * + * @param extrusion + * @param level + */ + void renderExtrusion(Extrusion extrusion, int level); + /** * Renders an area symbol with the given bitmap. * diff --git a/vtm/src/org/oscim/theme/RenderThemeHandler.java b/vtm/src/org/oscim/theme/RenderThemeHandler.java index 9c5643b1..8a3a8fbf 100644 --- a/vtm/src/org/oscim/theme/RenderThemeHandler.java +++ b/vtm/src/org/oscim/theme/RenderThemeHandler.java @@ -37,6 +37,7 @@ import org.oscim.renderer.elements.TextureItem; import org.oscim.theme.renderinstruction.Area; import org.oscim.theme.renderinstruction.AreaLevel; import org.oscim.theme.renderinstruction.Circle; +import org.oscim.theme.renderinstruction.Extrusion; import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.LineSymbol; import org.oscim.theme.renderinstruction.RenderInstruction; @@ -304,6 +305,11 @@ public class RenderThemeHandler extends DefaultHandler { Log.d(TAG, "BUG not an outline style: " + style); } + } else if ("extrusion".equals(localName)) { + checkState(localName, Element.RENDERING_INSTRUCTION); + Extrusion extrusion = createExtrusion(localName, attributes, mLevel++); + mCurrentRule.addRenderingInstruction(extrusion); + } else if ("atlas".equals(localName)) { checkState(localName, Element.ATLAS); createAtlas(localName, attributes); @@ -828,4 +834,29 @@ public class RenderThemeHandler extends DefaultHandler { + elementName); } } + + private Extrusion createExtrusion(String elementName, Attributes attributes, int level) { + int colorSide = 0; + int colorTop = 0; + int colorLine = 0; + + for (int i = 0; i < attributes.getLength(); ++i) { + String name = attributes.getLocalName(i); + String value = attributes.getValue(i); + + if ("fill-sides".equals(name)) + colorSide = Color.parseColor(value); + + else if ("fill-top".equals(name)) + colorTop = Color.parseColor(value); + + else if ("stroke".equals(name)) + colorLine = Color.parseColor(value); + + else + logUnknownAttribute(elementName, name, value, i); + } + + return new Extrusion(level, colorSide, colorTop, colorLine); + } } diff --git a/vtm/src/org/oscim/theme/renderinstruction/Extrusion.java b/vtm/src/org/oscim/theme/renderinstruction/Extrusion.java new file mode 100644 index 00000000..a8a32862 --- /dev/null +++ b/vtm/src/org/oscim/theme/renderinstruction/Extrusion.java @@ -0,0 +1,25 @@ +package org.oscim.theme.renderinstruction; + +import org.oscim.theme.IRenderTheme.Callback; + +public class Extrusion extends RenderInstruction { + + public Extrusion(int level, int colorSides, int colorTop, int colorLine) { + this.colorSide = colorSides; + this.colorTop = colorTop; + this.colorLine = colorLine; + + this.level = level; + } + + @Override + public void renderWay(Callback renderCallback) { + renderCallback.renderExtrusion(this, this.level); + } + + private final int level; + + public final int colorTop; + public final int colorSide; + public final int colorLine; +}