From a1ed8cabbf1e161625f024c5f2c0ea1d87bc6a0c Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 1 Dec 2013 17:08:52 +0100 Subject: [PATCH] Fix open sea maps creator --- .../net/osmand/binary/BinaryInspector.java | 6 +-- .../src/net/osmand/osm/MapRenderingTypes.java | 49 +++++++------------ .../src/net/osmand/osm/edit/Entity.java | 4 ++ .../src/net/osmand/osm/edit/EntityParser.java | 7 ++- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index 89b543ddaf..44710acd1f 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -56,11 +56,11 @@ public class BinaryInspector { in.inspector(args); // test cases show info /*in.inspector(new String[]{ - "-vpoi", - //"-vmap", "-vmapobjects", + //"-vpoi", + "-vmap", "-vmapobjects", //"-vstreets", "-bbox=4,55,7,50", - "/home/victor/projects/osmand/osm-gen/World_sea_map.obf"});*/ + "/home/victor/projects/osmand/osm-gen/World_seamarks_2.obf"});*/ } private void printToFile(String s) throws IOException { diff --git a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java index bd0b0d83f7..2263547156 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java @@ -12,13 +12,12 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import java.util.TreeMap; import net.osmand.PlatformUtil; import net.osmand.data.AmenityType; -import net.osmand.osm.edit.Entity; import net.osmand.osm.edit.OSMSettings.OSMTagKey; import net.osmand.util.Algorithms; @@ -133,8 +132,17 @@ public class MapRenderingTypes { return amenityTypeNameToTagVal; } - public Iterator> splitTagsIntoDifferentObjects(final Map tags) { + public Collection> splitTagsIntoDifferentObjects(final Map tags) { // check open sea maps tags + boolean split = splitIsNeeded(tags); + if(!split) { + return Collections.singleton(tags); + } else { + return splitOpenSeaMapsTags(tags); + } + } + + protected boolean splitIsNeeded(final Map tags) { boolean seamark = false; for(String s : tags.keySet()) { if(s.startsWith("seamark:")) { @@ -142,35 +150,10 @@ public class MapRenderingTypes { break; } } - if(!seamark) { - return oneIterator(tags); - } else { - return splitOpenSeaMapsTags(tags); - } + return seamark; } - 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) { + private Collection> splitOpenSeaMapsTags(final Map tags) { Map> groupByOpenSeamaps = new HashMap>(); Map common = new HashMap(); String ATTACHED_KEY = "seamark:attached"; @@ -197,15 +180,19 @@ public class MapRenderingTypes { common.put(s, value); } } + List> res = new ArrayList>(); for (Entry> g : groupByOpenSeamaps.entrySet()) { g.getValue().putAll(common); g.getValue().put("seamark", g.getKey()); if (openSeaType(type).equals(g.getKey())) { g.getValue().remove(ATTACHED_KEY); g.getValue().put("seamark", type); + res.add(0, g.getValue()); + } else { + res.add(g.getValue()); } } - return groupByOpenSeamaps.values().iterator(); + return res; } diff --git a/OsmAnd-java/src/net/osmand/osm/edit/Entity.java b/OsmAnd-java/src/net/osmand/osm/edit/Entity.java index 8c90995f7b..beda3a6402 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/Entity.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/Entity.java @@ -142,6 +142,10 @@ public abstract class Entity { return tags.put(key, value); } + public void replaceTags(Map toPut){ + tags = new LinkedHashMap(toPut); + } + public String getTag(OSMTagKey key){ return getTag(key.getValue()); } diff --git a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java index b2f03e5831..f99a4b22c0 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java @@ -1,6 +1,6 @@ package net.osmand.osm.edit; -import java.util.Iterator; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -110,9 +110,8 @@ public class EntityParser { amenitiesList.clear(); // it could be collection of amenities boolean relation = entity instanceof Relation; - Iterator> it = renderingTypes.splitTagsIntoDifferentObjects(entity.getTags()); - while (it.hasNext()) { - Map tags = it.next(); + Collection> it = renderingTypes.splitTagsIntoDifferentObjects(entity.getTags()); + for(Map tags : it) { if (!tags.isEmpty()) { boolean purerelation = relation && !"multipolygon".equals(tags.get("type")); for (Map.Entry e : tags.entrySet()) {