Пример #1
0
  public void addTurn(List<Road> via, Road.End to) {
    assert equals(to.getJunction());

    Relation existing = null;
    for (Turn t : to.getTurns()) {
      if (t.getFrom().getOutgoingRoadEnd().equals(getOutgoingRoadEnd()) && t.getVia().equals(via)) {
        if (t.getFrom().equals(this)) {
          // was already added
          return;
        }

        existing = t.getRelation();
      }
    }

    final Relation r;
    if (existing == null) {
      r = new Relation();
      r.put("type", Constants.TYPE_TURNS);

      r.addMember(new RelationMember(Constants.TURN_ROLE_FROM, getOutgoingRoadEnd().getWay()));
      if (via.isEmpty()) {
        r.addMember(new RelationMember(Constants.TURN_ROLE_VIA, getOutgoingJunction().getNode()));
      } else {
        for (Way w :
            Utils.flattenVia(getOutgoingJunction().getNode(), via, to.getJunction().getNode())) {
          r.addMember(new RelationMember(Constants.TURN_ROLE_VIA, w));
        }
      }
      r.addMember(new RelationMember(Constants.TURN_ROLE_TO, to.getWay()));

      getOutgoingJunction().getNode().getDataSet().addPrimitive(r);
    } else {
      r = existing;
    }

    final String key = isExtra() ? Constants.TURN_KEY_EXTRA_LANES : Constants.TURN_KEY_LANES;
    final List<Integer> lanes = Turn.indices(r, key);
    lanes.add(getIndex());
    r.put(key, Turn.join(lanes));
  }