import * as d3Geo from 'd3-geo';
import {NextApiHandler} from 'next';

const testHandler: NextApiHandler = async (req, res) => {
  const mercator = d3Geo.geoMercator()

  let lambda, phi;
  let sx;
  let sy;
  let q;

  [lambda, phi] = mercator.invert!([0, -128])!
  sx = 64
  sy = 32
  q = ((90 - phi) / 180 * sy | 0) * sx + ((180 + lambda) / 360 * sx | 0) << 2;
  console.log(q);

  // [lambda, phi] = mercator.invert!([63, 0])!
  // sx = 64
  // sy = 32
  // q = ((90 - phi) / 180 * sy | 0) * sx + ((180 + lambda) / 360 * sx | 0) << 2;
  // console.log(q);
  //
  // [lambda, phi] = mercator.invert!([0, 16])!
  // sx = 64
  // sy = 32
  // q = ((90 - phi) / 180 * sy | 0) * sx + ((180 + lambda) / 360 * sx | 0) << 2;
  // console.log(q);

  res.json(0)
}

export default testHandler;
