refactoring
This commit is contained in:
parent
30c5fda90a
commit
74ffdbeba5
3 changed files with 39 additions and 41 deletions
|
@ -179,26 +179,6 @@ public class Amenity extends MapObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addProfileTag(Entry<String, String> e) {
|
|
||||||
if (getAdditionalInfo("profile") == null) {
|
|
||||||
if (e.getKey().startsWith("tag_")) {
|
|
||||||
switch (e.getValue().trim()) {
|
|
||||||
case "bicycle":
|
|
||||||
case "cycling":
|
|
||||||
case "mtb":
|
|
||||||
setAdditionalInfo("profile", "bicycle");
|
|
||||||
break;
|
|
||||||
case "hiking":
|
|
||||||
case "hike":
|
|
||||||
case "walking":
|
|
||||||
case "walk":
|
|
||||||
setAdditionalInfo("profile", "pedestrian");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toStringEn() {
|
public String toStringEn() {
|
||||||
return super.toStringEn() + ": " + type.getKeyName() + ":" + subType;
|
return super.toStringEn() + ": " + type.getKeyName() + ":" + subType;
|
||||||
|
|
|
@ -922,11 +922,7 @@ public class MapPoiTypes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pat = poiTypesByTag.get(otag);
|
pat = poiTypesByTag.get(otag);
|
||||||
if (pat == null && otag.startsWith("tag_")) {
|
|
||||||
a.addProfileTag(e);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (pat != null && pat.isAdditional()) {
|
if (pat != null && pat.isAdditional()) {
|
||||||
a.setAdditionalInfo(pat.getKeyName(), e.getValue());
|
a.setAdditionalInfo(pat.getKeyName(), e.getValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import net.osmand.osm.edit.Relation.RelationMember;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
public class EntityParser {
|
public class EntityParser {
|
||||||
|
|
||||||
public static void parseMapObject(MapObject mo, Entity e, Map<String, String> tags) {
|
public static void parseMapObject(MapObject mo, Entity e, Map<String, String> tags) {
|
||||||
mo.setId(e.getId());
|
mo.setId(e.getId());
|
||||||
if(mo instanceof Amenity) {
|
if(mo instanceof Amenity) {
|
||||||
|
@ -123,7 +123,7 @@ public class EntityParser {
|
||||||
mo.setName(ref);
|
mo.setName(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setNameFromBrand(MapObject mo, Map<String, String> tags) {
|
private static void setNameFromBrand(MapObject mo, Map<String, String> tags) {
|
||||||
String ref = tags.get(OSMTagKey.BRAND.getValue());
|
String ref = tags.get(OSMTagKey.BRAND.getValue());
|
||||||
if(ref != null){
|
if(ref != null){
|
||||||
|
@ -140,7 +140,7 @@ public class EntityParser {
|
||||||
op += " [" + ref + "]";
|
op += " [" + ref + "]";
|
||||||
mo.setName(op);
|
mo.setName(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String getWebSiteURL(Map<String, String> tagValues, boolean checkWikipedia) {
|
private static String getWebSiteURL(Map<String, String> tagValues, boolean checkWikipedia) {
|
||||||
String siteUrl = null;
|
String siteUrl = null;
|
||||||
|
@ -170,14 +170,14 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
return siteUrl;
|
return siteUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<Amenity> parseAmenities(MapPoiTypes poiTypes, Entity entity, Map<String, String> tags,
|
public static List<Amenity> parseAmenities(MapPoiTypes poiTypes, Entity entity, Map<String, String> tags,
|
||||||
List<Amenity> amenitiesList) {
|
List<Amenity> amenitiesList) {
|
||||||
amenitiesList.clear();
|
amenitiesList.clear();
|
||||||
// it could be collection of amenities
|
// it could be collection of amenities
|
||||||
boolean relation = entity instanceof Relation;
|
boolean relation = entity instanceof Relation;
|
||||||
boolean purerelation = relation &&
|
boolean purerelation = relation &&
|
||||||
!("multipolygon".equals(tags.get("type")) || "boundary".equals(tags.get("type")));
|
!("multipolygon".equals(tags.get("type")) || "boundary".equals(tags.get("type")));
|
||||||
Collection<Map<String, String>> it = MapRenderingTypes.splitTagsIntoDifferentObjects(tags);
|
Collection<Map<String, String>> it = MapRenderingTypes.splitTagsIntoDifferentObjects(tags);
|
||||||
for (Map<String, String> ts : it) {
|
for (Map<String, String> ts : it) {
|
||||||
|
@ -193,6 +193,10 @@ public class EntityParser {
|
||||||
if (wbs != null) {
|
if (wbs != null) {
|
||||||
am.setAdditionalInfo("wikipedia", wbs);
|
am.setAdditionalInfo("wikipedia", wbs);
|
||||||
}
|
}
|
||||||
|
String tagCategory = getTagCategory(entity);
|
||||||
|
if (tagCategory != null) {
|
||||||
|
am.setAdditionalInfo("profile", tagCategory);
|
||||||
|
}
|
||||||
if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) {
|
if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) {
|
||||||
amenitiesList.add(am);
|
amenitiesList.add(am);
|
||||||
}
|
}
|
||||||
|
@ -201,9 +205,27 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
return amenitiesList;
|
return amenitiesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getTagCategory(Entity e) {
|
||||||
|
Map<String, String> tags = e.getTags();
|
||||||
|
for (String key : tags.keySet()) {
|
||||||
|
if (key.startsWith("tag_")) {
|
||||||
|
switch (tags.get(key).trim()) {
|
||||||
|
case "bicycle":
|
||||||
|
case "cycling":
|
||||||
|
case "mtb":
|
||||||
|
return "bicycle";
|
||||||
|
case "hiking":
|
||||||
|
case "hike":
|
||||||
|
case "walking":
|
||||||
|
case "walk":
|
||||||
|
return "pedestrian";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean checkAmenitiesToAdd(Amenity a, List<Amenity> amenitiesList){
|
private static boolean checkAmenitiesToAdd(Amenity a, List<Amenity> amenitiesList){
|
||||||
// check amenity for duplication
|
// check amenity for duplication
|
||||||
for(Amenity b : amenitiesList){
|
for(Amenity b : amenitiesList){
|
||||||
|
@ -212,9 +234,9 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Building parseBuilding(Entity e){
|
public static Building parseBuilding(Entity e){
|
||||||
Building b = new Building();
|
Building b = new Building();
|
||||||
parseMapObject(b, e, e.getTags());
|
parseMapObject(b, e, e.getTags());
|
||||||
|
@ -228,7 +250,7 @@ public class EntityParser {
|
||||||
List<Node> nodes = ((Way) e).getNodes();
|
List<Node> nodes = ((Way) e).getNodes();
|
||||||
for(int i = 0; i < nodes.size(); i++) {
|
for(int i = 0; i < nodes.size(); i++) {
|
||||||
Node node = nodes.get(i);
|
Node node = nodes.get(i);
|
||||||
if(node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) &&
|
if(node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) &&
|
||||||
!Algorithms.isEmpty(node.getTag(OSMTagKey.REF))) {
|
!Algorithms.isEmpty(node.getTag(OSMTagKey.REF))) {
|
||||||
b.addEntrance(node.getTag(OSMTagKey.REF), node.getLatLon());
|
b.addEntrance(node.getTag(OSMTagKey.REF), node.getLatLon());
|
||||||
}
|
}
|
||||||
|
@ -236,11 +258,11 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static City parseCity(Node el) {
|
public static City parseCity(Node el) {
|
||||||
return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE.getValue())));
|
return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE.getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static City parseCity(Entity el, CityType t) {
|
public static City parseCity(Entity el, CityType t) {
|
||||||
if(t == null) {
|
if(t == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -252,15 +274,15 @@ public class EntityParser {
|
||||||
c.setIsin(isin);
|
c.setIsin(isin);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static TransportRoute parserRoute(Relation r, String ref){
|
public static TransportRoute parserRoute(Relation r, String ref){
|
||||||
TransportRoute rt = new TransportRoute();
|
TransportRoute rt = new TransportRoute();
|
||||||
parseMapObject(rt, r, r.getTags());
|
parseMapObject(rt, r, r.getTags());
|
||||||
rt.setRef(ref);
|
rt.setRef(ref);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransportStop parseTransportStop(Entity e){
|
public static TransportStop parseTransportStop(Entity e){
|
||||||
TransportStop st = new TransportStop();
|
TransportStop st = new TransportStop();
|
||||||
parseMapObject(st, e, e.getTags());
|
parseMapObject(st, e, e.getTags());
|
||||||
|
|
Loading…
Reference in a new issue