Ignore:
Timestamp:
2010-02-14T15:01:00+01:00 (15 years ago)
Author:
jttt
Message:

Calculate bbox for relations, use it in mappaint.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2970 r2982  
    2323     */
    2424    private final List<RelationMember> members = new ArrayList<RelationMember>();
     25
     26    private BBox bbox;
    2527
    2628    /**
     
    336338    @Override
    337339    public BBox getBBox() {
    338         return new BBox(0, 0, 0, 0);
     340        if (bbox == null) {
     341            calculateBBox(new HashSet<PrimitiveId>());
     342            if (bbox == null) {
     343                bbox = new BBox(0, 0, 0, 0); // No members
     344            }
     345        }
     346        return  bbox;
     347    }
     348
     349    private BBox calculateBBox(Set<PrimitiveId> visitedRelations) {
     350        if (visitedRelations.contains(this))
     351            return null;
     352        visitedRelations.add(this);
     353        if (members.isEmpty())
     354            return null;
     355        else {
     356            BBox result = null;
     357            for (RelationMember rm:members) {
     358                BBox box = rm.isRelation()?rm.getRelation().calculateBBox(visitedRelations):rm.getMember().getBBox();
     359                if (box != null) {
     360                    if (result == null) {
     361                        result = box;
     362                    } else {
     363                        result.add(box);
     364                    }
     365                }
     366            }
     367            return result;
     368        }
    339369    }
    340370
    341371    @Override
    342372    public void updatePosition() {
    343         // Do nothing for now
     373        bbox = calculateBBox(new HashSet<PrimitiveId>());
    344374    }
    345375
     
    355385            for (RelationMember rm: members) {
    356386                if (rm.getMember().getDataSet() != dataSet)
    357                     throw new DataIntegrityProblemException("Relation member must be part of the same dataset as relation");
     387                    throw new DataIntegrityProblemException(String.format("Relation member must be part of the same dataset as relation(%s, %s)", getPrimitiveId(), rm.getMember().getPrimitiveId()));
    358388            }
    359389        }
Note: See TracChangeset for help on using the changeset viewer.