add 'Extrusion' RenderInstruction to RenderTheme
This commit is contained in:
parent
206003e1ec
commit
f236fa33de
vtm/src/org/oscim
layers/tile/vector
theme
@ -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
|
||||
*/
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
25
vtm/src/org/oscim/theme/renderinstruction/Extrusion.java
Normal file
25
vtm/src/org/oscim/theme/renderinstruction/Extrusion.java
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user