#ifndef GOOGLE_TILE_H
#define GOOGLE_TILE_H

#include <opencv2/opencv.hpp>
#include <string>
#include <vector>
#include "StitchStruct.h"
using std::vector;
using std::string;


struct TileIndex
{
    int x;
    int y;
    int z;
};

struct TileBox
{
    double north;
    double south;
    double east;
    double west;
};



// 瓦片信息
struct TileInfo
{
    TileIndex ind;
    std::string tileName;
    std::string href;//相对路径
    TileBox boxLatLon;
    RECT32S boxInPan;
    SINT32 nStatus;//状态:0-未输出  1-已输出  2-已优化并输出
};

// 标准web瓦片大小
const int TILE_SIZE = 256;

class googleTile
{
public:
    googleTile();
    ~googleTile();

public:
    // 输出kml png
    void ExportGeoPng(cv::Mat _pan, TileInfo info, std::string dir);

    // 输出tile组
    void ExportTileSet(cv::Mat _pan, cv::Mat _panMask, vector<TileInfo> taskTilesVec, std::string dir, std::string fileString);

    // 输出单个tile
    void ExportOneTile(cv::Mat _pan, TileInfo tile, std::string dir, std::string fileString);

    // 使用感兴趣区大瓦片计算小瓦片覆盖表
    vector<TileInfo> CalcTileOverlayVec(TileInfo areaInfo,  int panWidth, int panHeight);

    // 计算给定分辨率最接近的瓦片等级,mp单位 米/像素
    int ZoomLevel(float mp);

private:
    TileIndex LatLonToTile(double latitude, double longitude, int zoomLevel);
    // 瓦片编号对应的信息
    TileBox GetTileBox(TileIndex ind);

    void WriteKml(vector<TileInfo> tiles, string filePath);

};

#endif // GOOGLE_TILE_H
