All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.cloudfarming.client.geoviewer.jxmap.map.cache.CacheUriTranslator Maven / Gradle / Ivy

Go to download

AgroSense geoviewer JXMap implementation. Contains a map/geoviewer TopComponent based on the JXMap classes from swingx.

The newest version!
/**
 * Copyright (C) 2008-2012 AgroSense Foundation.
 *
 * AgroSense is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
 * this software, see the FLOSS License Exception
 * .
 *
 * AgroSense is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with AgroSense.  If not, see .
 */
package nl.cloudfarming.client.geoviewer.jxmap.map.cache;

import java.net.URI;

/**
 * Translate UIR of requested Tile to {@link TileCacheInfo}, where information are stored
 *
 * @author Frantisek Post
 */
public class CacheUriTranslator {

    public static final String TILE_EXTENSION = ".png";
    public static final String FILE_NAME_FORMAT = "%dx%d" + TILE_EXTENSION;
    
    private CacheUriTranslator() {
    }
    
    public static synchronized TileCacheInfo getCacheInfo(URI uri) {
        assert uri != null;
        
        String path = uri.getPath();
        
        if (path != null && path.endsWith(TILE_EXTENSION)) {
            if (path.startsWith("/")) {
                path = path.substring(1); //remove slash
            }
            String xyZoom = path.substring(0, path.indexOf(TILE_EXTENSION));
            String[] coordinates = xyZoom.split("/");
            if (coordinates != null && coordinates.length == 3) {
                int zoom = Integer.parseInt(coordinates[0]);
                int x = Integer.parseInt(coordinates[1]);
                int y = Integer.parseInt(coordinates[2]);
                return new TileCacheInfo(zoom, x, y);
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy