diff --git a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java index e6f953f9fb..1e346002a5 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; @@ -132,8 +133,90 @@ public class MapRenderingTypes { return amenityTypeNameToTagVal; } + public Iterator> splitTagsIntoDifferentObjects(final Map tags) { + // check open sea maps tags + boolean seamark = false; + for(String s : tags.keySet()) { + if(s.startsWith("seamark:")) { + seamark = true; + break; + } + } + if(!seamark) { + return oneIterator(tags); + } else + return splitOpenSeaMapsTags(tags); + + + } + + private Iterator oneIterator(final T obj) { + return new Iterator() { + boolean hasNext = true; + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + @Override + public T next() { + hasNext = false; + return obj; + } + + @Override + public boolean hasNext() { + return hasNext; + } + }; + } + + private Iterator> splitOpenSeaMapsTags(final Map tags) { + Map> groupByOpenSeamaps = new HashMap>(); + Map common = new HashMap(); + String ATTACHED_KEY = "seamark:attached"; + String type = ""; + for (String s : tags.keySet()) { + String value = tags.get(s); + if (s.equals("seamark:type")) { + type = value; + common.put(ATTACHED_KEY, openSeaType(value)); + } else if (s.startsWith("seamark:")) { + String stype = s.substring("seamark:".length()); + int ind = stype.indexOf(':'); + if (ind == -1) { + common.put(s, value); + } else { + String group = openSeaType(stype.substring(0, ind)); + String add = stype.substring(ind + 1); + if (!groupByOpenSeamaps.containsKey(group)) { + groupByOpenSeamaps.put(group, new HashMap()); + } + groupByOpenSeamaps.get(group).put("seamark:" + add, value); + } + } else { + common.put(s, value); + } + } + for (Entry> g : groupByOpenSeamaps.entrySet()) { + g.getValue().putAll(common); + g.getValue().put("seamark:" + g.getKey(), g.getKey()); + if (openSeaType(type).equals(g.getKey())) { + g.getValue().remove(ATTACHED_KEY); + g.getValue().put("seamark:" + g.getKey(), type); + } + } + return groupByOpenSeamaps.values().iterator(); + } + private String openSeaType(String value) { + if(value.equals("light_major") || value.equals("light_minor")) { + return "light"; + } + return value; + } + public Map getAmenityNameToType(){ if(amenityNameToType == null){ amenityNameToType = new LinkedHashMap(); @@ -729,5 +812,7 @@ public class MapRenderingTypes { } + + } diff --git a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java index 63070b748d..5656a40b99 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java @@ -1,7 +1,8 @@ package net.osmand.osm.edit; -import java.util.Collection; +import java.util.Iterator; import java.util.List; +import java.util.Map; import net.osmand.data.Amenity; import net.osmand.data.AmenityType; @@ -102,19 +103,23 @@ public class EntityParser { public static List parseAmenities(MapRenderingTypes renderingTypes, Entity entity, List amenitiesList){ + amenitiesList.clear(); // it could be collection of amenities boolean relation = entity instanceof Relation; - Collection keySet = entity.getTagKeySet(); - if (!keySet.isEmpty()) { - boolean purerelation = relation && !"multipolygon".equals(entity.getTag("type")); - for (String t : keySet) { - AmenityType type = purerelation? renderingTypes.getAmenityTypeForRelation(t, entity.getTag(t)): - renderingTypes.getAmenityType(t, entity.getTag(t)); - if (type != null) { - String subtype = renderingTypes.getAmenitySubtype(t, entity.getTag(t)); - Amenity a = parseAmenity(entity, type, subtype, renderingTypes); - if(checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)){ - amenitiesList.add(a); + Iterator> it = renderingTypes.splitTagsIntoDifferentObjects(entity.getTags()); + while (it.hasNext()) { + Map tags = it.next(); + if (!tags.isEmpty()) { + boolean purerelation = relation && !"multipolygon".equals(tags.get("type")); + for (Map.Entry e : tags.entrySet()) { + AmenityType type = purerelation ? renderingTypes.getAmenityTypeForRelation(e.getKey(), e.getValue()) + : renderingTypes.getAmenityType(e.getKey(), e.getValue()); + if (type != null) { + String subtype = renderingTypes.getAmenitySubtype(e.getKey(), e.getValue()); + Amenity a = parseAmenity(entity, type, subtype, renderingTypes); + if (checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)) { + amenitiesList.add(a); + } } } }