Fix poi dialog

This commit is contained in:
Victor Shcherb 2015-07-09 17:57:27 +02:00
parent 83121530a1
commit 177bd52131
7 changed files with 235 additions and 114 deletions

View file

@ -66,7 +66,7 @@ public class BinaryInspector {
// test cases show info
if(args.length == 1 && "test".equals(args[0])) {
in.inspector(new String[]{
// "-vpoi",
"-vpoi",
// "-vmap", "-vmapobjects",
// "-vrouting",
// "-vaddress", "-vcities","-vstreetgroups",
@ -74,7 +74,7 @@ public class BinaryInspector {
// "-zoom=16",
// "-bbox=1.74,51.17,1.75,51.16",
// "-vstats",
"/Users/victorshcherb/osmand/osm-gen/Andorra-latest.origin3.obf"
"/Users/victorshcherb/osmand/osm-gen/Andorra-latest.obf"
});
} else {
in.inspector(args);

View file

@ -4,7 +4,6 @@ import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -12,7 +11,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import net.osmand.Location;

View file

@ -7,17 +7,17 @@ import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import net.osmand.PlatformUtil;
import net.osmand.StringMatcher;
import net.osmand.data.AmenityType;
import net.osmand.osm.MapRenderingTypes.MapRulType;
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.data.Amenity;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -277,37 +277,25 @@ public class MapPoiTypes {
}
lastCategory.addPoiType(tp);
} else if (name.equals("poi_additional")) {
PoiType tp = new PoiType(this, lastCategory, parser.getAttributeValue("", "name"));
tp.setAdditional(lastType != null ? lastType :
(lastFilter != null ? lastFilter : lastCategory));
tp.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top")));
tp.setOsmTag(parser.getAttributeValue("", "tag"));
tp.setOsmValue(parser.getAttributeValue("", "value"));
tp.setOsmTag2(parser.getAttributeValue("", "tag2"));
tp.setOsmValue2(parser.getAttributeValue("", "value2"));
if (lastType != null) {
lastType.addPoiAdditional(tp);
} else if (lastFilter != null) {
lastFilter.addPoiAdditional(tp);
} else if (lastCategory != null) {
lastCategory.addPoiAdditional(tp);
}
} else if (name.equals("poi_type")) {
PoiType tp = new PoiType(this, lastCategory, parser.getAttributeValue("", "name"));
tp.setOsmTag(parser.getAttributeValue("", "tag"));
tp.setOsmValue(parser.getAttributeValue("", "value"));
tp.setOsmTag2(parser.getAttributeValue("", "tag2"));
tp.setOsmValue2(parser.getAttributeValue("", "value2"));
lastType = tp;
if (lastFilter != null) {
lastFilter.addPoiType(tp);
}
allTypes.put(tp.getKeyName(), tp);
if(lastCategory == null) {
lastCategory = getOtherMapCategory();
}
lastCategory.addPoiType(tp);
if("true".equals(parser.getAttributeValue("", "lang"))) {
for(String lng : MapRenderingTypes.langs) {
parsePoiAdditional(parser, lastCategory, lastFilter, lastType, lng);
}
}
parsePoiAdditional(parser, lastCategory, lastFilter, lastType, null);
} else if (name.equals("poi_type")) {
if(lastCategory == null) {
lastCategory = getOtherMapCategory();
}
if("true".equals(parser.getAttributeValue("", "lang"))) {
for(String lng : MapRenderingTypes.langs) {
parsePoiType(allTypes, parser, lastCategory, lastFilter, lng);
}
}
lastType = parsePoiType(allTypes, parser, lastCategory, lastFilter, null);
}
} else if (tok == XmlPullParser.END_TAG) {
String name = parser.getName();
@ -346,6 +334,63 @@ public class MapPoiTypes {
init = true;
log.info("Time to init poi types " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
}
private void parsePoiAdditional(XmlPullParser parser, PoiCategory lastCategory, PoiFilter lastFilter,
PoiType lastType, String lang) {
String oname = parser.getAttributeValue("", "name");
if(lang != null) {
oname += ":" + lang;
}
String otag = parser.getAttributeValue("", "tag");
if(lang != null) {
otag += ":" + lang;
}
PoiType tp = new PoiType(this, lastCategory, oname);
tp.setAdditional(lastType != null ? lastType :
(lastFilter != null ? lastFilter : lastCategory));
tp.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top")));
tp.setText("text".equals(parser.getAttributeValue("", "type")));
tp.setOsmTag(otag);
tp.setOsmValue(parser.getAttributeValue("", "value"));
tp.setOsmTag2(parser.getAttributeValue("", "tag2"));
tp.setOsmValue2(parser.getAttributeValue("", "value2"));
if (lastType != null) {
lastType.addPoiAdditional(tp);
} else if (lastFilter != null) {
lastFilter.addPoiAdditional(tp);
} else if (lastCategory != null) {
lastCategory.addPoiAdditional(tp);
}
}
private PoiType parsePoiType(final Map<String, PoiType> allTypes, XmlPullParser parser, PoiCategory lastCategory,
PoiFilter lastFilter, String lang) {
String oname = parser.getAttributeValue("", "name");
if(lang != null) {
oname += ":" + lang;
}
PoiType tp = new PoiType(this, lastCategory, oname);
String otag = parser.getAttributeValue("", "tag");
if(lang != null) {
otag += ":" + lang;
}
tp.setOsmTag(otag);
tp.setOsmValue(parser.getAttributeValue("", "value"));
tp.setOsmTag2(parser.getAttributeValue("", "tag2"));
tp.setOsmValue2(parser.getAttributeValue("", "value2"));
tp.setText("text".equals(parser.getAttributeValue("", "type")));
tp.setNameOnly("true".equals(parser.getAttributeValue("", "name_only")));
tp.setRelation("relation".equals(parser.getAttributeValue("", "relation")));
tp.setMap("true".equals(parser.getAttributeValue("", "map")));
if (lastFilter != null) {
lastFilter.addPoiType(tp);
}
allTypes.put(tp.getKeyName(), tp);
lastCategory.addPoiType(tp);
return tp;
}
private void findDefaultOtherCategory() {
PoiCategory pc = getPoiCategoryByName("user_defined_other");
@ -452,65 +497,101 @@ public class MapPoiTypes {
}
public Map<String, String> getAmenityAdditionalInfo(Map<String, String> tags, AmenityType type, String subtype) {
TODO;
Map<String, String> map = new LinkedHashMap<String, String>();
for (String tag : tags.keySet()) {
String val = tags.get(tag);
MapRulType rType = getAmenityRuleType(tag, val);
if (rType != null && val != null && val.length() > 0) {
if(rType == nameEnRuleType && Algorithms.objectEquals(val, tags.get(OSMTagKey.NAME))) {
continue;
Map<String, PoiType> poiTypesByTag = new LinkedHashMap<String, PoiType>();
public void initPoiTypesByTag() {
if(!poiTypesByTag.isEmpty()) {
return;
}
for(PoiCategory poic : categories) {
for(PoiType p : poic.getPoiTypes()) {
initPoiType(p);
for(PoiType pts : p.getPoiAdditionals()) {
initPoiType(pts);
}
if (rType.isAdditionalOrText()) {
if (!rType.isText() && !Algorithms.isEmpty(rType.tagValuePattern.value)) {
val = rType.tagValuePattern.value;
}
map.put(rType.tagValuePattern.tag, val);
}
for(PoiType p : poic.getPoiAdditionals()) {
initPoiType(p);
}
}
}
private void initPoiType(PoiType p) {
if(!p.isReference()) {
String key = null;
if(p.isAdditional()) {
key = p.isText() ? p.getOsmTag() :
(p.getOsmTag() + "/" + p.getOsmValue());
} else {
key = p.getOsmTag() + "/" + p.getOsmValue();
}
if(poiTypesByTag.containsKey(key)) {
throw new UnsupportedOperationException("!! Duplicate poi type " + key);
}
poiTypesByTag.put(key, p);
}
}
public Amenity parseAmenity(String tag, String val, boolean relation, Map<String, String> otherTags) {
boolean hasName = !Algorithms.isEmpty(otherTags.get("name"));
initPoiTypesByTag();
PoiType pt = poiTypesByTag.get(tag+"/"+val);
if(pt == null) {
pt = poiTypesByTag.get(tag);
}
if(pt == null || pt.isAdditional()) {
return null;
}
if(!Algorithms.isEmpty(pt.getOsmTag2())) {
if(!Algorithms.objectEquals(otherTags.get(pt.getOsmTag2()), pt.getOsmValue2())) {
return null;
}
}
if(!hasName && pt.isNameOnly()) {
return null;
}
if(relation && !pt.isRelation()) {
return null;
}
Amenity a = new Amenity();
a.setType(pt.getCategory());
a.setSubType(pt.getKeyName());
// additional info
Iterator<Entry<String, String>> it = otherTags.entrySet().iterator();
while(it.hasNext()) {
Entry<String, String> e = it.next();
String otag = e.getKey();
if(!otag.equals(tag)) {
PoiType pat = poiTypesByTag.get(otag+"/"+e.getValue());
if(pat == null) {
pat = poiTypesByTag.get(otag);
}
if(pat != null && pat.isAdditional()) {
a.setAdditionalInfo(pat.getKeyName(), e.getValue());
}
}
}
return map;
return a;
}
public String getAmenitySubtype(String tag, String val){
String prefix = getAmenitySubtypePrefix(tag, val);
if(prefix != null){
return prefix + val;
}
return val;
}
public String getAmenitySubtypePrefix(String tag, String val){
Map<String, MapRulType> rules = getEncodingRuleTypes();
MapRulType rt = rules.get(constructRuleKey(tag, val));
if(rt != null && rt.poiPrefix != null && rt.isPOI()) {
return rt.poiPrefix;
}
rt = rules.get(constructRuleKey(tag, null));
if(rt != null && rt.poiPrefix != null && rt.isPOI()) {
return rt.poiPrefix;
}
return null;
}
public AmenityType getAmenityType(String tag, String val, boolean hasName){
TODO;
return getAmenityType(tag, val, false, hasName);
}
public AmenityType getAmenityTypeForRelation(String tag, String val, boolean hasName){
TODO;
return getAmenityType(tag, val, true, hasName);
}
public boolean isTextAdditionalInfo(String key, String value) {
if(key.startsWith("name:")) {
if(key.startsWith("name:") || key.equals("name")) {
return true;
}
TODO;
return true;
initPoiTypesByTag();
PoiType pat = poiTypesByTag.get(key+"/"+value);
if(pat == null) {
pat = poiTypesByTag.get(key);
}
if(pat == null) {
return true;
} else {
return pat.isText();
}
}
}

View file

@ -31,6 +31,9 @@ import org.xmlpull.v1.XmlPullParserException;
public class MapRenderingTypes {
private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class);
public static final String[] langs = new String[] { "af", "ar", "az", "be", "bg", "bn", "bpy", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "eo", "es", "et", "eu", "id", "fa", "fi", "fr", "fy", "ga", "gl", "he", "hi",
"hr", "ht", "hu", "hy", "is", "it", "ja", "ka", "ko", "ku", "la", "lb", "lt", "lv", "mk", "ml", "mr", "ms", "nds", "new", "nl", "nn", "no", "nv", "os", "pl", "pms", "pt", "ro", "ru", "sc", "sh", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "vi", "vo", "zh" };
public final static byte RESTRICTION_NO_RIGHT_TURN = 1;
public final static byte RESTRICTION_NO_LEFT_TURN = 2;

View file

@ -13,6 +13,11 @@ public class PoiType extends AbstractPoiType {
private String osmValue;
private String osmValue2;
private boolean text;
private boolean map;
private boolean nameOnly;
private boolean relation;
public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name) {
super(name, poiTypes);
@ -106,5 +111,40 @@ public class PoiType extends AbstractPoiType {
public AbstractPoiType getParentType() {
return parentType;
}
public boolean isText() {
return text;
}
public void setText(boolean text) {
this.text = text;
}
public boolean isMap() {
return map;
}
public void setMap(boolean map) {
this.map = map;
}
public boolean isNameOnly() {
return nameOnly;
}
public void setNameOnly(boolean nameOnly) {
this.nameOnly = nameOnly;
}
public boolean isRelation() {
return relation;
}
public void setRelation(boolean relation) {
this.relation = relation;
}
}

View file

@ -145,20 +145,6 @@ public class EntityParser {
return am;
}
public static Amenity parseAmenity(Entity entity, Map<String, String> tagValues, PoiCategory type, String subtype,
MapPoiTypes types) {
Amenity am = new Amenity();
parseMapObject(am, entity, tagValues);
am.setType(type);
am.setSubType(subtype);
AmenityType at = AmenityType.findOrCreateTypeNoReg(type.getKeyName());
am.setAdditionalInfo(types.getAmenityAdditionalInfo(tagValues, at, subtype));
String wbs = getWebSiteURL(tagValues);
if(wbs != null) {
am.setAdditionalInfo("website", wbs);
}
return am;
}
@ -194,16 +180,17 @@ public class EntityParser {
// it could be collection of amenities
boolean relation = entity instanceof Relation;
boolean purerelation = relation && !"multipolygon".equals(tags.get("type"));
boolean hasName = !Algorithms.isEmpty(tags.get("name"));
for (Map.Entry<String, String> e : tags.entrySet()) {
AmenityType type = purerelation ? poiTypes.getAmenityTypeForRelation(e.getKey(), e.getValue(), hasName)
: poiTypes.getAmenityType(e.getKey(), e.getValue(), hasName);
if (type != null) {
String subtype = poiTypes.getAmenitySubtype(e.getKey(), e.getValue());
PoiCategory pc = poiTypes.getPoiCategoryByName(type.getCategoryName(), true);
Amenity a = parseAmenity(entity, tags, pc, subtype, poiTypes);
if (checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)) {
amenitiesList.add(a);
Amenity am = poiTypes.parseAmenity(e.getKey(), e.getValue(), purerelation, tags);
if (am != null) {
parseMapObject(am, entity, tags);
String wbs = getWebSiteURL(tags);
if(wbs != null) {
am.setAdditionalInfo("website", wbs);
}
if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) {
amenitiesList.add(am);
}
}
}

View file

@ -136,7 +136,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
protected void onPostExecute(Node n) {
if(n != null){
showPOIDialog(DIALOG_EDIT_POI, n, editA.getType(), editA.getSubType());
showPOIDialog(DIALOG_EDIT_POI, n, editA);
} else {
AccessibleToast.makeText(activity, activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show();
}
@ -148,12 +148,24 @@ public class EditingPOIDialogProvider implements DialogProvider {
public void showCreateDialog(double latitude, double longitude){
prepareProvider();
Node n = new Node(latitude, longitude, -1);
n.putTag(OSMTagKey.OPENING_HOURS.getValue(), ""); //$NON-NLS-1$
showPOIDialog(DIALOG_CREATE_POI, n, poiTypes.getOtherPoiCategory(), "");
showPOIDialog(DIALOG_CREATE_POI, n, null);
}
private void showPOIDialog(int dialogID, Node n, PoiCategory type, String subType) {
Amenity a = EntityParser.parseAmenity(n, n.getTags(), type, subType, MapRenderingTypes.getDefault());
private void showPOIDialog(int dialogID, Node n, Amenity a) {
Amenity am;
if(a == null) {
am = new Amenity();
am.setType(poiTypes.getOtherPoiCategory());
am.setSubType("");
am.setAdditionalInfo(OSMTagKey.OPENING_HOURS.getValue(), "");
} else {
am = new Amenity();
am.copyNames(a);
am.setType(a.getType());
am.setSubType(a.getSubType());
am.setAdditionalInfo(a.getAdditionalInfo());
}
// Amenity a = EntityParser.parseAmenity(n, n.getTags(), type, subType, MapRenderingTypes.getDefault());
dialogBundle.putSerializable(KEY_AMENITY, a);
dialogBundle.putSerializable(KEY_AMENITY_NODE, n);
createPOIDialog(dialogID, dialogBundle).show();
@ -731,7 +743,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
case DIALOG_POI_TYPES: {
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
Builder builder = new AlertDialog.Builder(activity);
final List<PoiCategory> categories = poiTypes.getCategories(true);
final List<PoiCategory> categories = poiTypes.getCategories(false);
String[] vals = new String[categories.size()];
for (int i = 0; i < vals.length; i++) {
vals[i] = categories.get(i).getTranslation();