implement ordering for xml renderer

git-svn-id: https://osmand.googlecode.com/svn/trunk@684 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-11-21 22:53:31 +00:00
parent f02c68e6f9
commit 5838309ea3
6 changed files with 262 additions and 101 deletions

View file

@ -393,6 +393,17 @@ public class MapRenderingTypes {
return (3 & (type >> 12));
}
// 0 - normal, -1 - under, 1 - bridge,over
public static int getNegativeWayLayer(int type) {
int i = (3 & (type >> 12));
if (i == 1) {
return -1;
} else if (i == 2) {
return 1;
}
return 0;
}
// HIGHWAY special attributes :
// o/oneway 1 bit
// f/free toll 1 bit

View file

@ -57,6 +57,8 @@ public class OsmandRenderingRulesParser {
public String val = null;
public int layer = 0;
public int textLength = 0;
public float order = 0;
public int orderType = -1;
public String shader = null;
@ -94,6 +96,7 @@ public class OsmandRenderingRulesParser {
public final static int POLYGON_STATE = 2;
public final static int LINE_STATE = 3;
public final static int TEXT_STATE = 4;
public final static int ORDER_STATE = 5;
public void parseRenderingRules(InputStream is, RenderingRuleVisitor visitor) throws IOException, SAXException {
try {
@ -123,6 +126,8 @@ public class OsmandRenderingRulesParser {
if("filter".equals(name)){ //$NON-NLS-1$
FilterState st = parseFilterAttributes(attributes);
stack.push(st);
} else if("order".equals(name)){ //$NON-NLS-1$
state = ORDER_STATE;
} else if("text".equals(name)){ //$NON-NLS-1$
state = TEXT_STATE;
} else if("point".equals(name)){ //$NON-NLS-1$
@ -150,7 +155,7 @@ public class OsmandRenderingRulesParser {
if ("filter".equals(name)) { //$NON-NLS-1$
List<FilterState> list = popAndAggregateState();
for (FilterState pop : list) {
if (pop.tag != null && pop.minzoom != -1) {
if (pop.tag != null && (pop.minzoom != -1 || state == ORDER_STATE)) {
visitor.visitRule(state, pop);
}
}
@ -215,9 +220,15 @@ public class OsmandRenderingRulesParser {
if(toMerge.tag != null && mergeInto.tag == null){
mergeInto.tag = toMerge.tag;
}
if(toMerge.orderType != -1 && mergeInto.orderType == -1){
mergeInto.orderType = toMerge.orderType;
}
if(toMerge.layer != 0 && mergeInto.layer == 0){
mergeInto.layer = toMerge.layer;
}
if(toMerge.order != 0 && mergeInto.order == 0){
mergeInto.order = toMerge.order;
}
if(toMerge.textLength != 0 && mergeInto.textLength == 0){
mergeInto.textLength = toMerge.textLength;
}
@ -315,6 +326,11 @@ public class OsmandRenderingRulesParser {
state.maxzoom = Integer.parseInt(val);
} else if(name.equals("layer")){ //$NON-NLS-1$
state.layer = Integer.parseInt(val);
} else if(name.equals("orderType")){ //$NON-NLS-1$
int i1 = val.equals("polygon") ? 3 : (val.equals("line") ? 2 : 1); //$NON-NLS-1$ //$NON-NLS-2$
state.orderType = i1;
} else if(name.equals("order")){ //$NON-NLS-1$
state.order = Float.parseFloat(val);
} else if(name.equals("icon")){ //$NON-NLS-1$
state.icon = val;
} else if(name.equals("color")){ //$NON-NLS-1$
@ -457,10 +473,18 @@ public class OsmandRenderingRulesParser {
res+= " icon="+s.icon; //$NON-NLS-1$
}
res = generateAttributes(s.main, res, "");
if(s.order != 0){
res+= " order="+s.order; //$NON-NLS-1$
}
if(s.orderType != 0){
res+= " orderType="+s.orderType; //$NON-NLS-1$
}
res = generateAttributes(s.main, res, ""); //$NON-NLS-1$
int p = 2;
for(EffectAttributes ef : s.effectAttributes){
res = generateAttributes(ef, res, "_"+(p++));
res = generateAttributes(ef, res, "_"+(p++)); //$NON-NLS-1$
}
if(s.text != null){
if(s.text.textSize != 0){
@ -481,11 +505,13 @@ public class OsmandRenderingRulesParser {
if(state == POLYGON_STATE){
// return res;
} else if(state == LINE_STATE){
return res;
// return res;
} else if(state == POINT_STATE){
// return res;
} else if(state == TEXT_STATE){
// return res;
} else if(state == ORDER_STATE){
return res;
}
return null;
}
@ -493,13 +519,13 @@ public class OsmandRenderingRulesParser {
private static String generateAttributes(EffectAttributes s, String res, String prefix) {
if(s.color != 0){
res +=" color"+prefix+"="+colorToString(s.color); //$NON-NLS-1$
res +=" color"+prefix+"="+colorToString(s.color); //$NON-NLS-1$ //$NON-NLS-2$
}
if(s.strokeWidth != 0){
res+= " strokeWidth"+prefix+"="+s.strokeWidth; //$NON-NLS-1$
res+= " strokeWidth"+prefix+"="+s.strokeWidth; //$NON-NLS-1$ //$NON-NLS-2$
}
if(s.pathEffect != null){
res+= " pathEffect"+prefix+"="+s.pathEffect; //$NON-NLS-1$
res+= " pathEffect"+prefix+"="+s.pathEffect; //$NON-NLS-1$ //$NON-NLS-2$
}
return res;
}

View file

@ -9,76 +9,144 @@
shop_supermarket, sosphone, spring station_small, station, telephone, theatre, toilets, tower_water, traffic_light transport_ford, tree,
tree2, view_point, vineyard, windmill, zoo
-->
<!-- TODO oneway!!! -->
<!-- input exact layer, orderType check tag, value -->
<order>
<!-- point has order 128 -->
<filter orderType="polygon">
<filter tag="" layer="-1" order="0.5" />
<filter tag="" layer="1" order="64" />
<filter tag="" order="1" />
<filter tag="building" order="64" />
<filter tag="building" layer="-1" order="2" />
<filter tag="landuse" order="1" />
<filter tag="landuse" value="reservoir" order="5" />
<filter tag="landuse" value="water" order="5" />
<filter tag="natural" value="water" order="5" />
<filter tag="waterway" order="5" />
<filter tag="leisure" order="2" />
<filter tag="leisure" value="pitch" order="4" />
<filter tag="power" order="4" />
<filter tag="natural" value="coastline" order="0.5" />
<filter tag="natural" order="1" />
</filter>
<filter orderType="line">
<filter tag="" layer="-1" order="10" />
<filter tag="" order="11" />
<filter tag="" layer="1" order="67" />
<filter tag="railway" layer="-1" order="58" />
<filter tag="railway" order="58" />
<!-- over buildings -->
<filter tag="aerialway" order="68" />
<filter tag="power" order="68" />
<filter tag="administrative" order="62" />
<filter tag="waterway" order="18" />
<filter tag="highway" value="motorway" order="57" />
<filter tag="highway" value="trunk" order="56" />
<filter tag="highway" value="primary" order="55" />
<filter tag="highway" value="secondary" order="54" />
<filter tag="highway" value="tertiary" order="53" />
<filter tag="highway" value="residential" order="52" />
<filter tag="highway" value="service" order="52" />
<filter tag="highway" value="unclassified" order="51" />
<filter tag="highway" value="road" order="51" />
<filter tag="highway" value="track" order="50" />
<filter tag="highway" value="path" order="48" />
<filter tag="highway" value="living_street" order="47" />
<filter tag="highway" value="construction" order="46" />
<filter tag="highway" value="proposed" order="45" />
<filter tag="highway" value="motorway_link" order="44" />
<filter tag="highway" value="trunk_link" order="43" />
<filter tag="highway" value="primary_link" order="42" />
<filter tag="highway" value="secondary_link" order="41" />
<filter tag="highway" value="pedestrian" order="40" />
<filter tag="highway" value="cycleway" order="39" />
<filter tag="highway" value="byway" order="38" />
<filter tag="highway" value="footway" order="37" />
<filter tag="highway" value="steps" order="36" />
<filter tag="highway" value="bridleway" order="35" />
</filter>
</order>
<!-- 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">
<filter textLength="1" textShield="tru_shield1"/>
<filter textLength="2" textShield="tru_shield2"/>
<filter textLength="3" textShield="tru_shield3"/>
<filter textLength="4" textShield="tru_shield4"/>
<filter textLength="5" textShield="tru_shield5"/>
<filter textLength="6" textShield="tru_shield6"/>
<filter textLength="1" textShield="tru_shield1" />
<filter textLength="2" textShield="tru_shield2" />
<filter textLength="3" textShield="tru_shield3" />
<filter textLength="4" textShield="tru_shield4" />
<filter textLength="5" textShield="tru_shield5" />
<filter textLength="6" textShield="tru_shield6" />
</filter>
<filter minzoom="10" tag="highway" value="motorway" ref="only" textMinDistance="70" textColor="#ffffff" textSize="10" textBold="true">
<filter textLength="1" textShield="mot_shield1"/>
<filter textLength="2" textShield="mot_shield2"/>
<filter textLength="3" textShield="mot_shield3"/>
<filter textLength="4" textShield="mot_shield4"/>
<filter textLength="5" textShield="mot_shield5"/>
<filter textLength="6" textShield="mot_shield6"/>
<filter textLength="1" textShield="mot_shield1" />
<filter textLength="2" textShield="mot_shield2" />
<filter textLength="3" textShield="mot_shield3" />
<filter textLength="4" textShield="mot_shield4" />
<filter textLength="5" textShield="mot_shield5" />
<filter textLength="6" textShield="mot_shield6" />
</filter>
<filter minzoom="11" tag="highway" value="primary" ref="only" textMinDistance="70" textColor="#ffffff" textSize="10" textBold="true">
<filter textLength="1" textShield="pri_shield1"/>
<filter textLength="2" textShield="pri_shield2"/>
<filter textLength="3" textShield="pri_shield3"/>
<filter textLength="4" textShield="pri_shield4"/>
<filter textLength="5" textShield="pri_shield5"/>
<filter textLength="6" textShield="pri_shield6"/>
<filter textLength="1" textShield="pri_shield1" />
<filter textLength="2" textShield="pri_shield2" />
<filter textLength="3" textShield="pri_shield3" />
<filter textLength="4" textShield="pri_shield4" />
<filter textLength="5" textShield="pri_shield5" />
<filter textLength="6" textShield="pri_shield6" />
</filter>
<filter minzoom="14" tag="highway" value="secondary" ref="only" textMinDistance="70" textColor="#ffffff" textSize="10" textBold="true">
<filter textLength="1" textShield="sec_shield1"/>
<filter textLength="2" textShield="sec_shield2"/>
<filter textLength="3" textShield="sec_shield3"/>
<filter textLength="4" textShield="sec_shield4"/>
<filter textLength="5" textShield="sec_shield5"/>
<filter textLength="6" textShield="sec_shield6"/>
<filter textLength="1" textShield="sec_shield1" />
<filter textLength="2" textShield="sec_shield2" />
<filter textLength="3" textShield="sec_shield3" />
<filter textLength="4" textShield="sec_shield4" />
<filter textLength="5" textShield="sec_shield5" />
<filter textLength="6" textShield="sec_shield6" />
</filter>
<filter minzoom="15" tag="highway" value="tertiary" ref="only" textMinDistance="70" textColor="#ffffff" textSize="10" textBold="true">
<filter textLength="1" textShield="ter_shield1"/>
<filter textLength="2" textShield="ter_shield2"/>
<filter textLength="3" textShield="ter_shield3"/>
<filter textLength="4" textShield="ter_shield4"/>
<filter textLength="5" textShield="ter_shield5"/>
<filter textLength="6" textShield="ter_shield6"/>
<filter textLength="1" textShield="ter_shield1" />
<filter textLength="2" textShield="ter_shield2" />
<filter textLength="3" textShield="ter_shield3" />
<filter textLength="4" textShield="ter_shield4" />
<filter textLength="5" textShield="ter_shield5" />
<filter textLength="6" textShield="ter_shield6" />
</filter>
<!-- Highway text -->
<filter minzoom="16" textSize="9" textOnPath="true" tag="highway" value="motorway" />
<filter minzoom="16" textSize="9" textOnPath="true" tag="highway" value="motorway_link" />
<switch>
<case tag="highway" value="trunk"/>
<case tag="highway" value="trunk_link"/>
<case tag="highway" value="primary"/>
<case tag="highway" value="primary_link"/>
<case tag="highway" value="secondary"/>
<case tag="highway" value="secondary_link"/>
<case tag="highway" value="trunk" />
<case tag="highway" value="trunk_link" />
<case tag="highway" value="primary" />
<case tag="highway" value="primary_link" />
<case tag="highway" value="secondary" />
<case tag="highway" value="secondary_link" />
<filter>
<filter minzoom="13" maxzoom="13" textSize="8" textOnPath="true" />
<filter minzoom="14" maxzoom="14" textSize="9" textOnPath="true" />
<filter minzoom="15" maxzoom="16" textSize="10" textOnPath="true" />
<filter minzoom="17" textSize="12" textOnPath="true"/>
<filter minzoom="17" textSize="12" textOnPath="true" />
</filter>
</switch>
<filter minzoom="15" maxzoom="16" textSize="9" textOnPath="true" tag="highway" value="tertiary" />
<filter minzoom="17" textSize="11" textOnPath="true" tag="highway" value="tertiary" />
<filter minzoom="15" maxzoom="16" textSize="9" textOnPath="true" tag="highway" value="residential" />
@ -89,7 +157,7 @@
<filter minzoom="17" textSize="11" textOnPath="true" tag="highway" value="unclassified" />
<filter minzoom="15" maxzoom="16" textSize="9" textOnPath="true" tag="highway" value="road" />
<filter minzoom="17" textSize="11" textOnPath="true" tag="highway" value="road" />
<filter minzoom="16" textSize="9" textOnPath="true" tag="highway" value="track" />
<filter minzoom="16" textSize="9" textOnPath="true" tag="highway" value="path" />
<filter minzoom="16" textSize="9" textOnPath="true" tag="highway" value="living_street" />

View file

@ -28,7 +28,7 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
private static final Log log = LogUtil.getLog(BaseOsmandRender.class);
@SuppressWarnings("unchecked")
private Map<String, Map<String, List<FilterState>>>[] rules = new LinkedHashMap[5];
private Map<String, Map<String, List<FilterState>>>[] rules = new LinkedHashMap[6];
private static BaseOsmandRender defaultRender = null;
@ -63,10 +63,13 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
@Override
public void visitRule(int state, FilterState filter) {
boolean accept = filter.minzoom != -1;
boolean accept = filter.minzoom != -1 || state == OsmandRenderingRulesParser.ORDER_STATE;
if(state == OsmandRenderingRulesParser.POINT_STATE){
accept &= RenderingIcons.getIcons().containsKey(filter.icon);
}
if(state == OsmandRenderingRulesParser.ORDER_STATE){
accept &= filter.order != 0 && filter.orderType != 0;
}
if (accept) {
if (rules[state] == null) {
rules[state] = new LinkedHashMap<String, Map<String, List<FilterState>>>();
@ -88,6 +91,46 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
}
return i;
}
// type
public float getObjectOrder(String tag, String val, int type, int layer) {
if(type == 0){
// replace multipolygon with polygon
type = 3;
}
float f = getObjectOrderImpl(tag, val, type, layer);
if (f == 0) {
f = getObjectOrderImpl(tag, null, type, layer);
}
if (f == 0) {
f = getObjectOrderImpl("", null, type, layer); //$NON-NLS-1$
}
if (f == 0) {
if (type == 0 || type == 3) {
return 1f;
} else if (type == 1) {
return 128f;
} else {
return 35f;
}
}
return f;
}
private float getObjectOrderImpl(String tag, String val, int type, int layer) {
Map<String, List<FilterState>> map = rules[OsmandRenderingRulesParser.ORDER_STATE].get(tag);
if (map != null) {
List<FilterState> list = map.get(val);
if (list != null) {
for (FilterState f : list) {
if(f.orderType == type && f.layer == layer){
return f.order;
}
}
}
}
return 0;
}
private Integer getPointIconImpl(String tag, String val, int zoom) {
Map<String, List<FilterState>> map = rules[OsmandRenderingRulesParser.POINT_STATE].get(tag);

View file

@ -277,17 +277,30 @@ public class OsmandRenderer {
int sz = objects.size();
int init = sz / 4;
TFloatObjectHashMap<TIntArrayList> orderMap = new TFloatObjectHashMap<TIntArrayList>();
// TreeMap<Float, TIntArrayList> orderMap = new TreeMap<Float, TIntArrayList>();
for (int i = 0; i < sz; i++) {
BinaryMapDataObject o = objects.get(i);
int sh = i << 8;
for (int j = 0; j < o.getTypes().length; j++) {
put(orderMap, BinaryMapDataObject.getOrder(o.getTypes()[j]), sh + j, init);
}
if(rc.interrupted){
return null;
if (render != null) {
for (int i = 0; i < sz; i++) {
BinaryMapDataObject o = objects.get(i);
int sh = i << 8;
for (int j = 0; j < o.getTypes().length; j++) {
// put(orderMap, BinaryMapDataObject.getOrder(o.getTypes()[j]), sh + j, init);
int wholeType = o.getTypes()[j];
int mask = wholeType & 3;
int layer = 0;
if(mask != 1){
layer = MapRenderingTypes.getNegativeWayLayer(wholeType);
}
TagValuePair pair = o.getMapIndex().decodeType(MapRenderingTypes.getMainObjectType(wholeType),
MapRenderingTypes.getObjectSubType(wholeType));
if(pair != null){
put(orderMap, render.getObjectOrder(pair.tag, pair.value, mask, layer), sh + j, init);
}
}
if (rc.interrupted) {
return null;
}
}
}

View file

@ -247,21 +247,21 @@ public class CommandPlayer {
public static final String A_RIGHT_SH = "right_sh"; //$NON-NLS-1$
public static final String A_RIGHT_SL = "right_sl"; //$NON-NLS-1$
protected static final String С_PREPARE_TURN = "prepare_turn"; //$NON-NLS-1$
protected static final String С_PREPARE_ROUNDABOUT = "prepare_roundabout"; //$NON-NLS-1$
protected static final String С_PREPARE_MAKE_UT = "prepare_make_ut"; //$NON-NLS-1$
protected static final String С_ROUNDABOUT = "roundabout"; //$NON-NLS-1$
protected static final String С_GO_AHEAD = "go_ahead"; //$NON-NLS-1$
protected static final String С_TURN = "turn"; //$NON-NLS-1$
protected static final String С_MAKE_UT = "make_ut"; //$NON-NLS-1$
protected static final String С_PREAMBLE = "preamble"; //$NON-NLS-1$
protected static final String С_AND_ARRIVE_DESTINATION = "and_arrive_destination"; //$NON-NLS-1$
protected static final String С_THEN = "then"; //$NON-NLS-1$
protected static final String С_REACHED_DESTINATION = "reached_destination"; //$NON-NLS-1$
protected static final String С_BEAR_LEFT = "bear_left"; //$NON-NLS-1$
protected static final String С_BEAR_RIGHT = "bear_right"; //$NON-NLS-1$
protected static final String С_ROUTE_RECALC = "route_recalc"; //$NON-NLS-1$
protected static final String С_ROUTE_NEW_CALC = "route_new_calc"; //$NON-NLS-1$
protected static final String C_PREPARE_TURN = "prepare_turn"; //$NON-NLS-1$
protected static final String C_PREPARE_ROUNDABOUT = "prepare_roundabout"; //$NON-NLS-1$
protected static final String C_PREPARE_MAKE_UT = "prepare_make_ut"; //$NON-NLS-1$
protected static final String C_ROUNDABOUT = "roundabout"; //$NON-NLS-1$
protected static final String C_GO_AHEAD = "go_ahead"; //$NON-NLS-1$
protected static final String C_TURN = "turn"; //$NON-NLS-1$
protected static final String C_MAKE_UT = "make_ut"; //$NON-NLS-1$
protected static final String C_PREAMBLE = "preamble"; //$NON-NLS-1$
protected static final String C_AND_ARRIVE_DESTINATION = "and_arrive_destination"; //$NON-NLS-1$
protected static final String C_THEN = "then"; //$NON-NLS-1$
protected static final String C_REACHED_DESTINATION = "reached_destination"; //$NON-NLS-1$
protected static final String C_BEAR_LEFT = "bear_left"; //$NON-NLS-1$
protected static final String C_BEAR_RIGHT = "bear_right"; //$NON-NLS-1$
protected static final String C_ROUTE_RECALC = "route_recalc"; //$NON-NLS-1$
protected static final String C_ROUTE_NEW_CALC = "route_new_calc"; //$NON-NLS-1$
protected static final String DELAY_CONST = "delay_"; //$NON-NLS-1$
@ -278,7 +278,7 @@ public class CommandPlayer {
public CommandBuilder(boolean preamble) {
if (preamble) {
addCommand(С_PREAMBLE);
addCommand(C_PREAMBLE);
}
}
@ -320,32 +320,32 @@ public class CommandPlayer {
public CommandBuilder goAhead(){
return addCommand(С_GO_AHEAD);
return addCommand(C_GO_AHEAD);
}
public CommandBuilder goAhead(double dist){
return addCommand(С_GO_AHEAD, dist);
return addCommand(C_GO_AHEAD, dist);
}
public CommandBuilder makeUT(){
return addCommand(С_MAKE_UT);
return addCommand(C_MAKE_UT);
}
public CommandBuilder makeUT(double dist){
return addCommand(С_MAKE_UT, dist);
return addCommand(C_MAKE_UT, dist);
}
public CommandBuilder prepareMakeUT(double dist){
return addCommand(С_PREPARE_MAKE_UT, dist);
return addCommand(C_PREPARE_MAKE_UT, dist);
}
public CommandBuilder turn(String param){
return addCommand(С_TURN, param);
return addCommand(C_TURN, param);
}
public CommandBuilder turn(String param, double dist){
return addCommand(С_TURN, param, dist);
return addCommand(C_TURN, param, dist);
}
/**
@ -355,47 +355,47 @@ public class CommandPlayer {
* @return
*/
public CommandBuilder prepareTurn(String param, double dist){
return addCommand(С_PREPARE_TURN, param, dist);
return addCommand(C_PREPARE_TURN, param, dist);
}
public CommandBuilder prepareRoundAbout(double dist){
return addCommand(С_PREPARE_ROUNDABOUT, dist);
return addCommand(C_PREPARE_ROUNDABOUT, dist);
}
public CommandBuilder roundAbout(double dist, double angle, int exit){
return addCommand(С_ROUNDABOUT, dist, angle, exit);
return addCommand(C_ROUNDABOUT, dist, angle, exit);
}
public CommandBuilder roundAbout(double angle, int exit){
return addCommand(С_ROUNDABOUT, angle, exit);
return addCommand(C_ROUNDABOUT, angle, exit);
}
public CommandBuilder andArriveAtDestination(){
return addCommand(С_AND_ARRIVE_DESTINATION);
return addCommand(C_AND_ARRIVE_DESTINATION);
}
public CommandBuilder arrivedAtDestination(){
return addCommand(С_REACHED_DESTINATION);
return addCommand(C_REACHED_DESTINATION);
}
public CommandBuilder bearLeft(){
return addCommand(С_BEAR_LEFT);
return addCommand(C_BEAR_LEFT);
}
public CommandBuilder bearRight(){
return addCommand(С_BEAR_RIGHT);
return addCommand(C_BEAR_RIGHT);
}
public CommandBuilder then(){
return addCommand(С_THEN);
return addCommand(C_THEN);
}
public CommandBuilder newRouteCalculated(double dist){
return addCommand(С_ROUTE_NEW_CALC, dist);
return addCommand(C_ROUTE_NEW_CALC, dist);
}
public CommandBuilder routeRecalculated(double dist){
return addCommand(С_ROUTE_RECALC, dist);
return addCommand(C_ROUTE_RECALC, dist);
}