From ab2707ba58abcf62d6180c3f5e62838fea33067e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 7 Nov 2015 22:57:29 +0100 Subject: [PATCH] Add support name tag --- .../src/net/osmand/osm/MapPoiTypes.java | 30 ++++++++++++------- OsmAnd-java/src/net/osmand/osm/PoiType.java | 9 ++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index 4b77f80a08..790bbb5b2b 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -1,14 +1,5 @@ package net.osmand.osm; -import net.osmand.PlatformUtil; -import net.osmand.StringMatcher; -import net.osmand.data.Amenity; -import net.osmand.util.Algorithms; - -import org.apache.commons.logging.Log; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -25,6 +16,15 @@ 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.Amenity; +import net.osmand.util.Algorithms; + +import org.apache.commons.logging.Log; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + public class MapPoiTypes { private static MapPoiTypes DEFAULT_INSTANCE = null; @@ -389,6 +389,7 @@ public class MapPoiTypes { tp.setOsmValue2(parser.getAttributeValue("", "value2")); tp.setText("text".equals(parser.getAttributeValue("", "type"))); tp.setNameOnly("true".equals(parser.getAttributeValue("", "name_only"))); + tp.setNameTag(parser.getAttributeValue("", "name_tag")); tp.setRelation("true".equals(parser.getAttributeValue("", "relation"))); if (lastFilter != null) { lastFilter.addPoiType(tp); @@ -544,7 +545,8 @@ public class MapPoiTypes { public Amenity parseAmenity(String tag, String val, boolean relation, Map otherTags) { - boolean hasName = !Algorithms.isEmpty(otherTags.get("name")); + + initPoiTypesByTag(); PoiType pt = poiTypesByTag.get(tag+"/"+val); if(pt == null) { @@ -561,6 +563,11 @@ public class MapPoiTypes { if(pt.getCategory() == getOtherMapCategory()) { return null; } + String nameValue = otherTags.get("name"); + if(pt.getNameTag() != null) { + nameValue = otherTags.get(pt.getNameTag()); + } + boolean hasName = !Algorithms.isEmpty(nameValue); if(!hasName && pt.isNameOnly()) { return null; } @@ -571,6 +578,9 @@ public class MapPoiTypes { Amenity a = new Amenity(); a.setType(pt.getCategory()); a.setSubType(pt.getKeyName()); + if(pt.getNameTag() != null) { + a.setName(nameValue); + } // additional info Iterator> it = otherTags.entrySet().iterator(); while(it.hasNext()) { diff --git a/OsmAnd-java/src/net/osmand/osm/PoiType.java b/OsmAnd-java/src/net/osmand/osm/PoiType.java index a28be242e6..505e7f54bd 100644 --- a/OsmAnd-java/src/net/osmand/osm/PoiType.java +++ b/OsmAnd-java/src/net/osmand/osm/PoiType.java @@ -13,6 +13,7 @@ public class PoiType extends AbstractPoiType { private String osmValue; private String osmValue2; + private String nameTag; private boolean text; private boolean nameOnly; private boolean relation; @@ -118,6 +119,14 @@ public class PoiType extends AbstractPoiType { public void setText(boolean text) { this.text = text; } + + public String getNameTag() { + return nameTag; + } + + public void setNameTag(String nameTag) { + this.nameTag = nameTag; + } public boolean isNameOnly() { return nameOnly;