- Timestamp:
- 2019-05-15T22:38:20+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/SplitWayCommand.java
r14654 r15078 9 9 import java.util.Collection; 10 10 import java.util.Collections; 11 import java.util.HashMap; 11 12 import java.util.HashSet; 12 13 import java.util.Iterator; 13 14 import java.util.LinkedList; 14 15 import java.util.List; 16 import java.util.Map; 15 17 import java.util.Objects; 16 18 import java.util.Optional; … … 52 54 private final Way originalWay; 53 55 private final List<Way> newWays; 56 /** Map<Restriction type, type to treat it as> */ 57 private static final Map<String, String> relationSpecialTypes = new HashMap<>(); 58 static { 59 relationSpecialTypes.put("restriction", "restriction"); 60 relationSpecialTypes.put("destination_sign", "restriction"); 61 } 54 62 55 63 /** … … 311 319 if (rm.isWay() && rm.getMember() == way) { 312 320 boolean insert = true; 313 if ("restriction".equals(type) || "destination_sign".equals(type)) { 314 /* this code assumes the restriction is correct. No real error checking done */ 315 String role = rm.getRole(); 316 if ("from".equals(role) || "to".equals(role)) { 317 OsmPrimitive via = findVia(r, type); 318 List<Node> nodes = new ArrayList<>(); 319 if (via != null) { 320 if (via instanceof Node) { 321 nodes.add((Node) via); 322 } else if (via instanceof Way) { 323 nodes.add(((Way) via).lastNode()); 324 nodes.add(((Way) via).firstNode()); 325 } 326 } 327 Way res = null; 328 for (Node n : nodes) { 329 if (changedWay.isFirstLastNode(n)) { 330 res = way; 331 } 332 } 333 if (res == null) { 334 for (Way wayToAdd : newWays) { 335 for (Node n : nodes) { 336 if (wayToAdd.isFirstLastNode(n)) { 337 res = wayToAdd; 338 } 339 } 340 } 341 if (res != null) { 342 if (c == null) { 343 c = new Relation(r); 344 } 345 c.addMember(new RelationMember(role, res)); 346 c.removeMembersFor(way); 347 insert = false; 348 } 349 } else { 350 insert = false; 351 } 352 } else if (!"via".equals(role)) { 353 warnme = true; 354 } 321 if (relationSpecialTypes.containsKey(type) && "restriction".equals(relationSpecialTypes.get(type))) { 322 Map<String, Boolean> rValue = treatAsRestriction(r, rm, c, newWays, way, changedWay); 323 warnme = rValue.containsKey("warnme") ? rValue.get("warnme") : warnme; 324 insert = rValue.containsKey("insert") ? rValue.get("insert") : insert; 355 325 } else if (!("route".equals(type)) && !("multipolygon".equals(type))) { 356 326 warnme = true; … … 440 410 } 441 411 412 private static Map<String, Boolean> treatAsRestriction(Relation r, 413 RelationMember rm, Relation c, Collection<Way> newWays, Way way, 414 Way changedWay) { 415 HashMap<String, Boolean> rMap = new HashMap<>(); 416 /* this code assumes the restriction is correct. No real error checking done */ 417 String role = rm.getRole(); 418 String type = Optional.ofNullable(r.get("type")).orElse(""); 419 if ("from".equals(role) || "to".equals(role)) { 420 OsmPrimitive via = findVia(r, type); 421 List<Node> nodes = new ArrayList<>(); 422 if (via != null) { 423 if (via instanceof Node) { 424 nodes.add((Node) via); 425 } else if (via instanceof Way) { 426 nodes.add(((Way) via).lastNode()); 427 nodes.add(((Way) via).firstNode()); 428 } 429 } 430 Way res = null; 431 for (Node n : nodes) { 432 if (changedWay.isFirstLastNode(n)) { 433 res = way; 434 } 435 } 436 if (res == null) { 437 for (Way wayToAdd : newWays) { 438 for (Node n : nodes) { 439 if (wayToAdd.isFirstLastNode(n)) { 440 res = wayToAdd; 441 } 442 } 443 } 444 if (res != null) { 445 if (c == null) { 446 c = new Relation(r); 447 } 448 c.addMember(new RelationMember(role, res)); 449 c.removeMembersFor(way); 450 rMap.put("insert", false); 451 } 452 } else { 453 rMap.put("insert", false); 454 } 455 } else if (!"via".equals(role)) { 456 rMap.put("warnme", true); 457 } 458 return rMap; 459 } 460 442 461 static OsmPrimitive findVia(Relation r, String type) { 443 462 if (type != null) { … … 478 497 return chunks != null ? splitWay(way, chunks, selection) : null; 479 498 } 499 500 /** 501 * Add relations that are treated in a specific way. 502 * @param relationType The value in the {@code type} key 503 * @param treatAs The type of relation to treat the {@code relationType} as. 504 * Currently only supports relations that can be handled like "restriction" 505 * relations. 506 * @return the previous value associated with relationType, or null if there was no mapping 507 * @since 15078 508 */ 509 public static String addSpecialRelationType(String relationType, String treatAs) { 510 return relationSpecialTypes.put(relationType, treatAs); 511 } 512 513 /** 514 * Get the types of relations that are treated differently 515 * @return {@code Map<Relation Type, Type of Relation it is to be treated as>} 516 * @since 15078 517 */ 518 public static Map<String, String> getSpecialRelationTypes() { 519 return relationSpecialTypes; 520 } 480 521 }
Note:
See TracChangeset
for help on using the changeset viewer.