package com.sysu.admin.utils.shape;

import com.alibaba.fastjson.JSON;

/**
 * @author shu hao
 * @description:
 * @date 2022/5/30 9:21
 */
public class TileUtil {

    public static void main(String[] args) {

        System.out.println(JSON.toJSONString(getRowColNum(new double[]{100,100}, 256, 300)));
        System.out.println(JSON.toJSONString(getRowColNum(new double[]{100,72001}, 256, 300)));
        System.out.println(JSON.toJSONString(getRowColNum(new double[]{72001,72001}, 256, 300)));

    }

    /**
     * 计算瓦片row col
     * @param xy  当前 坐标
     * @param tileSize  瓦片的按大小 一般256 x 256
     * @param resolution 一像素代表的实际距离
     * @return
     */
    public static int[] getRowColNum(double[] xy, int tileSize, double resolution){
        int[] result = {0,0};
        result[0] = (int)Math.floor(xy[0]/( tileSize * resolution));
        result[1] = (int)Math.floor(xy[1]/( tileSize * resolution));
        return result;
    }

}
