'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _assign = require('lodash/assign');

var _assign2 = _interopRequireDefault(_assign);

var _methodsUtil = require('../../../_util/methods-util');

var _index = require('./index');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var XYZTile = function () {
  function XYZTile(iMapApi) {
    (0, _classCallCheck3['default'])(this, XYZTile);

    this.iMapApi = iMapApi;
    this.exports = iMapApi && iMapApi.exports ? iMapApi.exports : {};
    this.proxyURL = iMapApi.proxyURL || '';
    this.options = (0, _extends3['default'])({}, _index.defaultServicesSourceOptions, _index.defaultServicesLayerOptions);
  }

  /**
   * 获取解析XYZTile服务的图层对象
   * @param {String} id 图层Id名称
   * @param {String} name 图层Name名
   * @param {String} url 服务地址
   * @param {Object} options 解析服务的参数选项
   */


  (0, _createClass3['default'])(XYZTile, [{
    key: 'getLayer',
    value: function getLayer(id) {
      var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

      var _this = this;

      var url = arguments[2];
      var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

      var opts = (0, _assign2['default'])(this.options, options);
      // 获取图层对象
      var layer = (0, _index.getServicesBaseLayer)(opts);
      layer.id = id;
      // 获取图层数据源
      var layerSource = (0, _index.getServicesLayerSource)(opts);
      !layerSource.tileSize && (layerSource.tileSize = layerSource.defaultTileSize);
      // 实际服务源地址
      var isProxyUrl = (0, _methodsUtil.isBooleanFlase)(opts.proxy) ? false : true;
      var urls = (0, _methodsUtil.isArray)(url) ? url : [url];
      layerSource.tiles = urls.map(function (item) {
        return isProxyUrl ? '' + _this.proxyURL + item : item;
      });
      layer.source = layerSource;
      // 存储图层的服务类型
      layer.metadata.serviceType = 'XYZTile';
      layer.metadata.serviceName = name || '';
      return layer;
    }
  }]);
  return XYZTile;
}(); /**
      * @文件说明: Services.XYZTile XYZ瓦片服务
      * @创建人: pjtools@vip.qq.com
      * @创建时间: 2020-03-22 21:34:04
      */

exports['default'] = XYZTile;