"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.getSign = exports["default"] = exports.IRSLabelImageryProvider = void 0;
var _cesium = require("cesium");
var _cryptoJs = _interopRequireDefault(require("crypto-js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
// 获取标识
var getSign = exports.getSign = function getSign(accessKey, secretKey) {
  // 默认的是湖州一期项目上申请的ak,sk,其他项目最好自己申请电子地图组件
  accessKey = accessKey || "111438d1e25b4928a38f851ede290777"; // 修改自己申请的accessKey，ak、sk不要弄反
  secretKey = secretKey || "c2c6d32f91864c68bba0e0ca1ba61d14"; // 修改自己申请的secretKey，ak、sk不要弄反

  //和普通base64加密不一样
  function base64UrlEncode(str) {
    var encodedSource = _cryptoJs["default"].enc.Base64.stringify(str);
    var reg = new RegExp('/', 'g');
    encodedSource = encodedSource.replace(/=+$/, '').replace(/\+/g, '-').replace(reg, '_');
    return encodedSource;
  }
  var header = JSON.stringify({
    "alg": "HS256",
    "typ": "JWT"
  });

  //ak、sk和生成token建议在后端，避免前端调用的时候泄露
  var payload = JSON.stringify({
    "key": accessKey,
    "exp": new Date().setHours(new Date().getHours() + 1)
  });
  var before_sign = base64UrlEncode(_cryptoJs["default"].enc.Utf8.parse(header)) + '.' + base64UrlEncode(_cryptoJs["default"].enc.Utf8.parse(payload));
  var signature = _cryptoJs["default"].HmacSHA256(before_sign, secretKey);
  signature = base64UrlEncode(signature);
  return before_sign + '.' + signature;
};
var STYLE = {
  'vec': 'tdt_biaozhunyangshi_2017',
  'dark': 'tdt_kejiganyangshi_2017',
  'green': 'tdt_qingxinyangshi_2017'
};
var TYPE = {
  'emap': 'vmap',
  'emap_lab': 'label'
};
var TIME = {
  'emap': 'IC33000020220811000009',
  'emap_lab': 'IC33000020220811000011'
};
var getOptions = function getOptions(options) {
  var layer = options.layer,
    ak = options.ak,
    sk = options.sk;
  var final_sign = getSign(ak, sk);
  var time = TIME[options.layer || 'emap'];
  var type = TYPE[options.layer || 'emap'];
  var style = STYLE[options.style || 'vec'];
  var url = "https://ibcdsg.zj.gov.cn:8443/restapi/prod/".concat(time, "/mapserver/").concat(type, "/WMTS/1.0/zjvmap/").concat(style, "?x-bg-auth-type=jwt_auth&jwt=").concat(final_sign);
  return {
    url: url,
    layer: layer,
    style: 'default',
    tileMatrixSetID: 'EPSG:4326',
    format: 'image/png',
    tilingScheme: new _cesium.GeographicTilingScheme(),
    maximumLevel: 21,
    tileMatrixLabels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21']
  };
};
var IRSLabelImageryProvider = exports.IRSLabelImageryProvider = /*#__PURE__*/function (_WebMapTileServiceIma) {
  function IRSLabelImageryProvider() {
    var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    _classCallCheck(this, IRSLabelImageryProvider);
    return _callSuper(this, IRSLabelImageryProvider, [getOptions(_objectSpread(_objectSpread({}, options), {}, {
      layer: 'emap_lab'
    }))]);
  }
  _inherits(IRSLabelImageryProvider, _WebMapTileServiceIma);
  return _createClass(IRSLabelImageryProvider);
}(_cesium.WebMapTileServiceImageryProvider);
var IRSImageryProvider = /*#__PURE__*/function (_WebMapTileServiceIma2) {
  function IRSImageryProvider() {
    var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    _classCallCheck(this, IRSImageryProvider);
    return _callSuper(this, IRSImageryProvider, [getOptions(_objectSpread(_objectSpread({}, options), {}, {
      layer: 'emap'
    }))]);
  }
  _inherits(IRSImageryProvider, _WebMapTileServiceIma2);
  return _createClass(IRSImageryProvider);
}(_cesium.WebMapTileServiceImageryProvider);
var _default = exports["default"] = IRSImageryProvider;
//# sourceMappingURL=IRSImageryProvider.js.map
