implement basic xml renderer

git-svn-id: https://osmand.googlecode.com/svn/trunk@682 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-11-21 14:08:30 +00:00
parent 85ad5226a4
commit ab9f6a46bd
12 changed files with 1650 additions and 932 deletions

View file

@ -5,7 +5,7 @@ public class Version {
public static final String APP_NAME = "OsmAnd"; //$NON-NLS-1$
public static final String APP_MAP_CREATOR_NAME = "OsmAndMapCreator"; //$NON-NLS-1$
public static final String APP_VERSION = "0.5.1"; //$NON-NLS-1$
public static final String APP_DESCRIPTION = "alpha (b3)"; //$NON-NLS-1$
public static final String APP_DESCRIPTION = "alpha (b4)"; //$NON-NLS-1$
public static final boolean VELCOM_EDITION = false;
public static final String APP_NAME_VERSION = APP_NAME + " " + APP_VERSION; //$NON-NLS-1$

View file

@ -1,5 +1,6 @@
package net.osmand.binary;
import net.osmand.binary.BinaryMapIndexReader.MapIndex;
import net.osmand.osm.MapRenderingTypes;
public class BinaryMapDataObject {
@ -14,6 +15,8 @@ public class BinaryMapDataObject {
protected String name;
protected MapIndex mapIndex = null;
public BinaryMapDataObject(){
}
@ -22,6 +25,7 @@ public class BinaryMapDataObject {
this.stringId = stringId;
}
protected void setCoordinates(int[] coordinates) {
this.coordinates = coordinates;
}
@ -59,6 +63,14 @@ public class BinaryMapDataObject {
return highwayAttributes;
}
public MapIndex getMapIndex() {
return mapIndex;
}
public void setMapIndex(MapIndex mapIndex) {
this.mapIndex = mapIndex;
}
protected void setHighwayAttributes(int highwayAttributes) {
this.highwayAttributes = highwayAttributes;
}

View file

@ -20,7 +20,9 @@ import net.osmand.data.Street;
import net.osmand.data.TransportStop;
import net.osmand.data.City.CityType;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.osm.MapUtils;
import net.osmand.osm.MapRenderingTypes.MapRulType;
import net.sf.junidecode.Junidecode;
import org.apache.commons.logging.Log;
@ -43,9 +45,6 @@ public class BinaryMapIndexReader {
private final static Log log = LogUtil.getLog(BinaryMapIndexReader.class);
public BinaryMapIndexReader(final RandomAccessFile raf) throws IOException {
this.raf = raf;
codedIS = CodedInputStreamRAF.newInstance(raf, 1024);
@ -668,6 +667,19 @@ public class BinaryMapIndexReader {
int tag = WireFormat.getTagFieldNumber(t);
switch (tag) {
case 0:
if(index.encodingRules.isEmpty()){
// init encoding rules by default
Map<String, MapRulType> map = MapRenderingTypes.getEncodingRuleTypes();
for(String tags : map.keySet()){
MapRulType rt = map.get(tags);
if(rt.getType(null) != 0){
initMapEncodingRule(index, rt.getType(null), rt.getSubType(null), tags, null);
}
for (String value : rt.getValuesSet()) {
initMapEncodingRule(index, rt.getType(value), rt.getSubType(value), tags, value);
}
}
}
return;
case OsmandOdb.OsmAndMapIndex.NAME_FIELD_NUMBER :
index.setName(codedIS.readString());
@ -696,6 +708,17 @@ public class BinaryMapIndexReader {
}
}
private void initMapEncodingRule(MapIndex index, int type, int subtype, String tag, String val) {
int ind = ((subtype << 5) | type);
if(!index.encodingRules.containsKey(tag)){
index.encodingRules.put(tag, new LinkedHashMap<String, Integer>());
}
index.encodingRules.get(tag).put(val, ind);
if(!index.decodingRules.containsKey(ind)){
index.decodingRules.put(ind, new TagValuePair(tag, val));
}
}
private void readMapEncodingRule(MapIndex index) throws IOException {
int subtype = 0;
int type = 0;
@ -706,10 +729,7 @@ public class BinaryMapIndexReader {
int tag = WireFormat.getTagFieldNumber(t);
switch (tag) {
case 0:
if(!index.encodingRules.containsKey(tags)){
index.encodingRules.put(tags, new LinkedHashMap<String, Integer>());
}
index.encodingRules.get(tags).put(val, ((subtype << 5) | type));
initMapEncodingRule(index, type, subtype, tags, val);
return;
case OsmandOdb.MapEncodingRule.VALUE_FIELD_NUMBER :
val = codedIS.readString();
@ -730,6 +750,7 @@ public class BinaryMapIndexReader {
}
}
private MapRoot readMapLevel() throws IOException {
MapRoot root = new MapRoot();
while(true){
@ -829,7 +850,7 @@ public class BinaryMapIndexReader {
}
codedIS.seek(tree.filePointer);
int oldLimit = codedIS.pushLimit(tree.length);
searchMapTreeBounds(index.left, index.right, index.top, index.bottom, req);
searchMapTreeBounds(index.left, index.right, index.top, index.bottom, req, mapIndex);
codedIS.popLimit(oldLimit);
}
}
@ -1416,7 +1437,7 @@ public class BinaryMapIndexReader {
}
private void searchMapTreeBounds(int pleft, int pright, int ptop, int pbottom,
SearchRequest<BinaryMapDataObject> req) throws IOException {
SearchRequest<BinaryMapDataObject> req, MapIndex root) throws IOException {
int init = 0;
int lastIndexResult = -1;
int cright = 0;
@ -1464,7 +1485,7 @@ public class BinaryMapIndexReader {
if(lastIndexResult == -1){
lastIndexResult = req.searchResults.size();
}
BinaryMapDataObject mapObject = readMapDataObject(cleft, cright, ctop, cbottom, req);
BinaryMapDataObject mapObject = readMapDataObject(cleft, cright, ctop, cbottom, req, root);
if(mapObject != null){
req.searchResults.add(mapObject);
@ -1476,7 +1497,7 @@ public class BinaryMapIndexReader {
length = readInt();
int filePointer = codedIS.getTotalBytesRead();
oldLimit = codedIS.pushLimit(length);
searchMapTreeBounds(cleft, cright, ctop, cbottom, req);
searchMapTreeBounds(cleft, cright, ctop, cbottom, req, root);
codedIS.popLimit(oldLimit);
codedIS.seek(filePointer + length);
if(lastIndexResult >= 0){
@ -1523,7 +1544,8 @@ public class BinaryMapIndexReader {
}
private int MASK_TO_READ = ~((1 << BinaryMapIndexWriter.SHIFT_COORDINATES) - 1);
private BinaryMapDataObject readMapDataObject(int left, int right, int top, int bottom, SearchRequest<BinaryMapDataObject> req) throws IOException {
private BinaryMapDataObject readMapDataObject(int left, int right, int top, int bottom, SearchRequest<BinaryMapDataObject> req,
MapIndex root) throws IOException {
int tag = WireFormat.getTagFieldNumber(codedIS.readTag());
if(OsmandOdb.MapData.COORDINATES_FIELD_NUMBER != tag) {
throw new IllegalArgumentException();
@ -1596,6 +1618,7 @@ public class BinaryMapIndexReader {
BinaryMapDataObject dataObject = new BinaryMapDataObject();
dataObject.coordinates = req.cacheCoordinates.toArray();
dataObject.types = req.cacheTypes.toArray();
dataObject.mapIndex = root;
while(true){
int t = codedIS.readTag();
@ -1765,11 +1788,72 @@ public class BinaryMapIndexReader {
public static class MapIndex extends BinaryIndexPart {
List<MapRoot> roots = new ArrayList<MapRoot>();
Map<String, Map<String, Integer>> encodingRules = new LinkedHashMap<String, Map<String,Integer>>();
Map<String, Map<String, Integer>> encodingRules = new LinkedHashMap<String, Map<String, Integer>>();
Map<Integer, TagValuePair> decodingRules = new LinkedHashMap<Integer, TagValuePair>();
public List<MapRoot> getRoots() {
return roots;
}
public TagValuePair decodeType(int type, int subtype){
return decodingRules.get(((subtype << 5) | type));
}
}
public static class TagValuePair {
public String tag;
public String value;
public int additionalAttribute;
public TagValuePair(String tag, String value) {
super();
this.tag = tag;
this.value = value;
}
public TagValuePair(String tag, String value, int additionalAttribute) {
super();
this.tag = tag;
this.value = value;
this.additionalAttribute = additionalAttribute;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + additionalAttribute;
result = prime * result + ((tag == null) ? 0 : tag.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TagValuePair other = (TagValuePair) obj;
if (additionalAttribute != other.additionalAttribute)
return false;
if (tag == null) {
if (other.tag != null)
return false;
} else if (!tag.equals(other.tag))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}
@ -1856,7 +1940,7 @@ public class BinaryMapIndexReader {
int length = 0;
// offset from start for each SIZE_OFFSET_ARRAY elements
// (SIZE_OFFSET_ARRAY + 1) offset : offsets[0] + skipOneString()
// (SIZE_OFFSET_ARRAY + 1) offset = offsets[0] + skipOneString()
TIntArrayList offsets = new TIntArrayList();
Map<Integer, String> cacheOfStrings = new LinkedHashMap<Integer, String>();
@ -1874,10 +1958,10 @@ public class BinaryMapIndexReader {
}
public static void main(String[] args) throws IOException {
RandomAccessFile raf = new RandomAccessFile(new File("e:\\Information\\OSM maps\\osmand\\Minsk.obf"), "r");
RandomAccessFile raf = new RandomAccessFile(new File("e:\\Information\\OSM maps\\osmand\\Minsk.obf"), "r"); //$NON-NLS-1$ //$NON-NLS-2$
// RandomAccessFile raf = new RandomAccessFile(new File("e:\\Information\\OSM maps\\osmand\\Belarus_4.obf"), "r");
BinaryMapIndexReader reader = new BinaryMapIndexReader(raf);
System.out.println("VERSION " + reader.getVersion());
System.out.println("VERSION " + reader.getVersion()); //$NON-NLS-1$
long time = System.currentTimeMillis();
System.out.println(reader.mapIndexes.get(0).encodingRules);
@ -1951,8 +2035,8 @@ public class BinaryMapIndexReader {
// }
// }
System.out.println("MEMORY " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
System.out.println("Time " + (System.currentTimeMillis() - time));
System.out.println("MEMORY " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); //$NON-NLS-1$
System.out.println("Time " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
}
}

View file

@ -2514,18 +2514,18 @@ public class IndexCreator {
long time = System.currentTimeMillis();
IndexCreator creator = new IndexCreator(new File("e:/Information/OSM maps/osmand/"));
creator.setIndexMap(true);
// creator.setIndexAddress(true);
creator.setIndexAddress(true);
creator.setIndexPOI(true);
// creator.setIndexTransport(true);
creator.setIndexTransport(true);
creator.recreateOnlyBinaryFile = true;
creator.deleteDatabaseIndexes = false;
creator.recreateOnlyBinaryFile = false;
creator.deleteDatabaseIndexes = true;
creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/minsk.tmp.odb"));
creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/minsk.osm"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/minsk.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/minsk.osm"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/belarus_nodes.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/belarus.osm.bz2"), new ConsoleProgressImplementation(3), null);
creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/belarus_nodes.tmp.odb"));
creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/belarus.osm.bz2"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/ams.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/ams_part_map.osm"), new ConsoleProgressImplementation(3), null);
@ -2540,6 +2540,8 @@ public class IndexCreator {
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/luxembourg.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/luxembourg.osm.pbf"), new ConsoleProgressImplementation(15), null);
// creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/new_zealand.osm.bz2"), new ConsoleProgressImplementation(3), null);
System.out.println("WHOLE GENERATION TIME : " + (System.currentTimeMillis() - time));
System.out.println("COORDINATES_SIZE " + BinaryMapIndexWriter.COORDINATES_SIZE + " count " + BinaryMapIndexWriter.COORDINATES_COUNT);

View file

@ -9,6 +9,8 @@ public class MultyPolygon extends BinaryMapDataObject {
// first 32 bits - x, second 32 bits - y
private long[][] lines = null;
private String[] names = null;
private String tag = null;
private String value = null;
public MultyPolygon(){
super();
id = -1;
@ -62,5 +64,21 @@ public class MultyPolygon extends BinaryMapDataObject {
public int getPoint31YTile(int ind, int b) {
return (int)(lines[b][ind] & Integer.MAX_VALUE);
}
public void setTag(String tag) {
this.tag = tag;
}
public void setValue(String value) {
this.value = value;
}
public String getTag() {
return tag;
}
public String getValue() {
return value;
}
}

View file

@ -18,10 +18,10 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class OsmandRenderingRules {
public class OsmandRenderingRulesParser {
private final static Log log = LogUtil.getLog(OsmandRenderingRules.class);
private final static Log log = LogUtil.getLog(OsmandRenderingRulesParser.class);
public static class EffectAttributes {
public int color = 0;
@ -77,15 +77,27 @@ public class OsmandRenderingRules {
}
public interface RenderingRuleVisitor {
/**
* @param state - one of the point, polygon, line, text state
* @param filter
*/
public void visitRule(int state, FilterState filter);
public void rendering(String name, String depends);
}
private final static int POINT_STATE = 1;
private final static int POLYGON_STATE = 2;
private final static int LINE_STATE = 3;
private final static int TEXT_STATE = 4;
public void parseRenderingRules(InputStream is) throws IOException, SAXException {
public final static int POINT_STATE = 1;
public final static int POLYGON_STATE = 2;
public final static int LINE_STATE = 3;
public final static int TEXT_STATE = 4;
public void parseRenderingRules(InputStream is, RenderingRuleVisitor visitor) throws IOException, SAXException {
try {
final SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(is, new RenderingRulesHandler(saxParser));
saxParser.parse(is, new RenderingRulesHandler(saxParser, visitor));
} catch (ParserConfigurationException e) {
throw new SAXException(e);
}
@ -93,12 +105,15 @@ public class OsmandRenderingRules {
private class RenderingRulesHandler extends DefaultHandler {
private final SAXParser parser;
private final RenderingRuleVisitor visitor;
private int state;
Stack<Object> stack = new Stack<Object>();
public RenderingRulesHandler(SAXParser parser){
public RenderingRulesHandler(SAXParser parser, RenderingRuleVisitor visitor){
this.parser = parser;
this.visitor = visitor;
}
@Override
@ -121,8 +136,10 @@ public class OsmandRenderingRules {
} else if("case".equals(name)){ //$NON-NLS-1$
FilterState st = parseFilterAttributes(attributes);
((SwitchState)stack.peek()).filters.add(st);
} else if("renderer".equals(name)){ //$NON-NLS-1$
visitor.rendering(attributes.getValue("name"), attributes.getValue("depends")); //$NON-NLS-1$ //$NON-NLS-2$
} else {
// System.err.println("Unknown tag " + name);
log.warn("Unknown tag" + name); //$NON-NLS-1$
}
}
@ -133,61 +150,15 @@ public class OsmandRenderingRules {
List<FilterState> list = popAndAggregateState();
for (FilterState pop : list) {
if (pop.tag != null && pop.minzoom != -1) {
String gen = generateAttributes(pop);
if (gen != null) {
String res = "";
if (pop.maxzoom != -1) {
res += " zoom : " +pop.minzoom + "-" + pop.maxzoom;
} else {
res += " zoom : " +pop.minzoom;
}
res += " tag="+pop.tag;
res += " val="+pop.val;
if(pop.layer != 0){
res += " layer="+pop.layer;
}
res += gen;
System.out.println(res);
}
visitor.visitRule(state, pop);
}
}
} else if("switch".equals(name)){
} else if("switch".equals(name)){ //$NON-NLS-1$
stack.pop();
}
}
private String generateAttributes(FilterState s){
String res = "";
if(s.shader != null){
res+=" shader=" + s.shader;
}
if(s.main.color != 0){
res +=" color="+colorToString(s.main.color);
}
if(s.icon != null){
res+= " icon="+s.icon;
}
if(s.main.strokeWidth != 0){
res+= " strokeWidth="+s.main.strokeWidth;
}
if(s.main.pathEffect != null){
res+= " pathEffect="+s.main.pathEffect;
}
if(state == POLYGON_STATE){
return null;
// if(s.shader != null){
// return " shader=" + s.shader;
// }
// return " color=" + colorToString(s.main.color);
// } else if(state == POINT_STATE){
// return " icon=" + s.icon;
} else if(state == LINE_STATE){
return res;
} else {
return null;
}
}
public List<FilterState> popAndAggregateState() {
FilterState pop = (FilterState) stack.pop();
@ -204,8 +175,8 @@ public class OsmandRenderingRules {
}
} else {
List<FilterState> filters = ((SwitchState)o).filters;
if(res == null){
res =new ArrayList<FilterState>();
if (res == null) {
res = new ArrayList<FilterState>();
res.add(pop);
}
int l = res.size();
@ -217,7 +188,7 @@ public class OsmandRenderingRules {
}
}
for (int j = 0; j < res.size(); j++) {
mergeStateInto(filters.get(j % filters.size()), res.get(j));
mergeStateInto(filters.get(j / l), res.get(j));
}
}
@ -327,76 +298,76 @@ public class OsmandRenderingRules {
for(int i=0; i<attributes.getLength(); i++){
String name = attributes.getLocalName(i);
String val = attributes.getValue(i);
if(name.equals("tag")){
if(name.equals("tag")){ //$NON-NLS-1$
state.tag = val;
} else if(name.equals("value")){
} else if(name.equals("value")){ //$NON-NLS-1$
state.val = val;
} else if(name.equals("minzoom")){
} else if(name.equals("minzoom")){ //$NON-NLS-1$
state.minzoom = Integer.parseInt(val);
} else if(name.equals("maxzoom")){
} else if(name.equals("maxzoom")){ //$NON-NLS-1$
state.maxzoom = Integer.parseInt(val);
} else if(name.equals("maxzoom")){
} else if(name.equals("maxzoom")){ //$NON-NLS-1$
state.maxzoom = Integer.parseInt(val);
} else if(name.equals("layer")){
} else if(name.equals("layer")){ //$NON-NLS-1$
state.layer = Integer.parseInt(val);
} else if(name.equals("icon")){
} else if(name.equals("icon")){ //$NON-NLS-1$
state.icon = val;
} else if(name.equals("color")){
} else if(name.equals("color")){ //$NON-NLS-1$
state.main.color = parseColor(val);
} else if(name.startsWith("color_")){
} else if(name.startsWith("color_")){ //$NON-NLS-1$
EffectAttributes ef = state.getEffectAttributes(Integer.parseInt(name.substring(6)));
ef.color = parseColor(val);
} else if(name.equals("shader")){
} else if(name.equals("shader")){ //$NON-NLS-1$
state.shader = val;
} else if(name.equals("strokeWidth")){
} else if(name.equals("strokeWidth")){ //$NON-NLS-1$
state.main.strokeWidth = Float.parseFloat(val);
} else if(name.startsWith("strokeWidth_")){
} else if(name.startsWith("strokeWidth_")){ //$NON-NLS-1$
EffectAttributes ef = state.getEffectAttributes(Integer.parseInt(name.substring(12)));
ef.strokeWidth = Float.parseFloat(val);
} else if(name.equals("pathEffect")){
} else if(name.equals("pathEffect")){ //$NON-NLS-1$
state.main.pathEffect = val;
} else if(name.startsWith("pathEffect_")){
} else if(name.startsWith("pathEffect_")){ //$NON-NLS-1$
EffectAttributes ef = state.getEffectAttributes(Integer.parseInt(name.substring(11)));
ef.pathEffect = val;
} else if(name.equals("shadowRadius")){
} else if(name.equals("shadowRadius")){ //$NON-NLS-1$
state.main.shadowRadius = Float.parseFloat(val);
} else if(name.startsWith("shadowRadius_")){
} else if(name.startsWith("shadowRadius_")){ //$NON-NLS-1$
EffectAttributes ef = state.getEffectAttributes(Integer.parseInt(name.substring(14)));
ef.shadowRadius = Float.parseFloat(val);
} else if(name.equals("shadowColor")){
} else if(name.equals("shadowColor")){ //$NON-NLS-1$
state.main.shadowColor = parseColor(val);
} else if(name.startsWith("shadowColor_")){
} else if(name.startsWith("shadowColor_")){ //$NON-NLS-1$
EffectAttributes ef = state.getEffectAttributes(Integer.parseInt(name.substring(12)));
ef.shadowColor = parseColor(val);
} else if(name.equals("cap")){
} else if(name.equals("cap")){ //$NON-NLS-1$
state.main.cap = val;
} else if(name.startsWith("cap_")){
} else if(name.startsWith("cap_")){ //$NON-NLS-1$
EffectAttributes ef = state.getEffectAttributes(Integer.parseInt(name.substring(4)));
ef.cap = val;
} else if(name.equals("ref")){
} else if(name.equals("ref")){ //$NON-NLS-1$
state.text.ref = val;
} else if(name.equals("textSize")){
} else if(name.equals("textSize")){ //$NON-NLS-1$
state.text.textSize = Float.parseFloat(val);
} else if(name.equals("textBold")){
} else if(name.equals("textBold")){ //$NON-NLS-1$
state.text.textBold = Boolean.parseBoolean(val);
} else if(name.equals("textColor")){
} else if(name.equals("textColor")){ //$NON-NLS-1$
state.text.textColor = parseColor(val);
} else if(name.equals("textLength")){
} else if(name.equals("textLength")){ //$NON-NLS-1$
state.textLength = Integer.parseInt(val);
} else if(name.equals("textShield")){
} else if(name.equals("textShield")){ //$NON-NLS-1$
state.text.textShield = val;
} else if(name.equals("textMinDistance")){
} else if(name.equals("textMinDistance")){ //$NON-NLS-1$
state.text.textMinDistance = Integer.parseInt(val);
} else if(name.equals("textOnPath")){
} else if(name.equals("textOnPath")){ //$NON-NLS-1$
state.text.textOnPath = Boolean.parseBoolean(val);
} else if(name.equals("textWrapWidth")){
} else if(name.equals("textWrapWidth")){ //$NON-NLS-1$
state.text.textWrapWidth = Integer.parseInt(val);
} else if(name.equals("textDy")){
} else if(name.equals("textDy")){ //$NON-NLS-1$
state.text.textDy = Integer.parseInt(val);
} else if(name.equals("textHaloRadius")){
} else if(name.equals("textHaloRadius")){ //$NON-NLS-1$
state.text.textHaloRadius = Float.parseFloat(val);
} else {
log.warn("Unknown attribute " + name);
log.warn("Unknown attribute " + name); //$NON-NLS-1$
}
}
return state;
@ -420,23 +391,83 @@ public class OsmandRenderingRules {
// Set the alpha value
color |= 0x00000000ff000000;
} else if (colorString.length() != 9) {
throw new IllegalArgumentException("Unknown color" + colorString);
throw new IllegalArgumentException("Unknown color" + colorString); //$NON-NLS-1$
}
return (int)color;
}
throw new IllegalArgumentException("Unknown color" + colorString);
throw new IllegalArgumentException("Unknown color" + colorString); //$NON-NLS-1$
}
// TEST purpose
public static void main(String[] args) throws IOException, SAXException {
OsmandRenderingRulesParser parser = new OsmandRenderingRulesParser();
parser.parseRenderingRules(OsmandRenderingRulesParser.class.getResourceAsStream("default.render.xml"), //$NON-NLS-1$
new RenderingRuleVisitor() {
@Override
public void rendering(String name, String depends) {
System.out.println("Renderer " + name); //$NON-NLS-1$
}
@Override
public void visitRule(int state, FilterState filter) {
String gen = generateAttributes(state, filter);
if (gen != null) {
String res = ""; //$NON-NLS-1$
if (filter.maxzoom != -1) {
res += " zoom : " +filter.minzoom + "-" + filter.maxzoom; //$NON-NLS-1$ //$NON-NLS-2$
} else {
res += " zoom : " +filter.minzoom; //$NON-NLS-1$
}
res += " tag="+filter.tag; //$NON-NLS-1$
res += " val="+filter.val; //$NON-NLS-1$
if(filter.layer != 0){
res += " layer="+filter.layer; //$NON-NLS-1$
}
res += gen;
System.out.println(res);
}
}
});
}
public static String colorToString(int color) {
if ((0xFF000000 & color) == 0xFF000000) {
return "#" + Integer.toHexString(color & 0x00FFFFFF);
return "#" + Integer.toHexString(color & 0x00FFFFFF); //$NON-NLS-1$
} else {
return "#" + Integer.toHexString(color);
return "#" + Integer.toHexString(color); //$NON-NLS-1$
}
}
public static void main(String[] args) throws IOException, SAXException {
OsmandRenderingRules parser = new OsmandRenderingRules();
parser.parseRenderingRules(OsmandRenderingRules.class.getResourceAsStream("default.render.xml"));
private static String generateAttributes(int state, FilterState s){
String res = ""; //$NON-NLS-1$
if(s.shader != null){
res+=" shader=" + s.shader; //$NON-NLS-1$
}
if(s.main.color != 0){
res +=" color="+colorToString(s.main.color); //$NON-NLS-1$
}
if(s.icon != null){
res+= " icon="+s.icon; //$NON-NLS-1$
}
if(s.main.strokeWidth != 0){
res+= " strokeWidth="+s.main.strokeWidth; //$NON-NLS-1$
}
if(s.main.pathEffect != null){
res+= " pathEffect="+s.main.pathEffect; //$NON-NLS-1$
}
if(state == POLYGON_STATE){
// return res;
} else if(state == LINE_STATE){
return res;
} else if(state == POINT_STATE){
// return res;
} else if(state == TEXT_STATE){
// return res;
}
return null;
}
}

View file

@ -1,4 +1,4 @@
<renderer>
<renderer name="default" depends="">
<!--
Currently available icons : aerodrome, airport, alpinehut, atm, bank, bar, beach, bollard, bus_station, bus_stop_small, bus_stop,
cable_car, cafe, camp_site, car_share, caravan_park, cave_entrance, chair_lift, cinema, cliff, cliff2, danger, department_store, embassy,
@ -11,7 +11,7 @@
-->
<!-- TODO oneway!!! -->
<!-- PRIORITY Input to filter : tag, value, point, zoom [minzoom, maxzoom], textLength, ref -->
<!-- PRIORITY Input to filter : tag, value, zoom [minzoom, maxzoom], textLength, ref -->
<text>
<!-- Highway ref -->
<filter minzoom="10" tag="highway" value="trunk" ref="only" textMinDistance="70" textColor="#ffffff" textSize="10" textBold="true">
@ -175,7 +175,7 @@
<filter minzoom="16" textSize="9" textColor="#000033" textWrapWidth="16" tag="amenity" value="kindergarten" />
<filter minzoom="16" textSize="9" textColor="#000033" textDy="11" textWrapWidth="16" tag="amenity" value="school" />
<filter minzoom="16" textSize="9" textColor="#000033" textDy="11" textWrapWidth="16" tag="amenity" value="college" />
<filter minzoom="17" textSize="10" textBold="true" textColor="#734a08" textDy="12" tag="amenity" value="library" />
<filter minzoom="17" textSize="10" textBold="true" textColor="#734a08" textWrapWidth="16" textDy="12" tag="amenity" value="library" />
<filter minzoom="15" textSize="9" textBold="true" textColor="#000033" textWrapWidth="16" tag="amenity" value="university" />
<filter minzoom="17" textSize="9" textColor="#0066ff" textDy="9" textWrapWidth="34" tag="amenity" value="parking" />

View file

@ -0,0 +1,259 @@
package net.osmand.render;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.LogUtil;
import net.osmand.render.OsmandRenderer.RenderingContext;
import net.osmand.render.OsmandRenderer.RenderingPaintProperties;
import net.osmand.render.OsmandRenderingRulesParser.EffectAttributes;
import net.osmand.render.OsmandRenderingRulesParser.FilterState;
import net.osmand.render.OsmandRenderingRulesParser.RenderingRuleVisitor;
import org.apache.commons.logging.Log;
import org.xml.sax.SAXException;
import android.graphics.Color;
import android.graphics.Paint.Cap;
public class BaseOsmandRender implements RenderingRuleVisitor {
public String name = "default"; //$NON-NLS-1$
public List<String> depends = new ArrayList<String>();
private static final Log log = LogUtil.getLog(BaseOsmandRender.class);
@SuppressWarnings("unchecked")
private Map<String, Map<String, List<FilterState>>>[] rules = new LinkedHashMap[5];
private static BaseOsmandRender defaultRender = null;
public static BaseOsmandRender defaultRender() throws IOException, SAXException{
if(defaultRender == null){
defaultRender = new BaseOsmandRender(OsmandRenderingRulesParser.class.getResourceAsStream("default.render.xml")); //$NON-NLS-1$
}
return defaultRender;
}
public BaseOsmandRender(InputStream is) throws IOException, SAXException {
long time = System.currentTimeMillis();
OsmandRenderingRulesParser parser = new OsmandRenderingRulesParser();
parser.parseRenderingRules(is, this);
log.info("Init render " + name + " for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
protected BaseOsmandRender(){
}
@Override
public void rendering(String name, String depends) {
this.name = name;
if(depends != null && depends.length() > 0){
for(String s : depends.split(",")) { //$NON-NLS-1$
if(s.trim().length() > 0){
this.depends.add(s.trim());
}
}
}
}
@Override
public void visitRule(int state, FilterState filter) {
boolean accept = filter.minzoom != -1;
if(state == OsmandRenderingRulesParser.POINT_STATE){
accept &= RenderingIcons.getIcons().containsKey(filter.icon);
}
if (accept) {
if (rules[state] == null) {
rules[state] = new LinkedHashMap<String, Map<String, List<FilterState>>>();
}
if (rules[state].get(filter.tag) == null) {
rules[state].put(filter.tag, new LinkedHashMap<String, List<FilterState>>());
}
if (rules[state].get(filter.tag).get(filter.val) == null) {
rules[state].get(filter.tag).put(filter.val, new ArrayList<FilterState>(3));
}
rules[state].get(filter.tag).get(filter.val).add(filter);
}
}
public Integer getPointIcon(String tag, String val, int zoom){
Integer i = getPointIconImpl(tag,val, zoom);
if(i== null){
return getPointIconImpl(tag, null, zoom);
}
return i;
}
private Integer getPointIconImpl(String tag, String val, int zoom) {
Map<String, List<FilterState>> map = rules[OsmandRenderingRulesParser.POINT_STATE].get(tag);
if (map != null) {
List<FilterState> list = map.get(val);
if (list != null) {
for (FilterState f : list) {
if (f.minzoom <= zoom && (zoom <= f.maxzoom || f.maxzoom == -1)) {
return RenderingIcons.getIcons().get(f.icon);
}
}
}
}
return null;
}
// TODO layer
public boolean renderPolyline(String tag, String val, int zoom, RenderingContext rc, OsmandRenderer o){
boolean r = renderPolylineImpl(tag,val, zoom, rc, o);
if(!r){
return renderPolylineImpl(tag, null, zoom, rc, o);
}
return r;
}
private boolean renderPolylineImpl(String tag, String val, int zoom, RenderingContext rc, OsmandRenderer o) {
Map<String, List<FilterState>> map = rules[OsmandRenderingRulesParser.LINE_STATE].get(tag);
if (map != null) {
List<FilterState> list = map.get(val);
if (list != null) {
for (FilterState f : list) {
// TODO layer!!!
if (f.minzoom <= zoom && (zoom <= f.maxzoom || f.maxzoom == -1) && f.layer == 0) {
// to not make transparent
rc.main.color = Color.BLACK;
if(f.shader != null){
Integer i = RenderingIcons.getIcons().get(f.shader);
if(i != null){
rc.main.shader = o.getShader(i);
}
}
rc.main.fillArea = false;
applyEffectAttributes(f.main, rc.main, o);
if(f.effectAttributes.size() > 0){
applyEffectAttributes(f.effectAttributes.get(0), rc.second, o);
if(f.effectAttributes.size() > 1){
applyEffectAttributes(f.effectAttributes.get(1), rc.third, o);
}
}
return true;
}
}
}
}
return false;
}
public boolean renderPolygon(String tag, String val, int zoom, RenderingContext rc, OsmandRenderer o){
boolean r = renderPolygonImpl(tag,val, zoom, rc, o);
if(!r){
return renderPolygonImpl(tag, null, zoom, rc, o);
}
return r;
}
private boolean renderPolygonImpl(String tag, String val, int zoom, RenderingContext rc, OsmandRenderer o) {
Map<String, List<FilterState>> map = rules[OsmandRenderingRulesParser.POLYGON_STATE].get(tag);
if (map != null) {
List<FilterState> list = map.get(val);
if (list != null) {
for (FilterState f : list) {
if (f.minzoom <= zoom && (zoom <= f.maxzoom || f.maxzoom == -1)) {
if(f.shader != null){
Integer i = RenderingIcons.getIcons().get(f.shader);
if(i != null){
// to not make transparent
rc.main.color = Color.BLACK;
rc.main.shader = o.getShader(i);
}
}
rc.main.fillArea = true;
applyEffectAttributes(f.main, rc.main, o);
if(f.effectAttributes.size() > 0){
applyEffectAttributes(f.effectAttributes.get(0), rc.second, o);
if(f.effectAttributes.size() > 1){
applyEffectAttributes(f.effectAttributes.get(1), rc.third, o);
}
}
return true;
}
}
}
}
return false;
}
private void applyEffectAttributes(EffectAttributes ef, RenderingPaintProperties props, OsmandRenderer o){
if(ef.cap != null){
props.cap = Cap.valueOf(ef.cap.toUpperCase());
}
if(ef.color != 0){
// do not set transparent color
props.color = ef.color;
}
if(ef.pathEffect != null){
props.pathEffect = o.getDashEffect(ef.pathEffect);
}
if(ef.strokeWidth > 0){
props.strokeWidth = ef.strokeWidth;
}
if(ef.shadowColor != 0 && ef.shadowRadius > 0){
props.shadowColor = ef.shadowColor;
props.shadowLayer = (int) ef.shadowRadius;
}
}
public String renderObjectText(String name, String tag, String val, RenderingContext rc) {
if(name == null || name.length() == 0){
return null;
}
String ret = renderObjectTextImpl(name, tag, val, rc);
if(rc.textSize > 0){
return ret;
}
return renderObjectTextImpl(name, tag, null, rc);
}
private String renderObjectTextImpl(String name, String tag, String val, RenderingContext rc) {
Map<String, List<FilterState>> map = rules[OsmandRenderingRulesParser.TEXT_STATE].get(tag);
if (map != null) {
List<FilterState> list = map.get(val);
if (list != null) {
// first find rule with same text length
for (FilterState f : list) {
if (f.minzoom <= rc.zoom && (rc.zoom <= f.maxzoom || f.maxzoom == -1)) {
if(f.textLength == name.length() && f.text.textSize > 0){
fillTextProperties(f, rc);
return name;
}
}
}
for (FilterState f : list) {
if (f.minzoom <= rc.zoom && (rc.zoom <= f.maxzoom || f.maxzoom == -1)) {
if(f.textLength == 0 && f.text.textSize > 0){
fillTextProperties(f, rc);
return name;
}
}
}
}
}
return null;
}
private void fillTextProperties(FilterState f, RenderingContext rc) {
rc.textSize = f.text.textSize;
rc.textColor = f.text.textColor;
rc.textSize = f.text.textSize;
rc.textMinDistance = f.text.textMinDistance;
rc.showTextOnPath = f.text.textOnPath;
Integer i = RenderingIcons.getIcons().get(f.text.textShield);
rc.textShield = i== null ? 0 : i.intValue();
rc.textWrapWidth = f.text.textWrapWidth;
rc.textHaloRadius = f.text.textHaloRadius;
rc.textBold = f.text.textBold;
rc.textDy = f.text.textDy;
}
}

View file

@ -25,6 +25,7 @@ import net.osmand.RotatedTileBox;
import net.osmand.binary.BinaryMapDataObject;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
import net.osmand.data.index.IndexConstants;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.osm.MapUtils;
@ -193,7 +194,7 @@ public class MapRenderRepositories {
ArrayList<BinaryMapDataObject> tempList = new ArrayList<BinaryMapDataObject>();
System.gc(); // to clear previous objects
TLongSet ids = new TLongHashSet();
Map<Integer, List<BinaryMapDataObject>> multiPolygons = new LinkedHashMap<Integer, List<BinaryMapDataObject>>();
Map<TagValuePair, List<BinaryMapDataObject>> multiPolygons = new LinkedHashMap<TagValuePair, List<BinaryMapDataObject>>();
int leftX = MapUtils.get31TileNumberX(cLeftLongitude);
int rightX = MapUtils.get31TileNumberX(cRightLongitude);
int bottomY = MapUtils.get31TileNumberY(cBottomLatitude);
@ -242,7 +243,19 @@ public class MapRenderRepositories {
count++;
for(int i=0; i < r.getTypes().length; i++){
registerMultipolygon(multiPolygons, r.getTypes()[i], r);
if ((r.getTypes()[i] & 0x3) == MapRenderingTypes.MULTY_POLYGON_TYPE) {
// multy polygon
int type = MapRenderingTypes.getMainObjectType(r.getTypes()[i]);
int subtype = MapRenderingTypes.getObjectSubType(r.getTypes()[i]);
TagValuePair pair = r.getMapIndex().decodeType(type, subtype);
if(pair != null){
pair = new TagValuePair(pair.tag, pair.value, r.getTypes()[i]);
if (!multiPolygons.containsKey(pair)) {
multiPolygons.put(pair, new ArrayList<BinaryMapDataObject>());
}
multiPolygons.get(pair).add(r);
}
}
}
@ -339,30 +352,18 @@ public class MapRenderRepositories {
/// Manipulating with multipolygons
private void registerMultipolygon(Map<Integer, List<BinaryMapDataObject>> multyPolygons, int type, BinaryMapDataObject obj) {
if ((type & 0x3) == MapRenderingTypes.MULTY_POLYGON_TYPE) {
// multy polygon
if (type != 0) {
if (!multyPolygons.containsKey(type)) {
multyPolygons.put(type, new ArrayList<BinaryMapDataObject>());
}
multyPolygons.get(type).add(obj);
}
}
}
public List<MultyPolygon> proccessMultiPolygons(Map<Integer, List<BinaryMapDataObject>> multyPolygons, int leftX, int rightX, int bottomY, int topY, int zoom){
public List<MultyPolygon> proccessMultiPolygons(Map<TagValuePair, List<BinaryMapDataObject>> multyPolygons, int leftX, int rightX, int bottomY, int topY, int zoom){
List<MultyPolygon> listPolygons = new ArrayList<MultyPolygon>(multyPolygons.size());
List<List<Long>> completedRings = new ArrayList<List<Long>>();
List<List<Long>> incompletedRings = new ArrayList<List<Long>>();
List<String> completedRingNames = new ArrayList<String>();
List<String> incompletedRingNames = new ArrayList<String>();
for (Integer type : multyPolygons.keySet()) {
for (TagValuePair type : multyPolygons.keySet()) {
List<BinaryMapDataObject> directList;
List<BinaryMapDataObject> inverselist;
if(((type >> 15) & 1) == 1){
int directType = (type & ((1 << 15) - 1));
if(((type.additionalAttribute >> 15) & 1) == 1){
TagValuePair directType = new TagValuePair(type.tag, type.value, type.additionalAttribute & ((1 << 15) - 1));
if (!multyPolygons.containsKey(directType)) {
inverselist = multyPolygons.get(type);
directList = Collections.emptyList();
@ -371,7 +372,7 @@ public class MapRenderRepositories {
continue;
}
} else {
int inverseType = (type | (1 << 15));
TagValuePair inverseType = new TagValuePair(type.tag, type.value, type.additionalAttribute | (1 << 15));
directList = multyPolygons.get(type);
inverselist = Collections.emptyList();
if (multyPolygons.containsKey(inverseType)) {
@ -394,10 +395,13 @@ public class MapRenderRepositories {
private MultyPolygon processMultiPolygon(int leftX, int rightX, int bottomY, int topY, List<MultyPolygon> listPolygons,
List<List<Long>> completedRings, List<List<Long>> incompletedRings, List<String> completedRingNames, List<String> incompletedRingNames,
Integer type, List<BinaryMapDataObject> directList, List<BinaryMapDataObject> inverselist, int zoom) {
TagValuePair type, List<BinaryMapDataObject> directList, List<BinaryMapDataObject> inverselist, int zoom) {
MultyPolygon pl = new MultyPolygon();
// TODO delete setType at all!!!
// delete direction last bit (to not show point)
pl.setType(type & 0x7fff);
pl.setType(type.additionalAttribute);
pl.setTag(type.tag);
pl.setValue(type.value);
long dbId = 0;
for (int km = 0; km < 2; km++) {
List<BinaryMapDataObject> list = km == 0 ? directList : inverselist;
@ -443,8 +447,7 @@ public class MapRenderRepositories {
} else {
// due to self intersection small objects (for low zooms check only coastline)
if (zoom >= 13
|| (MapRenderingTypes.getMainObjectType(pl.getTypes()[0]) == MapRenderingTypes.NATURAL && MapRenderingTypes
.getObjectSubType(pl.getTypes()[0]) == 5)) {
|| ("natural".equals(type.tag) && "coastline".equals(type.value))) { //$NON-NLS-1$//$NON-NLS-2$
boolean clockwiseFound = false;
for (List<Long> c : completedRings) {
if (isClockwiseWay(c)) {

File diff suppressed because it is too large Load diff

View file

@ -9,14 +9,14 @@ public class RenderingIcons {
private static Map<String, Integer> icons = new LinkedHashMap<String, Integer>();
public Map<String, Integer> getIcons(){
public static Map<String, Integer> getIcons(){
if(icons.isEmpty()){
initIcons();
}
return icons;
}
private void initIcons() {
private static void initIcons() {
icons.put("aerodrome", R.drawable.h_aerodrome); //$NON-NLS-1$
icons.put("airport", R.drawable.h_airport); //$NON-NLS-1$
icons.put("alpinehut", R.drawable.h_alpinehut); //$NON-NLS-1$

View file

@ -0,0 +1,764 @@
package net.osmand.render;
import net.osmand.R;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.render.OsmandRenderer.RenderingContext;
import android.graphics.Color;
public class TextRenderer {
private static int[] trunkShields = new int[]{R.drawable.tru_shield1, R.drawable.tru_shield2, R.drawable.tru_shield3,
R.drawable.tru_shield4, R.drawable.tru_shield5, R.drawable.tru_shield6, R.drawable.tru_shield7,};
private static int[] motorShields = new int[]{R.drawable.mot_shield1, R.drawable.mot_shield2, R.drawable.mot_shield3,
R.drawable.mot_shield4, R.drawable.mot_shield5, R.drawable.mot_shield6, R.drawable.mot_shield7,};
private static int[] primaryShields = new int[]{R.drawable.pri_shield1, R.drawable.pri_shield2, R.drawable.pri_shield3,
R.drawable.pri_shield4, R.drawable.pri_shield5, R.drawable.pri_shield6, R.drawable.pri_shield7,};
private static int[] secondaryShields = new int[]{R.drawable.sec_shield1, R.drawable.sec_shield2, R.drawable.sec_shield3,
R.drawable.sec_shield4, R.drawable.sec_shield5, R.drawable.sec_shield6, R.drawable.sec_shield7,};
private static int[] tertiaryShields = new int[]{R.drawable.ter_shield1, R.drawable.ter_shield2, R.drawable.ter_shield3,
R.drawable.ter_shield4, R.drawable.ter_shield5, R.drawable.ter_shield6, R.drawable.ter_shield7,};
public static String renderObjectText(String name, int subType, int type, int zoom, boolean point, RenderingContext rc) {
if(name == null || name.length() == 0){
return null;
}
int textSize = 0;
int textColor = 0;
int wrapWidth = 0;
int shadowRadius = 0;
int textMinDistance = 0;
int textShield = 0;
int dy = 0;
boolean bold = false;
boolean showTextOnPath = false;
switch (type) {
case MapRenderingTypes.HIGHWAY : {
if(name.charAt(0) == MapRenderingTypes.REF_CHAR){
name = name.substring(1);
for(int k = 0; k < name.length(); k++){
if(name.charAt(k) == MapRenderingTypes.REF_CHAR){
if(k < name.length() - 1 && zoom > 14){
rc.showAnotherText = name.substring(k + 1);
}
name = name.substring(0, k);
break;
}
}
if(rc.showAnotherText != null && zoom >= 16){
break;
}
if(name.length() > 6){
name = name.substring(0, 6);
}
int len = name.length();
if(len == 0){
// skip it
} else {
textSize = 10;
textColor = Color.WHITE;
bold = true;
textMinDistance = 70;
// spacing = 750
if (subType == MapRenderingTypes.PL_HW_TRUNK) {
textShield = trunkShields[len - 1];
if(zoom < 10){
textSize = 0;
}
} else if (subType == MapRenderingTypes.PL_HW_MOTORWAY) {
textShield = motorShields[len - 1];
if(zoom < 10){
textSize = 0;
}
} else if (subType == MapRenderingTypes.PL_HW_PRIMARY) {
textShield = primaryShields[len - 1];
if(zoom < 11){
textSize = 0;
}
} else if (subType == MapRenderingTypes.PL_HW_SECONDARY) {
if(zoom < 14){
textSize = 0;
}
textShield = secondaryShields[len - 1];
} else if (subType == MapRenderingTypes.PL_HW_TERTIARY) {
if(zoom < 15){
textSize = 0;
}
textShield = tertiaryShields[len - 1];
} else {
if(zoom < 16){
textSize = 0;
} else {
showTextOnPath = true;
textColor = Color.BLACK;
textSize = 10;
textMinDistance = 40;
shadowRadius = 1;
// spacing = 750;
}
}
}
} else {
if(subType == MapRenderingTypes.PL_HW_TRUNK || subType == MapRenderingTypes.PL_HW_PRIMARY
|| subType == MapRenderingTypes.PL_HW_SECONDARY){
textColor = Color.BLACK;
showTextOnPath = true;
if(zoom == 13 && type != MapRenderingTypes.PL_HW_SECONDARY){
textSize = 8;
} else if(zoom == 14){
textSize = 9;
} else if(zoom > 14 && zoom < 17){
textSize = 10;
} else if(zoom > 16){
textSize = 12;
}
} else if(subType == MapRenderingTypes.PL_HW_TERTIARY || subType == MapRenderingTypes.PL_HW_RESIDENTIAL
|| subType == MapRenderingTypes.PL_HW_UNCLASSIFIED || subType == MapRenderingTypes.PL_HW_SERVICE){
textColor = Color.BLACK;
showTextOnPath = true;
if(zoom < 15){
textSize = 0;
} else if(zoom < 17){
textSize = 9;
} else {
textSize = 11;
}
} else if(subType < 32){
// highway subtype
if(zoom >= 16){
textColor = Color.BLACK;
showTextOnPath = true;
textSize = 9;
}
} else if(subType == 40){
// bus stop
if(zoom >= 17){
textMinDistance = 20;
textColor = Color.BLACK;
textSize = 9;
wrapWidth = 25;
dy = 11;
}
}
}
} break;
case MapRenderingTypes.WATERWAY : {
if (subType == 1) {
if (zoom >= 15 /* && !tunnel */) {
showTextOnPath = true;
textSize = 8;
shadowRadius = 1;
textColor = 0xff6699cc;
}
} else if (subType == 2 || subType == 4) {
if (zoom >= 12 /* && !tunnel */) {
textSize = 9;
showTextOnPath = true;
shadowRadius = 1;
textColor = 0xff6699cc;
textMinDistance = 70;
}
} else if (subType == 5 || subType == 6) {
if (zoom >= 15 /* && !tunnel */) {
textSize = 8;
showTextOnPath = true;
shadowRadius = 1;
textColor = 0xff6699cc;
}
} else if (subType == 12) {
if(zoom >= 15){
textColor = Color.BLACK;
textSize = 8;
shadowRadius = 1;
}
} else if (subType == 8) {
if (zoom >= 15) {
shadowRadius = 1;
textSize = 9;
textColor = 0xff0066ff;
wrapWidth = 70;
dy = 10;
}
}
}
break;
case MapRenderingTypes.AEROWAY: {
textColor = 0xff6692da;
shadowRadius = 1;
if(name.charAt(0) == MapRenderingTypes.REF_CHAR){
name = name.substring(1);
}
if (subType == 7 || subType == 8) {
if (zoom >= 15) {
showTextOnPath = true;
textSize = 10;
textColor = 0xff333333;
textMinDistance = 50;
shadowRadius = 1;
// spacing = 750;
}
} else if (subType == 10) {
// airport
if (zoom >= 10 && zoom <= 12) {
textSize = 9;
dy = -12;
bold = true;
}
} else if (subType == 1) {
// aerodrome
if (zoom >= 10 && zoom <= 12) {
textSize = 8;
dy = -12;
}
} else if (subType == 12) {
if (zoom >= 17) {
textSize = 10;
textColor = 0xffaa66cc;
shadowRadius = 1;
wrapWidth = 10;
}
}
}
break;
case MapRenderingTypes.AERIALWAY: {
if (subType == 7) {
if (zoom >= 14) {
textColor = 0xff6666ff;
shadowRadius = 1;
if (zoom == 14) {
dy = -7;
textSize = 8;
} else {
dy = -10;
textSize = 10;
}
}
}
}
break;
case MapRenderingTypes.RAILWAY: {
if (zoom >= 14) {
textColor = 0xff6666ff;
shadowRadius = 1;
if (subType == 13) {
bold = true;
if (zoom == 14) {
dy = -8;
textSize = 9;
} else {
dy = -10;
textSize = 11;
}
} else if (subType == 22 || subType == 23) {
if (zoom == 14) {
dy = -7;
textSize = 8;
} else {
dy = -10;
textSize = 10;
}
}
}
}
break;
case MapRenderingTypes.EMERGENCY: {
if (zoom >= 17) {
if (subType == 10) {
dy = 9;
textColor = 0xff734a08;
wrapWidth = 30;
textSize = 10;
}
}
}
break;
case MapRenderingTypes.NATURAL: {
if (subType == 23) {
if (zoom >= 12) {
shadowRadius = 2;
textColor = 0xff00000;
textSize = 10;
wrapWidth = 10;
}
} else if (subType == 13) {
if (zoom >= 14) {
shadowRadius = 1;
textColor = 0xff654321;
textSize = 9;
dy = 5;
}
} else if (subType == 3) {
if (zoom >= 15) {
shadowRadius = 1;
textColor = 0xff654321;
textSize = 10;
dy = 9;
wrapWidth = 20;
}
} else if (subType == 21) {
if (zoom >= 12) {
textSize = 10;
shadowRadius = 1;
wrapWidth = 20;
textColor = 0xff6699cc;
}
} else if (subType == 2) {
if (zoom >= 14) {
textSize = 10;
shadowRadius = 1;
wrapWidth = 20;
textColor = 0xff6699cc;
}
} else if (subType == 17) {
if (zoom >= 16) {
textSize = 8;
shadowRadius = 1;
dy = 10;
wrapWidth = 20;
textColor = 0xff6699cc;
}
}
}
break;
case MapRenderingTypes.LANDUSE: {
if (zoom >= 15) {
if (subType == 22) {
textSize = 10;
shadowRadius = 1;
wrapWidth = 20;
textColor = 0xff6699cc;
} else if (point) {
textColor = 0xff000000;
shadowRadius = 2;
wrapWidth = 10;
textSize = 9;
}
}
}
break;
case MapRenderingTypes.TOURISM: {
if (subType == 9) {
if (zoom >= 16) {
textColor = 0xff6699cc;
shadowRadius = 1;
dy = 15;
textSize = 9;
}
} else if (subType == 12 || subType == 13 || subType == 14) {
if (zoom >= 17) {
textColor = 0xff0066ff;
shadowRadius = 1;
dy = 14;
textSize = 10;
}
} else if (subType == 11) {
if (zoom >= 17) {
textColor = 0xff0066ff;
shadowRadius = 1;
dy = 13;
textSize = 8;
}
} else if (subType == 4) {
if (zoom >= 17) {
shadowRadius = 1;
textSize = 10;
textColor = 0xff0066ff;
wrapWidth = 70;
dy = 15;
}
} else if (subType == 5) {
if (zoom >= 17) {
shadowRadius = 1;
textSize = 10;
textColor = 0xff0066ff;
wrapWidth = 70;
dy = 19;
}
} else if (subType == 7) {
if (zoom >= 15) {
textColor = 0xff734a08;
textSize = 9;
wrapWidth = 30;
shadowRadius = 1;
}
} else if (subType == 15) {
if (zoom >= 17) {
textColor = 0xff734a08;
textSize = 10;
dy = 12;
shadowRadius = 1;
}
}
}
break;
case MapRenderingTypes.LEISURE: {
if (subType == 8) {
if (zoom >= 15) {
textColor = Color.BLUE;
textSize = 9;
wrapWidth = 30;
shadowRadius = 1;
}
} else if ((zoom >= 15 && !point) || zoom >= 17) {
textColor = 0xff000000;
shadowRadius = 2;
wrapWidth = 15;
textSize = 9;
}
}
break;
case MapRenderingTypes.HISTORIC: {
if (zoom >= 17) {
if (subType == 6) {
shadowRadius = 1;
textColor = 0xff654321;
textSize = 9;
dy = 12;
wrapWidth = 20;
}
}
}
break;
case MapRenderingTypes.AMENITY_TRANSPORTATION: {
if (zoom >= 17) {
if (subType == 1) {
dy = 9;
textColor = 0xff0066ff;
textSize = 9;
wrapWidth = 34;
} else if (subType == 4 || subType == 18) {
textColor = 0xff0066ff;
shadowRadius = 1;
dy = 13;
textSize = 9;
}
}
}
break;
case MapRenderingTypes.AMENITY_EDUCATION: {
if (subType == 4) {
if (zoom >= 17) {
dy = 12;
textColor = 0xff734a08;
bold = true;
textSize = 10;
}
} else if (subType == 5) {
if (zoom >= 15) {
textColor = 0xff000033;
bold = true;
textSize = 9;
wrapWidth = 16;
}
} else if (subType == 1 || subType == 2 || subType == 3) {
if (zoom >= 16) {
textColor = 0xff000033;
if(subType != 1){
dy = 11;
}
textSize = 9;
wrapWidth = 16;
}
}
}
break;
case MapRenderingTypes.MAN_MADE: {
if (subType == 1 || subType == 5) {
if(zoom >= 16){
textColor = 0xff444444;
textSize = 9;
if(zoom >= 17){
textSize = 11;
if(zoom >= 18){
textSize = 15;
}
}
wrapWidth = 16;
}
} else if (subType == 17) {
if (zoom >= 15) {
textColor = 0xff000033;
textSize = 9;
shadowRadius = 2;
dy = 16;
wrapWidth = 12;
}
} else if (subType == 27) {
if (zoom >= 17) {
textSize = 9;
textColor = 0xff734a08;
dy = 12;
shadowRadius = 1;
wrapWidth = 20;
}
}
}
break;
case MapRenderingTypes.AMENITY_ENTERTAINMENT: {
if (zoom >= 17) {
textSize = 9;
textColor = 0xff734a08;
dy = 12;
shadowRadius = 1;
wrapWidth = 15;
}
} break;
case MapRenderingTypes.AMENITY_FINANCE: {
if (subType == 2) {
if (zoom >= 17) {
shadowRadius = 1;
textSize = 9;
textColor = Color.BLACK;
dy = 14;
}
}
}
break;
case MapRenderingTypes.MILITARY: {
if (subType == 4) {
if (zoom >= 12) {
bold = true;
textSize = 9;
shadowRadius = 1;
wrapWidth = 10;
textColor = 0xffffc0cb;
}
}
}
break;
case MapRenderingTypes.SHOP: {
if (subType == 42 || subType == 13 || subType == 16 || subType == 19 || subType == 31 || subType == 48) {
if (zoom >= 17) {
textColor = 0xff993399;
textSize = 8;
dy = 13;
shadowRadius = 1;
wrapWidth = 14;
}
} else if (subType == 65 || subType == 17) {
if (zoom >= 16) {
textSize = 9;
textColor = 0xff993399;
dy = 13;
shadowRadius = 1;
wrapWidth = 20;
}
}
}
break;
case MapRenderingTypes.AMENITY_HEALTHCARE: {
if (subType == 2) {
if (zoom >= 16) {
textSize = 8;
textColor = 0xffda0092;
dy = 12;
shadowRadius = 2;
wrapWidth = 24;
}
} else if (subType == 1) {
if (zoom >= 17) {
textSize = 8;
textColor = 0xffda0092;
dy = 11;
shadowRadius = 1;
wrapWidth = 12;
}
}
}
break;
case MapRenderingTypes.AMENITY_OTHER: {
if (subType == 10) {
if (zoom >= 17) {
wrapWidth = 30;
textSize = 10;
textColor = 0xff734a08;
dy = 10;
}
} else if (subType == 26) {
if (zoom >= 17) {
wrapWidth = 30;
textSize = 11;
textColor = 0x000033;
dy = 10;
}
} else if (subType == 16) {
if (zoom >= 16) {
textColor = 0xff6699cc;
shadowRadius = 1;
dy = 15;
textSize = 9;
}
} else if (subType == 7) {
if (zoom >= 17) {
textColor = 0xff0066ff;
shadowRadius = 1;
wrapWidth = 20;
dy = 8;
textSize = 9;
}
} else if (subType == 13) {
if (zoom >= 17) {
textColor = 0xff734a08;
textSize = 10;
shadowRadius = 1;
wrapWidth = 20;
dy = 16;
}
} else if (subType == 2) {
if (zoom >= 16) {
textColor = 0xff660033;
textSize = 10;
shadowRadius = 2;
wrapWidth = 10;
}
}
}
break;
case MapRenderingTypes.AMENITY_SUSTENANCE: {
if (zoom >= 17) {
if (subType >= 1 && subType <= 4) {
shadowRadius = 1;
textColor = 0xff734a08;
wrapWidth = 34;
dy = 13;
textSize = 10;
} else if (subType >= 4 && subType <= 6) {
shadowRadius = 1;
textColor = 0xff734a08;
wrapWidth = 34;
dy = 13;
textSize = 10;
}
}
}
break;
case MapRenderingTypes.ADMINISTRATIVE: {
shadowRadius = 1;
switch (subType) {
case 11: {
if (zoom >= 14 && zoom < 16) {
textColor = 0xFF000000;
textSize = 8;
} else if (zoom >= 16) {
textColor = 0xFF777777;
textSize = 11;
}
}
break;
case 8:
case 9: {
if (zoom >= 12 && zoom < 15) {
textColor = 0xFF000000;
textSize = 9;
} else if (zoom >= 15) {
textColor = 0xFF777777;
textSize = 12;
}
}
break;
case 10: {
if (zoom >= 12 && zoom < 14) {
textColor = 0xFF000000;
textSize = 10;
} else if (zoom >= 14) {
textColor = 0xFF777777;
textSize = 13;
}
}
break;
case 19: {
if (zoom >= 8) {
textColor = 0xFF99cc99;
wrapWidth = 14;
if (zoom < 10) {
bold = true;
textSize = 8;
} else if (zoom < 12) {
bold = true;
textSize = 11;
}
}
}
break;
case 12: {
if (zoom >= 10) {
textColor = 0xFF000000;
textSize = 9;
}
}
break;
case 7: {
wrapWidth = 20;
if (zoom >= 9 && zoom < 11) {
textColor = 0xFF000000;
textSize = 8;
} else if (zoom >= 11 && zoom < 14) {
textColor = 0xFF000000;
textSize = 11;
} else if (zoom >= 14) {
textColor = 0xFF777777;
textSize = 13;
}
}
break;
case 6: {
wrapWidth = 20;
textColor = 0xFF000000;
if (zoom >= 6 && zoom < 9) {
textSize = 8;
} else if (zoom >= 9 && zoom < 11) {
textSize = 11;
} else if (zoom >= 11 && zoom <= 14) {
textSize = 14;
}
}
break;
case 42: {
wrapWidth = 20;
textColor = 0xff9d6c9d;
if (zoom >= 2 && zoom < 4) {
textSize = 8;
} else if (zoom >= 4 && zoom < 7) {
textSize = 10;
}
}
break;
case 43:
case 44: {
wrapWidth = 20;
textColor = 0xff9d6c9d;
if (zoom >= 4 && zoom < 8) {
textSize = 9;
} else if (zoom >= 7 && zoom < 9) {
textSize = 11;
}
}
break;
case 33: {
if (zoom >= 17) {
textSize = 9;
textColor = 0xff444444;
}
}
break;
}
}
break;
}
rc.textColor = textColor;
rc.textSize = textSize;
rc.textMinDistance = textMinDistance;
rc.showTextOnPath = showTextOnPath;
rc.textShield = textShield;
rc.textWrapWidth = wrapWidth;
rc.textHaloRadius = shadowRadius;
rc.textBold = bold;
rc.textDy = dy;
return name;
}
}