| 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; |
| | 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 | |
| | 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 | * @since xxx |
| | 507 | */ |
| | 508 | public static void addSpecialRelationType(String relationType, String treatAs) { |
| | 509 | relationSpecialTypes.put(relationType, treatAs); |
| | 510 | } |
| | 511 | |
| | 512 | /** |
| | 513 | * Get the types of relations that are treated differently |
| | 514 | * @return {@code Map<Relation Type, Type of Relation it is to be treated as>} |
| | 515 | * @since xxx |
| | 516 | */ |
| | 517 | public static Map<String, String> getSpecialRelationTypes() { |
| | 518 | return relationSpecialTypes; |
| | 519 | } |