Changeset 388

Show
Ignore:
Timestamp:
09/05/08 02:30:42 (3 months ago)
Author:
arneke
Message:

Hooking zoomStart and zoomStop up to grid object instead of layer. More robust at looking for geowebcache.xml

Location:
trunk/geowebcache
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/geowebcache/pom.xml

    r374 r388  
    1212  <properties> 
    1313    <!-- gs.version>1.6.4</gs.version --> 
    14     <gt.version>2.5-RC1</gt.version> 
     14    <gt.version>2.5-SNAPSHOT</gt.version> 
    1515    <spring.version>2.5.5</spring.version> 
    1616    <restlet.version>1.0.8</restlet.version> 
  • trunk/geowebcache/src/main/java/org/geowebcache/demo/Demo.java

    r375 r388  
    166166        BBOX zoomBounds = grid.getBounds(); 
    167167        //String res = "resolutions: "+ Arrays.toString(grid.getResolutions()) + ",\n"; 
    168         String res = "maxResolution: " + Double.toString(grid.getResolutions()[0]) +",\n";  
     168        String res = "maxResolution: " + Double.toString(grid.getResolutions()[grid.getZoomStart()]) +",\n";  
    169169        String page = 
    170170            "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head>\n" 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/Grid.java

    r386 r388  
    2121import org.geowebcache.GeoWebCacheException; 
    2222import org.geowebcache.util.wms.BBOX; 
     23import org.mortbay.log.Log; 
    2324 
    2425/** 
     
    3738    private volatile transient GridCalculator gridCalculator; 
    3839     
    39     private volatile int zoomStart = 0; 
     40    private int zoomStart = 0; 
    4041     
    41     private volatile int zoomStop = 30; 
     42    private int zoomStop = 30; 
    4243     
    4344    public Grid(SRS srs, BBOX bounds, BBOX gridBounds, double[] resolutions) { 
     
    122123    } 
    123124     
     125    /**  
     126     * Use double locking to get the calculator to avoid performance hit. 
     127     *  
     128     * @return 
     129     * @throws GeoWebCacheException 
     130     */ 
    124131    public GridCalculator getGridCalculator() throws GeoWebCacheException { 
    125132        GridCalculator ret = gridCalculator; 
     
    136143 
    137144    private GridCalculator initGridCalculator() throws GeoWebCacheException { 
     145        if(zoomStart < 0 || zoomStop < zoomStart || zoomStop == 0) { 
     146            Log.debug("Missing values, setting zoomStart,zoomStop to 0,30"); 
     147            zoomStart = 0; 
     148            zoomStop = 30; 
     149        } 
    138150        return new GridCalculator(this); 
    139151    } 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/GridCalculator.java

    r387 r388  
    6969    public GridCalculator(Grid grid) throws GeoWebCacheException { 
    7070 
    71         //TODO this is messed up, ignoring Grid object 
    7271        this.grid = grid; 
    73         this.zoomStart = 0; 
    74         this.zoomStop = 30; 
    75         //this.metaWidth = metaWidth; 
    76         //this.metaHeight = metaHeight; 
    77  
     72         
    7873        if(grid.resolutions != null) { 
    7974            this.resolutions = grid.resolutions; 
    8075            this.zoomStop = resolutions.length - 1; 
     76        } else { 
     77            this.zoomStart = grid.getZoomStart(); 
     78            this.zoomStop = grid.getZoomStop(); 
    8179        } 
    8280         
     
    9694    private void determineGrid() throws GeoWebCacheException { 
    9795        if(grid.resolutions == null) { 
    98             // Figure out the approriate resolutions 
     96            // Figure out the appropriate resolutions 
    9997             
    10098            double ratio = gridWidth / gridHeight; 
     
    152150        } 
    153151         
    154         this.resolutions = new double[this.zoomStop - this.zoomStart + 1]; 
     152        // We still need the full array, even though we only care about a part of it 
     153        this.resolutions = new double[this.zoomStop + 1]; 
    155154        for(int i=this.zoomStart; i<= this.zoomStop; i++) { 
    156155            this.resolutions[i] = baseResolution; 
     
    472471    private int binarySearchForResolution(double reqResolution)  
    473472    throws BadTileException { 
    474         return binarySearchForResolution(this.resolutions, reqResolution); 
    475     } 
    476      
    477     protected static int binarySearchForResolution(double[] resolutions, double reqResolution)  
     473        return binarySearchForResolution(this.resolutions, reqResolution, this.zoomStart); 
     474    } 
     475     
     476    protected static int binarySearchForResolution(double[] resolutions, double reqResolution, int zoomStart)  
    478477    throws BadTileException { 
    479         int low = 0; 
     478        int low = zoomStart; 
    480479        int high = resolutions.length - 1; 
    481480         
     
    485484         
    486485        // Deal with the edge cases first 
    487         if(reqLower > resolutions[1]) { 
     486        if(reqLower > resolutions[low]) { 
    488487            if(resolutions[0] < reqLower) { 
    489488                throw new BadTileException("Resolution "+reqResolution+" is too big for grid," 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/TileLayerDispatcher.java

    r301 r388  
    103103        HashMap<String, TileLayer> layers = new HashMap<String, TileLayer>(); 
    104104 
    105         Iterator configIter = configs.iterator(); 
     105        Iterator<Configuration> configIter = configs.iterator(); 
    106106        while (configIter.hasNext()) { 
    107107            Map<String, TileLayer> configLayers = null; 
    108108 
    109             Configuration config = (Configuration) configIter.next(); 
     109            Configuration config = configIter.next(); 
    110110 
    111111            try { 
     
    113113            } catch (GeoWebCacheException gwce) { 
    114114                log.error(gwce.getMessage()); 
    115                 log 
    116                         .error("Failed to add layers from " 
     115                log.error("Failed to add layers from " 
    117116                                + config.getIdentifier()); 
    118117            } 
  • trunk/geowebcache/src/main/java/org/geowebcache/service/wms/WMSService.java

    r379 r388  
    6767            throws GeoWebCacheException { 
    6868        String[] keys = { "layers", "request" }; 
    69         String[] values = ServletUtils.selectedStringsFromMap(request 
    70                 .getParameterMap(), keys); 
     69        String[] values = ServletUtils.selectedStringsFromMap( 
     70                request.getParameterMap(), keys); 
    7171 
    7272        // Look for getCapabilities 
  • trunk/geowebcache/src/main/java/org/geowebcache/util/XMLConfiguration.java

    r384 r388  
    158158        xs.alias("transparent", boolean.class); 
    159159        xs.alias("SRS", org.geowebcache.layer.SRS.class); 
     160         
     161        xs.alias("zoomStart", int.class); 
     162        xs.alias("zoomStop", int.class); 
    160163        //xs.alias("debugheaders", boolean.class); 
    161164         
     
    312315 
    313316    public void determineConfigDirH() { 
     317        String baseDir = context.getServletContext().getRealPath(""); 
     318         
    314319        if (absPath != null) { 
    315320            configDirH = new File(absPath); 
     
    317322        } 
    318323 
     324         
    319325        /* Only keep going for relative directory */ 
    320326        if (relPath == null) { 
     
    322328            //String classpath = System.getProperty("java.class.path"); 
    323329            //System.out.println(classpath); 
    324             relPath = "/WEB-INF/classes"; 
     330             
     331            if(new File(baseDir + "/WEB-INF/classes/" + CONFIGURATION_FILE_NAME).exists()) { 
     332                relPath = "/WEB-INF/classes"; 
     333            } else if( new File(baseDir + "/../resources/" + CONFIGURATION_FILE_NAME).exists()) { 
     334                relPath = "/../resources"; 
     335            } 
    325336        } //else { 
    326337          //  if (File.separator.equals("\\") 
     
    331342        //} 
    332343 
    333         String baseDir = context.getServletContext().getRealPath(""); 
    334  
    335344        configDirH = new File(baseDir + relPath); 
    336345 
  • trunk/geowebcache/src/test/java/org/geowebcache/layer/GridCalculatorTest.java

    r341 r388  
    238238    public void test0binarySearch() throws Exception { 
    239239        double[] resolutions = {8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0}; 
    240         int result = GridCalculator.binarySearchForResolution(resolutions, 5.04); 
     240        int result = GridCalculator.binarySearchForResolution(resolutions, 5.04, 0); 
    241241        assertEquals(3, result); 
    242242         
    243         result = GridCalculator.binarySearchForResolution(resolutions, 8.03); 
     243        result = GridCalculator.binarySearchForResolution(resolutions, 8.03, 0); 
    244244        assertEquals(0, result); 
    245245         
    246         result = GridCalculator.binarySearchForResolution(resolutions, 0.98); 
     246        result = GridCalculator.binarySearchForResolution(resolutions, 0.98, 0); 
    247247        assertEquals(7, result); 
    248248         
    249         result = GridCalculator.binarySearchForResolution(resolutions, 1.005); 
     249        result = GridCalculator.binarySearchForResolution(resolutions, 1.005, 0); 
    250250        assertEquals(7, result); 
    251251 
    252         result = GridCalculator.binarySearchForResolution(resolutions, 6.025); 
     252        result = GridCalculator.binarySearchForResolution(resolutions, 6.025, 0); 
    253253        assertEquals(2, result); 
    254254    } 
     
    256256    public void test1binarySearch() throws Exception { 
    257257        double[] resolutions = {12.0, 10.0, 6.0, 5.0, 4.0, 3.0, 1.0}; 
    258         int result = GridCalculator.binarySearchForResolution(resolutions, 5.04); 
     258        int result = GridCalculator.binarySearchForResolution(resolutions, 5.04, 0); 
    259259        assertEquals(3, result); 
    260260         
    261         result = GridCalculator.binarySearchForResolution(resolutions, 0.98); 
     261        result = GridCalculator.binarySearchForResolution(resolutions, 0.98, 0); 
    262262        assertEquals(6, result); 
    263263         
    264         result = GridCalculator.binarySearchForResolution(resolutions, 12.05); 
     264        result = GridCalculator.binarySearchForResolution(resolutions, 12.05, 0); 
    265265        assertEquals(0, result); 
    266266         
    267         result = GridCalculator.binarySearchForResolution(resolutions, 4.002); 
     267        result = GridCalculator.binarySearchForResolution(resolutions, 4.002, 0); 
    268268        assertEquals(4, result); 
    269269