Changeset 33477 in osm for applications/editors/josm
- Timestamp:
- 2017-07-27T20:09:31+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/CreatePlatformNodeAction.java
r33461 r33477 9 9 import java.util.List; 10 10 import java.util.Map.Entry; 11 import java.util.Set; 12 import java.util.SortedSet; 13 import java.util.TreeSet; 11 14 12 15 import org.openstreetmap.josm.Main; … … 21 24 import org.openstreetmap.josm.data.osm.TagCollection; 22 25 import org.openstreetmap.josm.data.osm.Way; 26 import org.openstreetmap.josm.data.validation.routines.RegexValidator; 23 27 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 24 28 import org.openstreetmap.josm.tools.UserCancelException; … … 72 76 dummy3 = new Node(platformNode.getEastNorth()); 73 77 78 SortedSet<String> refs = new TreeSet<>(); 79 74 80 Main.main.undoRedo.add(new AddCommand(dummy1)); 75 81 Main.main.undoRedo.add(new AddCommand(dummy2)); 76 82 Main.main.undoRedo.add(new AddCommand(dummy3)); 77 83 78 populateMap(stopPositionNode);79 populateMap(platformNode);84 refs.addAll(populateMap(stopPositionNode)); 85 refs.addAll(populateMap(platformNode)); 80 86 81 87 if (platformWay != null) { 82 populateMap(platformWay);88 refs.addAll(populateMap(platformWay)); 83 89 platformWay.removeAll(); 84 90 platformWay.put("public_transport", "platform"); … … 93 99 platformNode.put("public_transport", "platform"); 94 100 platformNode.put("highway", "bus_stop"); 101 if (!refs.isEmpty()) { 102 platformNode.put("route_ref", getRefs(refs)); 103 } 95 104 96 105 List<OsmPrimitive> prims = new ArrayList<>(); … … 114 123 } 115 124 116 public voidpopulateMap(OsmPrimitive prim) {125 public List<String> populateMap(OsmPrimitive prim) { 117 126 List<String> unInterestingTags = new ArrayList<>(); 118 127 unInterestingTags.add("public_transport"); … … 120 129 unInterestingTags.add("source"); 121 130 131 List<String> refs = new ArrayList<>(); 122 132 for (Entry<String, String> tag: prim.getKeys().entrySet()) { 123 if (unInterestingTags.contains(tag.getKey())) { 133 if ("note".equals(tag.getKey()) 134 || "lines".equals(tag.getKey())) { 135 refs.addAll(addRefs(tag.getValue())); 124 136 continue; 125 137 } 126 if (dummy1.get(tag.getKey()) == null) { 127 dummy1.put(tag.getKey(), tag.getValue()); 128 } else if (dummy2.get(tag.getKey()) == null) { 129 dummy2.put(tag.getKey(), tag.getValue()); 130 } else if (dummy3.get(tag.getKey()) == null) { 131 dummy3.put(tag.getKey(), tag.getValue()); 138 139 if (!unInterestingTags.contains(tag.getKey())) { 140 if (dummy1.get(tag.getKey()) == null) { 141 dummy1.put(tag.getKey(), tag.getValue()); 142 } else if (dummy2.get(tag.getKey()) == null) { 143 dummy2.put(tag.getKey(), tag.getValue()); 144 } else if (dummy3.get(tag.getKey()) == null) { 145 dummy3.put(tag.getKey(), tag.getValue()); 146 } 132 147 } 133 148 } 149 return refs; 150 } 151 152 private List<String> addRefs(String value) { 153 List<String> refs = new ArrayList<>(); 154 if (new RegexValidator("\\w+([,;].+)*").isValid(value)) { 155 for (String ref : value.split("[,;]")) { 156 refs.add(ref.trim()); 157 } 158 } 159 return refs; 160 } 161 162 private String getRefs(Set<String> refs) { 163 StringBuilder sb = new StringBuilder(); 164 if (refs.isEmpty()) 165 return sb.toString(); 166 167 for (String ref : refs) { 168 sb.append(ref).append(';'); 169 } 170 171 return sb.toString().substring(0, sb.length() - 1); 134 172 } 135 173
Note:
See TracChangeset
for help on using the changeset viewer.