"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var BD_FACTOR = 3.14159265358979324 * 3000.0 / 180.0;
var PI = 3.1415926535897932384626;
var RADIUS = 6378245.0;
var EE = 0.00669342162296594323;
var CoordTransform = /*#__PURE__*/function () {
  function CoordTransform() {
    _classCallCheck(this, CoordTransform);
  }
  _createClass(CoordTransform, null, [{
    key: "BD09ToGCJ02",
    value:
    /**
     * BD-09 To GCJ-02
     * @param lng
     * @param lat
     * @returns {number[]}
     */
    function BD09ToGCJ02(lng, lat) {
      var x = +lng - 0.0065;
      var y = +lat - 0.006;
      var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * BD_FACTOR);
      var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * BD_FACTOR);
      var gg_lng = z * Math.cos(theta);
      var gg_lat = z * Math.sin(theta);
      return [gg_lng, gg_lat];
    }

    /**
     * GCJ-02 To BD-09
     * @param lng
     * @param lat
     * @returns {number[]}
     * @constructor
     */
  }, {
    key: "GCJ02ToBD09",
    value: function GCJ02ToBD09(lng, lat) {
      var _lat = +lat;
      var _lng = +lng;
      var z = Math.sqrt(_lng * _lng + _lat * _lat) + 0.00002 * Math.sin(_lat * BD_FACTOR);
      var theta = Math.atan2(_lat, _lng) + 0.000003 * Math.cos(_lng * BD_FACTOR);
      var bd_lng = z * Math.cos(theta) + 0.0065;
      var bd_lat = z * Math.sin(theta) + 0.006;
      return [bd_lng, bd_lat];
    }

    /**
     * WGS-84 To GCJ-02
     * @param lng
     * @param lat
     * @returns {number[]}
     */
  }, {
    key: "WGS84ToGCJ02",
    value: function WGS84ToGCJ02(lng, lat) {
      var _lat = +lat;
      var _lng = +lng;
      if (this.out_of_china(_lng, _lat)) {
        return [_lng, _lat];
      } else {
        var d = this.delta(_lng, _lat);
        return [_lng + d[0], _lat + d[1]];
      }
    }

    /**
     * GCJ-02 To WGS-84
     * @param lng
     * @param lat
     * @returns {number[]}
     * @constructor
     */
  }, {
    key: "GCJ02ToWGS84",
    value: function GCJ02ToWGS84(lng, lat) {
      var _lat = +lat;
      var _lng = +lng;
      if (this.out_of_china(_lng, _lat)) {
        return [_lng, _lat];
      } else {
        var d = this.delta(_lng, _lat);
        var mgLng = _lng + d[0];
        var mgLat = _lat + d[1];
        return [_lng * 2 - mgLng, _lat * 2 - mgLat];
      }
    }

    /**
     *
     * @param lng
     * @param lat
     * @returns {number[]}
     */
  }, {
    key: "delta",
    value: function delta(lng, lat) {
      var dLng = this.transformLng(lng - 105, lat - 35);
      var dLat = this.transformLat(lng - 105, lat - 35);
      var radLat = lat / 180 * PI;
      var magic = Math.sin(radLat);
      magic = 1 - EE * magic * magic;
      var sqrtMagic = Math.sqrt(magic);
      dLng = dLng * 180 / (RADIUS / sqrtMagic * Math.cos(radLat) * PI);
      dLat = dLat * 180 / (RADIUS * (1 - EE) / (magic * sqrtMagic) * PI);
      return [dLng, dLat];
    }

    /**
     *
     * @param lng
     * @param lat
     * @returns {number}
     */
  }, {
    key: "transformLng",
    value: function transformLng(lng, lat) {
      var _lat = +lat;
      var _lng = +lng;
      var ret = 300.0 + _lng + 2.0 * _lat + 0.1 * _lng * _lng + 0.1 * _lng * _lat + 0.1 * Math.sqrt(Math.abs(_lng));
      ret += (20.0 * Math.sin(6.0 * _lng * PI) + 20.0 * Math.sin(2.0 * _lng * PI)) * 2.0 / 3.0;
      ret += (20.0 * Math.sin(_lng * PI) + 40.0 * Math.sin(_lng / 3.0 * PI)) * 2.0 / 3.0;
      ret += (150.0 * Math.sin(_lng / 12.0 * PI) + 300.0 * Math.sin(_lng / 30.0 * PI)) * 2.0 / 3.0;
      return ret;
    }

    /**
     *
     * @param lng
     * @param lat
     * @returns {number}
     */
  }, {
    key: "transformLat",
    value: function transformLat(lng, lat) {
      var _lat = +lat;
      var _lng = +lng;
      var ret = -100.0 + 2.0 * _lng + 3.0 * _lat + 0.2 * _lat * _lat + 0.1 * _lng * _lat + 0.2 * Math.sqrt(Math.abs(_lng));
      ret += (20.0 * Math.sin(6.0 * _lng * PI) + 20.0 * Math.sin(2.0 * _lng * PI)) * 2.0 / 3.0;
      ret += (20.0 * Math.sin(_lat * PI) + 40.0 * Math.sin(_lat / 3.0 * PI)) * 2.0 / 3.0;
      ret += (160.0 * Math.sin(_lat / 12.0 * PI) + 320 * Math.sin(_lat * PI / 30.0)) * 2.0 / 3.0;
      return ret;
    }

    /**
     *
     * @param lng
     * @param lat
     * @returns {boolean}
     */
  }, {
    key: "out_of_china",
    value: function out_of_china(lng, lat) {
      var _lat = +lat;
      var _lng = +lng;
      return !(_lng > 73.66 && _lng < 135.05 && _lat > 3.86 && _lat < 53.55);
    }
  }]);
  return CoordTransform;
}();
var _default = CoordTransform;
exports["default"] = _default;
//# sourceMappingURL=CoordTransform.js.map
