Changeset 371

Show
Ignore:
Timestamp:
09/03/08 14:02:44 (4 months ago)
Author:
arneke
Message:

Attempt to add parent linking capability to KML and fix debuggrid. Google Earth tends to chew up all CPU with it, so commented out again.

Location:
trunk/geowebcache/src/main/java/org/geowebcache/service/kml
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/geowebcache/src/main/java/org/geowebcache/service/kml/KMLDebugGridLayer.java

    r370 r371  
    1818 
    1919import java.io.IOException; 
     20import java.util.Hashtable; 
    2021import java.util.List; 
    2122import java.util.Properties; 
    22 import java.util.Vector; 
    2323 
    2424import javax.servlet.http.HttpServletResponse; 
    2525 
    26 import org.apache.commons.logging.Log; 
    27 import org.apache.commons.logging.LogFactory; 
    2826import org.geowebcache.GeoWebCacheException; 
    2927import org.geowebcache.cache.Cache; 
     
    3230import org.geowebcache.cache.CacheKey; 
    3331import org.geowebcache.layer.BadTileException; 
     32import org.geowebcache.layer.Grid; 
    3433import org.geowebcache.layer.SRS; 
    3534import org.geowebcache.layer.TileLayer; 
    3635import org.geowebcache.mime.MimeType; 
    37 import org.geowebcache.mime.XMLMime; 
    3836import org.geowebcache.tile.Tile; 
    3937import org.geowebcache.util.wms.BBOX; 
     
    5250    public static final int IS_KMZ = 100; 
    5351     
    54     private static Log log = LogFactory.getLog(org.geowebcache.service.kml.KMLDebugGridLayer.class); 
     52    //private static Log log = LogFactory.getLog(org.geowebcache.service.kml.KMLDebugGridLayer.class); 
    5553     
    5654    private static KMLDebugGridLayer instance; 
     
    6159    public void lazyLayerInitialization(CacheFactory c){ 
    6260        //blah 
     61 
    6362    } 
    6463     
     
    6665     
    6766    private KMLDebugGridLayer() { 
    68          
     67        super.grids = new Hashtable<SRS,Grid>(); 
     68        grids.put(SRS.getEPSG4326(), new Grid(SRS.getEPSG4326(),BBOX.WORLD4326, BBOX.WORLD4326, null)); 
    6969    } 
    7070     
     
    7777     
    7878    public void acquireLayerLock() { 
    79         // TODO Auto-generated method stub 
    80         //log.warn("acquireLayerLock()"); 
    8179    } 
    8280 
    8381    public void destroy() { 
    84         // TODO Auto-generated method stub 
    85         //log.warn("destroy()"); 
    8682    } 
    8783 
    8884    public Tile doNonMetatilingRequest(Tile tile) throws GeoWebCacheException { 
    89         // TODO Auto-generated method stub 
    90         //log.warn("doNonMetatilingRequest(int[] gridLoc, int idx,String formatStr)"); 
    91         return null; 
    92     } 
    93  
    94     public BBOX getBboxForGridLoc(int srsIdx, int[] gridLoc) { 
    95         // TODO Auto-generated method stub 
    96         //log.warn("done - getBboxForGridLoc(int srsIdx, int[] gridLoc)"); 
    97          
    98         double tileWidth = 180.0 / Math.pow(2, gridLoc[2]); 
    99  
    100         BBOX bbox = new BBOX( 
    101                      -180.0 + tileWidth * gridLoc[0], 
    102                      -90.0 + tileWidth * gridLoc[1], 
    103                      -180.0 + tileWidth * (gridLoc[0] + 1), 
    104                      -90.0 + tileWidth * (gridLoc[1] + 1)); 
    105          
    106         return bbox; 
    107     } 
    108  
    109     public BBOX getBounds(int srsIdx) { 
    110         // TODO Auto-generated method stub 
    111         //log.warn("done - getBounds"); 
     85        return null; 
     86    } 
     87 
     88    public BBOX getBounds(SRS srs) { 
    11289        return new BBOX(-180.0, -90.0, 180.0, 90.0); 
    11390    } 
    11491 
    11592    public Cache getCache() { 
    116         // TODO Auto-generated method stub 
    117         //log.warn("getCache"); 
    11893        return null; 
    11994    } 
    12095 
    12196    public CacheKey getCacheKey() { 
    122         // TODO Auto-generated method stub 
    123         //log.warn("done - getCacheKey"); 
    12497        return this; 
    12598    } 
    12699 
    127100    public String getCachePrefix() { 
    128         // TODO Auto-generated method stub 
    129         //log.warn("done - getCachePrefix"); 
    130         return null; 
    131     } 
    132  
    133     public int[][] getCoveredGridLevels(int srsIdx, BBOX bounds) { 
    134         // TODO Auto-generated method stub 
    135         //log.warn("getCoveredGridLevels(int srsIdx, BBOX bounds)"); 
    136101        return null; 
    137102    } 
    138103 
    139104    public MimeType getDefaultMimeType() { 
    140         // TODO Auto-generated method stub 
    141         //log.warn("getDefaultMimeType()"); 
    142         return null; 
    143     } 
    144  
    145     public int[] getGridLocForBounds(int srsIdx, BBOX bounds) 
    146             throws BadTileException { 
    147         // TODO Auto-generated method stub 
    148         //log.warn("getGridLocForBounds(int srsIdx, BBOX bounds)"); 
    149105        return null; 
    150106    } 
    151107 
    152108    public int[] getMetaTilingFactors() { 
    153         // TODO Auto-generated method stub 
    154         //log.warn("getMetaTilingFactors()"); 
    155109        return null; 
    156110    } 
    157111 
    158112    public List <MimeType> getMimeTypes() { 
    159         // TODO Auto-generated method stub 
    160         //log.warn("getMimeTypes()"); 
    161113        return null; 
    162114    } 
    163115 
    164116    public String getName() { 
    165         // TODO Auto-generated method stub 
    166         //log.warn("done - getName()"); 
    167117        return "Debug grid"; 
    168118    } 
    169119 
    170120    public SRS[] getProjections() { 
    171         // TODO Auto-generated method stub 
    172         //log.warn("done - getProjections()"); 
    173          
    174121        SRS[] srsList = { SRS.getEPSG4326() }; 
    175122        return srsList; 
     
    177124 
    178125    public double[] getResolutions(int srsIdx) { 
    179         // TODO Auto-generated method stub 
    180         //log.warn("getResolutions()"); 
    181126        return null; 
    182127    } 
    183128 
    184129    public Tile getTile(Tile tile) 
    185             throws GeoWebCacheException, IOException { 
    186         // TODO Auto-generated method stub 
    187         //log.warn("getResponse(TileRequest tileRequest,ServiceRequest servReq, HttpServletResponse response)"); 
    188          
     130            throws GeoWebCacheException, IOException {         
    189131        int[] gridLoc = tile.getTileIndex(); 
    190132 
    191         BBOX bbox = this.getBboxForGridLoc(0, gridLoc); 
     133        BBOX bbox = this.getBboxForGridLoc(SRS.getEPSG4326(), gridLoc); 
    192134        
    193135        String data  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 
     
    226168    } 
    227169 
    228     public int getSRSIndex(SRS reqSRS) { 
    229         // TODO Auto-generated method stub 
    230         //log.warn("done - getSRSIndex"); 
    231         return 0; 
    232     } 
    233  
    234170    public String getStyles() { 
    235         // TODO Auto-generated method stub 
    236         //log.warn("getStyles()"); 
    237         return null; 
    238     } 
    239  
    240     public int[][] getZoomInGridLoc(int srsIdx, int[] gridLoc) { 
     171        return null; 
     172    } 
     173 
     174    public int[][] getZoomInGridLoc(SRS srs, int[] gridLoc) { 
    241175        //log.warn("done - getZoomInGridLoc(srsIdx, gridLoc)"); 
    242176         
     
    265199 
    266200    public int getZoomStart() { 
    267         // TODO Auto-generated method stub 
    268         //log.warn("getZoomStart()"); 
    269201        return 0; 
    270202    } 
    271203 
    272204    public int getZoomStop() { 
    273         // TODO Auto-generated method stub 
    274         //log.warn("getZoomStop()"); 
    275205        return 25; 
    276206    } 
    277207 
    278     public int[] getZoomedOutGridLoc(int srsIdx) { 
    279         // TODO Auto-generated method stub 
    280         //log.warn("done - getZoomedOutGridLoc"); 
    281         int[] zoomedOutGridLoc = new int[3]; 
    282         zoomedOutGridLoc[0] = -1; 
    283         zoomedOutGridLoc[1] = -1; 
    284         zoomedOutGridLoc[2] = -1; 
    285          
    286         return zoomedOutGridLoc; 
    287     } 
    288  
    289208    public Boolean initialize() { 
    290         // TODO Auto-generated method stub 
    291         //log.warn("initialize()"); 
    292209        return true; 
    293210    } 
    294211 
    295212    public Boolean isInitialized() { 
    296         // TODO Auto-generated method stub 
    297         //log.warn("isInitialized()"); 
    298213        return true; 
    299214    } 
     
    301216    public void putTile(Tile tile, Object ck, int[] gridLoc) 
    302217            throws CacheException { 
    303         // TODO Auto-generated method stub 
    304         //log.warn("putTile"); 
    305218    } 
    306219 
    307220    public void releaseLayerLock() { 
    308         // TODO Auto-generated method stub 
    309         //log.warn("releaseLayerLock()"); 
    310221    } 
    311222 
    312223    public void setExpirationHeader(HttpServletResponse response) { 
    313         // TODO Auto-generated method stub 
    314         //log.warn("setExpirationHeader"); 
    315224    } 
    316225 
    317226    public String supportsBbox(SRS srs, BBOX bounds) 
    318227            throws GeoWebCacheException { 
    319         // TODO Auto-generated method stub 
    320         //log.warn("supportsBbox"); 
    321228        return null; 
    322229    } 
    323230 
    324231    public boolean supportsFormat(String formatStr) throws GeoWebCacheException { 
    325         // TODO Auto-generated method stub 
    326         //log.warn("supportsFormat"); 
    327232        return false; 
    328233    } 
    329234 
    330235    public boolean supportsSRS(SRS srs) throws GeoWebCacheException { 
    331         // TODO Auto-generated method stub 
    332         //log.warn("supportsProjection"); 
    333         return false; 
    334     } 
    335  
    336     // Returns the KML for the tile, but not a cached KMZ overlay 
    337 //    public boolean tryCacheFetch(Tile tile) { 
    338 //        // TODO Auto-generated method stub 
    339 //        //log.warn("done - tryCacheFetch"); 
    340 //         
    341 //        Vector<Integer> lst = (Vector<Integer>) tile; 
    342 //         
    343 //        int kmz = lst.get(0); 
    344 //         
    345 //        if(kmz != KMLDebugGridLayer.IS_KMZ) { 
    346 //            return true; 
    347 //        } else { 
    348 //            System.out.println("OOPS"); 
    349 //        } 
    350 //         
    351 //        return false; 
    352 //    } 
     236        return false; 
     237    } 
    353238 
    354239    public boolean get(Tile tile, long ttl) throws CacheException { 
    355         // TODO Auto-generated method stub 
     240 
    356241        return true; 
    357242    } 
    358243 
    359244    public String getDefaultKeyBeanId() { 
    360         // TODO Auto-generated method stub 
     245 
    361246        return null; 
    362247    } 
    363248 
    364249    public String getDefaultPrefix(String param) throws CacheException { 
    365         // TODO Auto-generated method stub 
     250 
    366251        return null; 
    367252    } 
     
    369254     
    370255    public void init(Properties props) throws CacheException { 
    371         // TODO Auto-generated method stub 
     256 
    372257         
    373258    } 
    374259 
    375260    public boolean remove(Tile tile) throws CacheException { 
    376         // TODO Auto-generated method stub 
     261 
    377262        return false; 
    378263    } 
    379264 
    380265    public void removeAll() throws CacheException { 
    381         // TODO Auto-generated method stub 
     266 
    382267         
    383268    } 
     
    385270    /** Cache interface **/ 
    386271    public void set(Object key, Object obj, long ttl) throws CacheException { 
    387         // TODO Auto-generated method stub 
     272 
    388273         
    389274    } 
    390275 
    391276    public void setDefaultKeyBeanId(String defaultKeyBeanId) { 
    392         // TODO Auto-generated method stub 
     277 
    393278         
    394279    } 
    395280 
    396281    public void setUp(String cachePrefix) throws CacheException { 
    397         // TODO Auto-generated method stub 
     282 
    398283         
    399284    } 
     
    401286    public void setApplicationContext(ApplicationContext arg0) 
    402287            throws BeansException { 
    403         // TODO Auto-generated method stub 
     288 
    404289         
    405290    } 
     
    421306 
    422307    public int getType() { 
    423         // TODO Auto-generated method stub 
     308 
    424309        return 0; 
    425310    } 
    426311 
    427312    public void init() { 
    428         // TODO Auto-generated method stub 
     313 
    429314         
    430315    } 
    431316 
    432317    public void putTile(Tile tile) throws CacheException { 
    433         // TODO Auto-generated method stub 
     318 
    434319         
    435320    } 
    436321 
    437322    public void set(Tile tile, long ttl) throws CacheException { 
    438         // TODO Auto-generated method stub 
     323 
    439324         
    440325    } 
    441326 
    442327    public boolean tryCacheFetch(Tile tile) { 
    443         // TODO Auto-generated method stub 
     328 
    444329        return false; 
    445330    } 
     
    447332    public boolean get(CacheKey keyProto, Tile tile, long ttl) 
    448333            throws CacheException, GeoWebCacheException { 
    449         // TODO Auto-generated method stub 
     334 
    450335        return false; 
    451336    } 
    452337 
    453338    public boolean remove(CacheKey keyProto, Tile tile) throws CacheException { 
    454         // TODO Auto-generated method stub 
    455339        return false; 
    456340    } 
     
    458342    public void set(CacheKey keyProto, Tile tile, long ttl) 
    459343            throws CacheException, GeoWebCacheException { 
    460         // TODO Auto-generated method stub 
    461          
    462344    } 
    463345 
    464346    public Object createKey(Tile tile) { 
    465         // TODO Auto-generated method stub 
    466         return null; 
    467     } 
    468  
    469  
    470  
    471     @Override 
     347        return null; 
     348    } 
     349 
    472350    public void setCacheFactory(CacheFactory cacheFactory) { 
    473         // TODO Auto-generated method stub 
    474          
    475     } 
    476  
    477  
    478  
    479     @Override 
     351    } 
     352 
    480353    public BBOX getBboxForGridLoc(SRS srs, int[] gridLoc) { 
    481         // TODO Auto-generated method stub 
    482         return null; 
    483     } 
    484  
    485  
    486  
    487     @Override 
     354        double tileWidth = 180.0 / Math.pow(2, gridLoc[2]); 
     355 
     356        BBOX bbox = new BBOX( 
     357                     -180.0 + tileWidth * gridLoc[0], 
     358                     -90.0 + tileWidth * gridLoc[1], 
     359                     -180.0 + tileWidth * (gridLoc[0] + 1), 
     360                     -90.0 + tileWidth * (gridLoc[1] + 1)); 
     361         
     362        return bbox; 
     363    } 
     364 
    488365    public int[][] getCoveredGridLevels(SRS srs, BBOX bounds) { 
    489         // TODO Auto-generated method stub 
    490         return null; 
    491     } 
    492  
    493  
    494  
    495     @Override 
     366        return null; 
     367    } 
     368 
    496369    public int[] getGridLocForBounds(SRS srs, BBOX bounds) 
    497370            throws BadTileException { 
    498         // TODO Auto-generated method stub 
    499         return null; 
    500     } 
    501  
    502  
    503  
    504     @Override 
    505     public int[][] getZoomInGridLoc(SRS srs, int[] gridLoc) { 
    506         // TODO Auto-generated method stub 
    507         return null; 
    508     } 
    509  
    510  
    511  
    512     @Override 
     371        return null; 
     372    } 
     373 
    513374    public int[] getZoomedOutGridLoc(SRS srs) { 
    514         // TODO Auto-generated method stub 
    515         return null; 
    516     } 
    517  
    518     @Override 
     375        // log.warn("done - getZoomedOutGridLoc"); 
     376        int[] zoomedOutGridLoc = new int[3]; 
     377        zoomedOutGridLoc[0] = -1; 
     378        zoomedOutGridLoc[1] = -1; 
     379        zoomedOutGridLoc[2] = -1; 
     380 
     381        return zoomedOutGridLoc; 
     382 
     383    } 
     384 
    519385    public void seedTile(Tile tile, boolean tryCache) 
    520386            throws GeoWebCacheException, IOException { 
    521         // TODO Auto-generated method stub 
    522387         
    523388    } 
  • trunk/geowebcache/src/main/java/org/geowebcache/service/kml/KMLService.java

    r370 r371  
    1919import java.io.IOException; 
    2020import java.io.OutputStream; 
     21import java.util.Arrays; 
    2122 
    2223import javax.servlet.http.HttpServletRequest; 
     
    147148        if(tile.getLayerId().equalsIgnoreCase(KMLDebugGridLayer.LAYERNAME)) { 
    148149            tile.setHint(HINT_DEBUGGRID); 
    149         } 
    150          
     150            tile.setRequestHandler(Tile.RequestHandler.SERVICE); 
     151        } 
     152         
     153        //System.out.println(Arrays.toString(tile.getTileIndex()) + " " + tile.servletReq.getHeader("referer")); 
    151154        return tile; 
    152155    } 
     
    171174        } 
    172175        tile.setTileLayer(layer); 
    173          
    174176         
    175177        //TODO this needs to be done more nicely 
     
    406408                tile.getMimeType() instanceof ImageMime)); 
    407409 
     410        buf.append("\n<!-- Network links to subtiles -->\n"); 
    408411        // 2) Network links, only to tiles within bounds 
    409412        int[][] linkGridLocs = tileLayer.getZoomInGridLoc(srs, gridLoc); 
     
    421424                        linkGridLocs[i]); 
    422425                 
    423                 // Always use absolute URLs for these 
    424                 String gridLocUrl = tile.getUrlPrefix() + gridLocString(linkGridLocs[i])  
    425                 +"." +tile.getMimeType().getFileExtension()+ "." + tile.getWrapperMimeType().getFileExtension(); 
    426  
    427426                String gridLocStr = gridLocString(linkGridLocs[i]); 
    428427                 
    429                 buf.append(createNetworkLinkElement(tileLayer, linkBbox, gridLocUrl, gridLocStr)); 
     428                // Always use absolute URLs for these 
     429                String gridLocUrl = tile.getUrlPrefix()  
     430                    + gridLocStr +"." +tile.getMimeType().getFileExtension() 
     431                    + "." + tile.getWrapperMimeType().getFileExtension(); 
     432 
     433                buf.append(createNetworkLinkElement(tileLayer, linkBbox, gridLocUrl, gridLocStr,-1)); 
    430434                //moreData++; 
    431435            } 
    432436        } 
    433  
    434         // 3) Overlay, should be relative  
     437         
     438// The following was a nice try, unfortunately Google Earth appears to go to 100% CPU etc... 
     439// and the pane on the left hand side with the tile tree doesn't really know what to do 
     440// with new parents.... 
     441// 
     442//        buf.append("\n<!-- Network link to parent or sibling tile -->\n"); 
     443//        // 4) Add link to parent or sibling tile 
     444//        //    Just in case someone comes in via a search result 
     445//        //    Sibling = other hemisphere, when at zoom level 0 
     446//        if(gridLoc[2] >= 0) { 
     447//            int z = gridLoc[2] - 1; 
     448//            int x = Math.min((int) Math.round((gridLoc[0] -0.01) / 2.0), 2*(1 << z) - 1); 
     449//            int y = Math.min((int) Math.round((gridLoc[1] -0.01) / 2.0), (1 << z) - 1); 
     450//             
     451//             
     452//            // Override if we're linking to the sibling top tile 
     453//            if(gridLoc[2] == 0 && tile.getLayer().getZoomedOutGridLoc(srs)[2] == -1) { 
     454//                if(gridLoc[0] == 0) { 
     455//                    x = 1; 
     456//                } else { 
     457//                    x = 0; 
     458//                } 
     459//                y = 0; 
     460//                z = 0; 
     461//            } 
     462//             
     463//            int[] parentGridLoc = {x,y,z}; 
     464//             
     465//            BBOX linkBbox = tileLayer.getBboxForGridLoc(srs,parentGridLoc); 
     466//             
     467//            // Absolute URLs for these 
     468//            String gridLocStr = gridLocString(parentGridLoc); 
     469//             
     470//            String gridLocUrl = tile.getUrlPrefix()  
     471//                + gridLocStr +"." +tile.getMimeType().getFileExtension() 
     472//                + "." + tile.getWrapperMimeType().getFileExtension(); 
     473//             
     474//            buf.append(createNetworkLinkElement(tileLayer, linkBbox, gridLocUrl, gridLocStr, 385)); 
     475//        } 
     476         
     477        buf.append("\n<!-- Network link to actual content -->\n"); 
     478        // 5) Overlay, should be relative  
    435479        if (tile.getMimeType() instanceof ImageMime) { 
    436480            buf.append( 
     
    442486            String gridLocStr = gridLocString(gridLoc); 
    443487            String gridLocUrl = gridLocStr + "." + tile.getMimeType().getFileExtension(); 
     488             
    444489            if(isPackaged) { 
    445490                gridLocUrl = "data_" + gridLocUrl; 
    446491            } 
    447             buf.append(createNetworkLinkElement(tileLayer, bbox, gridLocUrl, gridLocStr)); 
     492             
     493            int maxLodPixels = -1; 
     494            if(tile.getLayer() instanceof KMLDebugGridLayer) { 
     495                maxLodPixels = 385; 
     496            } 
     497             
     498            buf.append(createNetworkLinkElement(tileLayer, bbox, gridLocUrl, gridLocStr, maxLodPixels)); 
    448499        } 
    449500 
     
    489540     */ 
    490541    private static String createNetworkLinkElement( 
    491             TileLayer layer, BBOX bbox, String gridLocUrl, String tileIdx) { 
    492          
    493         int maxLodPixels = -1; 
    494          
    495          
    496         // Hack 
    497         if(layer instanceof KMLDebugGridLayer && gridLocUrl.startsWith("data_")) { 
    498             maxLodPixels = 385; 
    499         } 
     542            TileLayer layer, BBOX bbox, String gridLocUrl, String tileIdx, int maxLodPixels) { 
    500543       
    501544        String xml = "\n<NetworkLink>"