import { MapLayerImageryProvider, MapLayerSourceStatus } from "../../../../tile/internal";
const levelToken = "{level}";
const rowToken = "{row}";
const columnToken = "{column}";
/**  Provide tiles from a url template in the a generic format ... i.e. https://b.tile.openstreetmap.org/{level}/{column}/{row}.png
*/
export class TileUrlImageryProvider extends MapLayerImageryProvider {
    constructor(settings) {
        super(settings, true);
    }
    static validateUrlTemplate(template) {
        return { status: (template.indexOf(levelToken) > 0 && template.indexOf(columnToken) > 0 && template.indexOf(rowToken) > 0) ? MapLayerSourceStatus.Valid : MapLayerSourceStatus.InvalidUrl };
    }
    // construct the Url from the desired Tile
    async constructUrl(row, column, level) {
        let url = this._settings.url;
        if (TileUrlImageryProvider.validateUrlTemplate(url).status !== MapLayerSourceStatus.Valid) {
            if (url.lastIndexOf("/") !== url.length - 1)
                url = `${url}/`;
            url = `${url}{level}/{column}/{row}.png`;
        }
        const tmpUrl = url.replace(levelToken, level.toString()).replace(columnToken, column.toString()).replace(rowToken, row.toString());
        return this.appendCustomParams(tmpUrl);
    }
}
//# sourceMappingURL=TileUrlImageryProvider.js.map