Ignore:
Timestamp:
2011-05-01T21:56:49+02:00 (13 years ago)
Author:
jttt
Message:

Improved wms cache

  • files saved in original format (no need to recode to png)
  • possibility to tile with different pos/ppd that overlaps current tile
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r4043 r4065  
    1616import java.util.ArrayList;
    1717import java.util.Collections;
     18import java.util.HashSet;
    1819import java.util.Iterator;
    1920import java.util.List;
     21import java.util.Set;
    2022import java.util.concurrent.locks.Condition;
    2123import java.util.concurrent.locks.Lock;
     
    4143import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    4244import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
     45import org.openstreetmap.josm.data.imagery.WmsCache;
    4346import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    4447import org.openstreetmap.josm.data.preferences.BooleanProperty;
     
    4750import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    4851import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    49 import org.openstreetmap.josm.io.CacheFiles;
    5052import org.openstreetmap.josm.io.imagery.Grabber;
    5153import org.openstreetmap.josm.io.imagery.HTMLGrabber;
     
    7981    protected ImageryInfo info;
    8082    protected final MapView mv;
     83    public WmsCache cache;
     84
    8185
    8286    // Image index boundary for current view
     
    118122        setBackgroundLayer(true); /* set global background variable */
    119123        initializeImages();
     124        if (info.getUrl() != null) {
     125            for (WMSLayer layer: Main.map.mapView.getLayersOfType(WMSLayer.class)) {
     126                if (layer.getInfo().getUrl().equals(info.getUrl())) {
     127                    cache = layer.cache;
     128                    break;
     129                }
     130            }
     131            if (cache == null) {
     132                cache = new WmsCache(info.getUrl(), imageSize);
     133                cache.loadIndex();
     134            }
     135        }
    120136        this.info = new ImageryInfo(info);
    121137        if(this.info.getPixelPerDegree() == 0.0) {
     
    157173        cancelGrabberThreads(false);
    158174        Main.pref.removePreferenceChangeListener(this);
     175        if (cache != null) {
     176            cache.saveIndex();
     177        }
    159178    }
    160179
     
    205224
    206225        ProjectionBounds bounds = mv.getProjectionBounds();
    207         bminx= getImageXIndex(bounds.min.east());
    208         bminy= getImageYIndex(bounds.min.north());
    209         bmaxx= getImageXIndex(bounds.max.east());
    210         bmaxy= getImageYIndex(bounds.max.north());
    211 
    212         leftEdge = (int)(bounds.min.east() * getPPD());
    213         bottomEdge = (int)(bounds.min.north() * getPPD());
     226        bminx= getImageXIndex(bounds.minEast);
     227        bminy= getImageYIndex(bounds.minNorth);
     228        bmaxx= getImageXIndex(bounds.maxEast);
     229        bmaxy= getImageYIndex(bounds.maxNorth);
     230
     231        leftEdge = (int)(bounds.minEast * getPPD());
     232        bottomEdge = (int)(bounds.minNorth * getPPD());
    214233
    215234        if (zoomIsTooBig()) {
    216             for(int x = bminx; x<=bmaxx; ++x) {
    217                 for(int y = bminy; y<=bmaxy; ++y) {
    218                     images[modulo(x,dax)][modulo(y,day)].paint(g, mv, x, y, leftEdge, bottomEdge);
     235            for(int x = 0; x<images.length; ++x) {
     236                for(int y = 0; y<images[0].length; ++y) {
     237                    GeorefImage image = images[x][y];
     238                    image.paint(g, mv, image.getXIndex(), image.getYIndex(), leftEdge, bottomEdge);
    219239                }
    220240            }
     
    305325    }
    306326
     327    public boolean isOverlapEnabled() {
     328        return WMSLayer.PROP_OVERLAP.get() && (WMSLayer.PROP_OVERLAP_EAST.get() > 0 || WMSLayer.PROP_OVERLAP_NORTH.get() > 0);
     329    }
     330
    307331    /**
    308332     *
     
    310334     */
    311335    public BufferedImage normalizeImage(BufferedImage img) {
    312         if (WMSLayer.PROP_OVERLAP.get() && (WMSLayer.PROP_OVERLAP_EAST.get() > 0 || WMSLayer.PROP_OVERLAP_NORTH.get() > 0)) {
     336        if (isOverlapEnabled()) {
    313337            BufferedImage copy = img;
    314338            img = new BufferedImage(imageSize, imageSize, copy.getType());
     
    357381
    358382        gatherFinishedRequests();
     383        Set<ProjectionBounds> areaToCache = new HashSet<ProjectionBounds>();
    359384
    360385        for(int x = bminx; x<=bmaxx; ++x) {
     
    362387                GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
    363388                if (!img.paint(g, mv, x, y, leftEdge, bottomEdge)) {
    364                     WMSRequest request = new WMSRequest(x, y, info.getPixelPerDegree(), real);
     389                    WMSRequest request = new WMSRequest(x, y, info.getPixelPerDegree(), real, true);
    365390                    addRequest(request);
    366                 }
    367             }
    368         }
     391                    areaToCache.add(new ProjectionBounds(getEastNorth(x, y), getEastNorth(x + 1, y + 1)));
     392                } else if (img.getState() == State.PARTLY_IN_CACHE && autoDownloadEnabled) {
     393                    WMSRequest request = new WMSRequest(x, y, info.getPixelPerDegree(), real, false);
     394                    addRequest(request);
     395                    areaToCache.add(new ProjectionBounds(getEastNorth(x, y), getEastNorth(x + 1, y + 1)));
     396                }
     397            }
     398        }
     399        cache.setAreaToCache(areaToCache);
    369400    }
    370401
     
    548579        @Override
    549580        public void actionPerformed(ActionEvent ev) {
    550             initializeImages();
    551581            resolution = mv.getDist100PixelText();
    552582            info.setPixelPerDegree(getPPD());
    553583            settingsChanged = true;
     584            for(int x = 0; x<dax; ++x) {
     585                for(int y = 0; y<day; ++y) {
     586                    images[x][y].changePosition(-1, -1);
     587                }
     588            }
    554589            mv.repaint();
    555590        }
     
    564599            // Delete small files, because they're probably blank tiles.
    565600            // See https://josm.openstreetmap.de/ticket/2307
    566             Grabber.cache.customCleanUp(CacheFiles.CLEAN_SMALL_FILES, 4096);
     601            cache.cleanSmallFiles(4096);
    567602
    568603            for (int x = 0; x < dax; ++x) {
     
    570605                    GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
    571606                    if(img.getState() == State.FAILED){
    572                         addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), true));
    573                         mv.repaint();
     607                        addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), true, false));
    574608                    }
    575609                }
     
    680714                settingsChanged = true;
    681715                mv.repaint();
     716                if (cache != null) {
     717                    cache.saveIndex();
     718                    cache = null;
     719                }
    682720                if(info.getUrl() != null)
    683721                {
     722                    cache = new WmsCache(info.getUrl(), imageSize);
    684723                    startGrabberThreads();
    685724                }
     
    737776                        GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
    738777                        if(img.getState() == State.NOT_IN_CACHE){
    739                             addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), false));
     778                            addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), false, true));
    740779                        }
    741780                    }
Note: See TracChangeset for help on using the changeset viewer.