Ignore:
Timestamp:
2011-12-01T00:53:26+01:00 (12 years ago)
Author:
Don-vip
Message:

see #6987 - multipolygon cache aware of events requiring cache refresh (data change, zoom, layer removing)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r4621 r4623  
    66import java.util.Collection;
    77import java.util.Collections;
    8 import java.util.HashMap;
    98import java.util.Iterator;
    109import java.util.List;
    11 import java.util.Map;
    1210import java.util.Map.Entry;
    1311
     
    1715import org.openstreetmap.josm.data.osm.Way;
    1816import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
     17import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
    1918import org.openstreetmap.josm.gui.NavigatableComponent;
    2019import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
     
    3130    private int defaultNodesIdx, defaultLinesIdx;
    3231   
    33     private final Map<NavigatableComponent, Map<Relation, Multipolygon>> multipolygonsCache;
    34 
    3532    public ElemStyles()
    3633    {
    3734        styleSources = new ArrayList<StyleSource>();
    38         multipolygonsCache = new HashMap<NavigatableComponent, Map<Relation,Multipolygon>>();
    3935    }
    4036
     
    121117    }
    122118
    123     private final Multipolygon getCachedMultipolygon(NavigatableComponent nc, Relation r) {
    124         Multipolygon multipolygon = null;
    125         Map<Relation, Multipolygon> map = multipolygonsCache.get(nc);
    126         if (map == null) {
    127             multipolygonsCache.put(nc, map = new HashMap<Relation, Multipolygon>());
    128         }
    129         multipolygon = map.get(r);
    130         if (multipolygon == null) {
    131             map.put(r, multipolygon = new Multipolygon(nc));
    132             multipolygon.load(r);
    133         }
    134         return multipolygon;
    135     }
    136    
    137119    /**
    138120     * Create the list of styles and its valid scale range for one primitive.
     
    179161                    continue;
    180162                }
    181                 Multipolygon multipolygon = getCachedMultipolygon(nc, r);
     163                Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r);
    182164
    183165                if (multipolygon.getOuterWays().contains(osm)) {
     
    244226                    continue;
    245227                }
    246                 final Multipolygon multipolygon = getCachedMultipolygon(nc, ref);
     228                final Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, ref);
    247229
    248230                if (multipolygon.getInnerWays().contains(osm)) {
     
    277259                if (!Utils.exists(p.a, AreaElemStyle.class)) {
    278260                    // look at outer ways to find area style
    279                     Multipolygon multipolygon = new Multipolygon(nc);
    280                     multipolygon.load((Relation) osm);
     261                    Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm);
    281262                    for (Way w : multipolygon.getOuterWays()) {
    282263                        Pair<StyleList, Range> wayStyles = generateStyles(w, scale, null, false);
     
    429410        styleSources.addAll(sources);
    430411    }
    431 
    432     public void clearMultipolygonsCache(NavigatableComponent nc) {
    433         multipolygonsCache.remove(nc);
    434     }
    435412}
Note: See TracChangeset for help on using the changeset viewer.