Ignore:
Timestamp:
2010-02-14T15:01:00+01:00 (14 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/DataSet.java

    r2944 r2982  
    136136    }
    137137
     138    public List<Relation> searchRelations(BBox bbox) {
     139        // QuadBuckets might be useful here (don't forget to do reindexing after some of rm is changed)
     140        List<Relation> result = new ArrayList<Relation>();
     141        for (Relation r: relations) {
     142            if (r.getBBox().intersects(bbox)) {
     143                result.add(r);
     144            }
     145        }
     146        return result;
     147    }
     148
    138149    /**
    139150     * All data sources of this DataSet.
     
    200211     * Adds a primitive to the dataset
    201212     *
    202      * @param primitive the primitive. Ignored if null.
     213     * @param primitive the primitive.
    203214     */
    204215    public void addPrimitive(OsmPrimitive primitive) {
     
    779790    }
    780791
    781     /**
    782      * Reindex all nodes and ways after their coordinates were changed. This is a temporary solution, reindexing should
    783      * be automatic in the future
    784      * @deprecated Reindexing should be automatic
    785      */
    786     @Deprecated
    787     public void reindexAll() {
    788         List<Node> ntmp = new ArrayList<Node>(nodes);
    789         nodes.clear();
    790         nodes.addAll(ntmp);
    791         List<Way> wtmp = new ArrayList<Way>(ways);
    792         ways.clear();
    793         ways.addAll(wtmp);
    794     }
    795 
    796792    private void reindexNode(Node node) {
    797793        nodes.remove(node);
    798794        nodes.add(node);
    799         for (Way way:OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) {
    800             ways.remove(way);
    801             way.updatePosition();
    802             ways.add(way);
     795        for (OsmPrimitive primitive: node.getReferrers()) {
     796            if (primitive instanceof Way) {
     797                reindexWay((Way)primitive);
     798            } else {
     799                reindexRelation((Relation) primitive);
     800            }
    803801        }
    804802    }
    805803
    806804    private void reindexWay(Way way) {
     805        BBox before = way.getBBox();
    807806        ways.remove(way);
    808807        way.updatePosition();
    809808        ways.add(way);
     809        if (!way.getBBox().equals(before)) {
     810            for (OsmPrimitive primitive: way.getReferrers()) {
     811                reindexRelation((Relation)primitive);
     812            }
     813        }
     814    }
     815
     816    private void reindexRelation(Relation relation) {
     817        BBox before = relation.getBBox();
     818        relation.updatePosition();
     819        if (!before.equals(relation.getBBox())) {
     820            for (OsmPrimitive primitive: relation.getReferrers()) {
     821                reindexRelation((Relation) primitive);
     822            }
     823        }
    810824    }
    811825
     
    874888
    875889    void fireRelationMembersChanged(Relation r) {
     890        reindexRelation(r);
    876891        fireEvent(new RelationMembersChangedEvent(this, r));
    877892    }
Note: See TracChangeset for help on using the changeset viewer.