import axios from 'axios'
import { MVT, proj, proj4 } from 'ol'


let mvt = new MVT();

(async function () {
  var instance = axios.create({
    responseType: 'blob'
  })

  // let url = 'https://osm2vectortiles-0.tileserver.com/v2/1/0/0.pbf';

  // https://a.tiles.mapbox.com/v4/mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7/15/26722/14305.vector.pbf?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA
  let url = '//localhost:3000/8192-8447.pbf';

  let res = await instance.get(url)

  var reader = new FileReader();
  reader.readAsArrayBuffer(res.data);
  reader.onload = function (e) {
    let features = mvt.readFeatures(reader.result)

    console.log(features)
    
    let lp = proj.transform(
      features[10].flatCoordinates_, 
      new proj.Projection({ code: 'EPSG:4326' }),
      new proj.Projection({ code: 'EPSG:4326' })
    );

    console.log(features[10].flatCoordinates_);
    console.log('--->', lp);

    var c = '36548279.19';
    var d = '2557986.78';
    var xyCd = [c, d];
    // 假如从4490的转到3度带的36度带位置，查询36度带处的参考为2360
    xyCd = proj.transform(xyCd, new proj.Projection({ code: 'EPSG:2360' }),
      new proj.Projection({ code: 'EPSG:4490' }));
    
    console.log(xyCd)
  }

})();

