Initial refactoring for route-road, route-bicycle, etc
This commit is contained in:
parent
4960d9159e
commit
4b5bf45471
1 changed files with 68 additions and 36 deletions
|
@ -13,6 +13,7 @@ import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.osm.MapRenderingTypes.MapRulType;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -153,6 +154,14 @@ public abstract class MapRenderingTypes {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected MapRulType checkOrCreateTextRule(String targetTag) {
|
||||||
|
MapRulType mt = types.get(constructRuleKey(targetTag, null));
|
||||||
|
if (mt == null) {
|
||||||
|
mt = registerRuleType(MapRulType.createText(targetTag));
|
||||||
|
}
|
||||||
|
return mt;
|
||||||
|
}
|
||||||
|
|
||||||
protected MapRulType getRuleType(String tag, String val, boolean poi, boolean map) {
|
protected MapRulType getRuleType(String tag, String val, boolean poi, boolean map) {
|
||||||
Map<String, MapRulType> types = getEncodingRuleTypes();
|
Map<String, MapRulType> types = getEncodingRuleTypes();
|
||||||
tag = lc(tag);
|
tag = lc(tag);
|
||||||
|
@ -171,7 +180,6 @@ public abstract class MapRenderingTypes {
|
||||||
rType.map = parent.map;
|
rType.map = parent.map;
|
||||||
rType.poi = parent.poi;
|
rType.poi = parent.poi;
|
||||||
rType.onlyPoint = parent.onlyPoint;
|
rType.onlyPoint = parent.onlyPoint;
|
||||||
rType.namePrefix = parent.namePrefix;
|
|
||||||
rType = registerRuleType(rType);
|
rType = registerRuleType(rType);
|
||||||
}
|
}
|
||||||
return rType;
|
return rType;
|
||||||
|
@ -264,38 +272,71 @@ public abstract class MapRenderingTypes {
|
||||||
rtype.category = parentCategory == null ? null : parentCategory.category;
|
rtype.category = parentCategory == null ? null : parentCategory.category;
|
||||||
rtype.onlyPoint = Boolean.parseBoolean(parser.getAttributeValue("", "point")); //$NON-NLS-1$
|
rtype.onlyPoint = Boolean.parseBoolean(parser.getAttributeValue("", "point")); //$NON-NLS-1$
|
||||||
rtype.relation = Boolean.parseBoolean(parser.getAttributeValue("", "relation")); //$NON-NLS-1$
|
rtype.relation = Boolean.parseBoolean(parser.getAttributeValue("", "relation")); //$NON-NLS-1$
|
||||||
rtype.relationGroup = Boolean.parseBoolean(parser.getAttributeValue("", "relationGroup")); //$NON-NLS-1$
|
|
||||||
if (rtype.isMain()) {
|
if (rtype.isMain()) {
|
||||||
rtype.namePrefix = parser.getAttributeValue("", "namePrefix"); //$NON-NLS-1$
|
if (rtype.relation) {
|
||||||
if (rtype.namePrefix == null) {
|
MapRulType mrt = MapRulType.createMainEntity(tag + "_" + value, null);
|
||||||
rtype.namePrefix = "";
|
mrt.order = rtype.order;
|
||||||
|
mrt.category = rtype.category;
|
||||||
|
mrt.poi = rtype.poi;
|
||||||
|
mrt.map = rtype.map;
|
||||||
|
registerMapRule(parser, mrt);
|
||||||
}
|
}
|
||||||
|
String nmts = parser.getAttributeValue("", "nameTags");
|
||||||
String v = parser.getAttributeValue("", "nameTags");
|
if(nmts != null) {
|
||||||
if (v != null) {
|
String namePrefix = parser.getAttributeValue("", "namePrefix"); //$NON-NLS-1$
|
||||||
String[] names = v.split(",");
|
if (namePrefix == null) {
|
||||||
rtype.names = new MapRulType[names.length * (langs.length + 1)];
|
namePrefix = "";
|
||||||
int j = 0;
|
|
||||||
for (int i = 0; i < names.length; i++) {
|
|
||||||
String tagName = names[i];
|
|
||||||
if (rtype.namePrefix.length() > 0) {
|
|
||||||
tagName = rtype.namePrefix + tagName;
|
|
||||||
}
|
|
||||||
MapRulType mt = MapRulType.createText(tagName);
|
|
||||||
mt = registerRuleType(mt);
|
|
||||||
rtype.names[j++] = mt;
|
|
||||||
for(String lng : langs) {
|
|
||||||
mt = MapRulType.createText(tagName + ":" + lng);
|
|
||||||
mt = registerRuleType(mt);
|
|
||||||
rtype.names[j++] = mt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
rtype.relationNames = new LinkedHashMap<String, String>();
|
||||||
|
putNameTags(nmts, rtype.relationNames, namePrefix);
|
||||||
|
}
|
||||||
|
String rnmts = parser.getAttributeValue("", "relationGroupNameTags");
|
||||||
|
if (rnmts != null) {
|
||||||
|
String relationGroupNamePrefix = parser.getAttributeValue("", "relationGroupNamePrefix"); //$NON-NLS-1$
|
||||||
|
if (relationGroupNamePrefix == null) {
|
||||||
|
relationGroupNamePrefix = "";
|
||||||
|
}
|
||||||
|
rtype.relationGroupNameTags = new LinkedHashMap<String, String>();
|
||||||
|
putNameTags(rnmts, rtype.relationGroupNameTags, relationGroupNamePrefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rtype;
|
return rtype;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putNameTags(String namesList, Map<String, String> names, String namePrefix) {
|
||||||
|
if (namesList != null) {
|
||||||
|
String[] nameSplit = namesList.split(",");
|
||||||
|
for (int i = 0; i < nameSplit.length; i++) {
|
||||||
|
String tagName = nameSplit[i];
|
||||||
|
String tagTargetName = tagName;
|
||||||
|
if (namePrefix.length() > 0) {
|
||||||
|
tagTargetName = namePrefix + tagName;
|
||||||
|
}
|
||||||
|
names.put(tagName, tagTargetName);
|
||||||
|
for (String lng : langs) {
|
||||||
|
names.put(tagName + ":" + lng, tagTargetName + ":" + lng);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerMapRule(XmlPullParser parser, MapRulType rtype) {
|
||||||
|
String val = parser.getAttributeValue("", "minzoom"); //$NON-NLS-1$
|
||||||
|
if (rtype.isMain()) {
|
||||||
|
rtype.minzoom = 15;
|
||||||
|
}
|
||||||
|
if (val != null) {
|
||||||
|
rtype.minzoom = Integer.parseInt(val);
|
||||||
|
}
|
||||||
|
val = parser.getAttributeValue("", "maxzoom"); //$NON-NLS-1$
|
||||||
|
rtype.maxzoom = 31;
|
||||||
|
if (val != null) {
|
||||||
|
rtype.maxzoom = Integer.parseInt(val);
|
||||||
|
}
|
||||||
|
registerRuleType(rtype);
|
||||||
|
}
|
||||||
|
|
||||||
protected MapRulType registerRuleType(MapRulType rt) {
|
protected MapRulType registerRuleType(MapRulType rt) {
|
||||||
String tag = rt.tagValuePattern.tag;
|
String tag = rt.tagValuePattern.tag;
|
||||||
String val = rt.tagValuePattern.value;
|
String val = rt.tagValuePattern.value;
|
||||||
|
@ -422,7 +463,8 @@ public abstract class MapRenderingTypes {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MapRulType {
|
public static class MapRulType {
|
||||||
protected MapRulType[] names;
|
protected Map<String, String> relationNames;
|
||||||
|
protected Map<String, String> relationGroupNameTags;
|
||||||
protected TagValuePattern tagValuePattern;
|
protected TagValuePattern tagValuePattern;
|
||||||
protected boolean additional;
|
protected boolean additional;
|
||||||
protected boolean additionalText;
|
protected boolean additionalText;
|
||||||
|
@ -431,7 +473,6 @@ public abstract class MapRenderingTypes {
|
||||||
|
|
||||||
protected String category = null;
|
protected String category = null;
|
||||||
protected boolean relation;
|
protected boolean relation;
|
||||||
protected boolean relationGroup;
|
|
||||||
// creation of only section
|
// creation of only section
|
||||||
protected boolean map = true;
|
protected boolean map = true;
|
||||||
protected boolean poi = true;
|
protected boolean poi = true;
|
||||||
|
@ -440,7 +481,6 @@ public abstract class MapRenderingTypes {
|
||||||
protected int minzoom;
|
protected int minzoom;
|
||||||
protected int maxzoom;
|
protected int maxzoom;
|
||||||
protected boolean onlyPoint;
|
protected boolean onlyPoint;
|
||||||
protected String namePrefix ="";
|
|
||||||
|
|
||||||
|
|
||||||
// inner id
|
// inner id
|
||||||
|
@ -549,14 +589,6 @@ public abstract class MapRenderingTypes {
|
||||||
return onlyPoint;
|
return onlyPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRelation() {
|
|
||||||
return relation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRelationGroup() {
|
|
||||||
return relationGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getFreq() {
|
public int getFreq() {
|
||||||
return freq;
|
return freq;
|
||||||
|
|
Loading…
Reference in a new issue