package org.geotools.tile.impl.osm;

/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2015-2017, Open Source Geospatial Foundation (OSGeo)
 *    (C) 2004-2008, Refractions Research Inc.
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 */
//package org.geotools.tile.impl.osm;

import java.io.File;
import org.geotools.tile.TileFactory;
import org.geotools.tile.impl.WebMercatorTileService;
import org.geotools.tile.TileServiceWepsIf;
import org.geotools.tile.util.CachedImageLoaderWeps;
import static usda.weru.util.About.getWepsCacheDirTiles;

/**
 * The tile service for the OpenStreetMap family.
 *
 * @author Tobias Sauerwein
 * @author Ugo Taddei
 * @since 12
 */
public class OSMServiceWeps extends WebMercatorTileService implements TileServiceWepsIf {

    private static final TileFactory tileFactory = new OSMTileFactoryWeps();

    private static double[] scaleList = {
        Double.NaN,
        Double.NaN,
        147914381,
        73957190,
        36978595,
        18489297,
        9244648,
        4622324,
        2311162,
        1155581,
        577790,
        288895,
        144447,
        72223,
        36111,
        18055,
        9027,
        4513,
        2256,
        1128,
        564,
        282,
        141,
        70
    };

    public OSMServiceWeps (String name, String baseUrl) {
        super(name, baseUrl);
        
        // WEPS
        File cacheDir = initCacheDir ();
        setCacheLoader(new CachedImageLoaderWeps(cacheDir));
    }

    @Override
    public File initCacheDir () {
        File cacheDir = getWepsCacheDirTiles ();
        if (getBaseUrl().contains("tile.openstreetmap.org")) {
            cacheDir = new File (cacheDir, "openstreetmap");
        } else {
            cacheDir = new File (cacheDir, "other");
        }
        cacheDir.mkdirs();
        return cacheDir;
    }

    @Override
    public double[] getScaleList() {
        return scaleList;
    }

    @Override
    public TileFactory getTileFactory() {
        return tileFactory;
    }

    // Weps
    CachedImageLoaderWeps cachedImageLoader = null;
    @Override
    public void setCacheLoader(CachedImageLoaderWeps cl) {
        cachedImageLoader = cl;
    }

    @Override
    public CachedImageLoaderWeps getCacheLoader() {
        return cachedImageLoader;
    }

}
