"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _BaiduMercatorTilingScheme = _interopRequireDefault(require("./BaiduMercatorTilingScheme"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _Cesium = Cesium,
  Cartesian2 = _Cesium.Cartesian2,
  WebMercatorTilingScheme = _Cesium.WebMercatorTilingScheme,
  DeveloperError = _Cesium.DeveloperError,
  ImageryProvider = _Cesium.ImageryProvider;
;
var URL = {
  IMG: 'http://shangetu{s}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46',
  VEC: 'http://online{s}.map.bdimg.com/tile/?qt=tile&x={x}&y={y}&z={z}&styles=sl&v=020',
  CUSTOM: 'http://api{s}.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&scale=1&customid={style}'
};
var BaiduImageryProvider = /*#__PURE__*/function () {
  function BaiduImageryProvider() {
    var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    _classCallCheck(this, BaiduImageryProvider);
    this._url = options.url || URL[options.style || 'CUSTOM'];
    this._tileWidth = 256;
    this._tileHeight = 256;
    this._maximumLevel = 18;
    this._crs = options.crs || 'BD09';
    if (options.crs === 'WGS84') {
      var resolutions = [];
      for (var i = 0; i < 19; i++) {
        resolutions[i] = 256 * Math.pow(2, 18 - i);
      }
      this._tilingScheme = new _BaiduMercatorTilingScheme["default"]({
        resolutions: resolutions,
        rectangleSouthwestInMeters: new Cartesian2(-20037726.37, -12474104.17),
        rectangleNortheastInMeters: new Cartesian2(20037726.37, 12474104.17)
      });
    } else {
      this._tilingScheme = new WebMercatorTilingScheme({
        rectangleSouthwestInMeters: new Cartesian2(-33554054, -33746824),
        rectangleNortheastInMeters: new Cartesian2(33554054, 33746824)
      });
    }
    this._rectangle = this._tilingScheme.rectangle;
    this._credit = undefined;
    this._style = options.style || 'normal';
  }
  _createClass(BaiduImageryProvider, [{
    key: "url",
    get: function get() {
      return this._url;
    }
  }, {
    key: "token",
    get: function get() {
      return this._token;
    }
  }, {
    key: "tileWidth",
    get: function get() {
      if (!this.ready) {
        throw new DeveloperError('tileWidth must not be called before the imagery provider is ready.');
      }
      return this._tileWidth;
    }
  }, {
    key: "tileHeight",
    get: function get() {
      if (!this.ready) {
        throw new DeveloperError('tileHeight must not be called before the imagery provider is ready.');
      }
      return this._tileHeight;
    }
  }, {
    key: "maximumLevel",
    get: function get() {
      if (!this.ready) {
        throw new DeveloperError('maximumLevel must not be called before the imagery provider is ready.');
      }
      return this._maximumLevel;
    }
  }, {
    key: "minimumLevel",
    get: function get() {
      if (!this.ready) {
        throw new DeveloperError('minimumLevel must not be called before the imagery provider is ready.');
      }
      return 0;
    }
  }, {
    key: "tilingScheme",
    get: function get() {
      if (!this.ready) {
        throw new DeveloperError('tilingScheme must not be called before the imagery provider is ready.');
      }
      return this._tilingScheme;
    }
  }, {
    key: "rectangle",
    get: function get() {
      if (!this.ready) {
        throw new DeveloperError('rectangle must not be called before the imagery provider is ready.');
      }
      return this._rectangle;
    }
  }, {
    key: "ready",
    get: function get() {
      return !!this._url;
    }
  }, {
    key: "credit",
    get: function get() {
      return this._credit;
    }
  }, {
    key: "hasAlphaChannel",
    get: function get() {
      return true;
    }
  }, {
    key: "getTileCredits",
    value: function getTileCredits(x, y, level) {}
  }, {
    key: "requestImage",
    value: function requestImage(x, y, level) {
      if (!this.ready) {
        throw new DeveloperError('requestImage must not be called before the imagery provider is ready.');
      }
      var xTiles = this._tilingScheme.getNumberOfXTilesAtLevel(level);
      var yTiles = this._tilingScheme.getNumberOfYTilesAtLevel(level);
      var url = this._url.replace('{z}', level).replace('{s}', String(1)).replace('{style}', this._style);
      if (this._crs === 'WGS84') {
        url = url.replace('{x}', String(x)).replace('{y}', String(-y));
      } else {
        url = url.replace('{x}', String(x - xTiles / 2)).replace('{y}', String(yTiles / 2 - y - 1));
      }
      return ImageryProvider.loadImage(this, url);
    }
  }]);
  return BaiduImageryProvider;
}();
var _default = BaiduImageryProvider;
exports["default"] = _default;
//# sourceMappingURL=BaiduImageryProvider.js.map
