import Zondy from './Zondy'
import { defaultValue, getGUID } from '../util'
/**
* IGS地图服务图层
* @class TileMatrixSet
* @classdesc IGS地图图层
* @param {Object} options 构造参数
* @param {Extent} [options.extent = undefined] 图层范围
* @param {String} [options.id = getGUID()] 图块矩阵集id
* @param {String} [options.tileInfo = undefined] 切片信息
* @param {WMTSLayer} [options.layer = undefined] 图层
*/
class TileMatrixSet {
constructor(options) {
options = defaultValue(options, {})
/**
* 图层范围
* @member {Extent} TileMatrixSet.prototype.extent
*/
this.extent = defaultValue(options.extent, undefined)
/**
* 图块矩阵集id
* @member {String} TileMatrixSet.prototype.id
*/
this.id = defaultValue(options.id, getGUID())
/**
* 切片信息
* @member {String} TileMatrixSet.prototype.tileInfo
*/
this.tileInfo = defaultValue(options.tileInfo, undefined)
/**
* 图层
* @member {WMTSLayer} TileMatrixSet.prototype.layer
*/
this.layer = defaultValue(options.layer, undefined)
/**
* 矩阵集
* @member {Array} TileMatrixSet.prototype.tileMatrix
*/
this.tileMatrix = defaultValue(options.tileMatrix, [])
/**
* 矩阵identifier
* @member {String} TileMatrixSet.prototype.identifier
*/
this.identifier = defaultValue(options.identifier, undefined)
/**
* 支持的CRS
* @member {String} TileMatrixSet.prototype.supportedCRS
*/
this.supportedCRS = defaultValue(options.supportedCRS, undefined)
}
/**
* @function TileMatrixSet.prototype.fromJSON
* @description 获取切片分辨率
* @param {Number} pxRes 切片像素单位长度,代表1像素是多少毫米,默认值为0.28mm(90.71DPI)
* @param {Boolean} isGeographic 是否为经纬度坐标,默认值为false
* @returns {Number} 分辨率数组
*/
getTileResolution(pxRes = 0.28, isGeographic = false) {
const resolution = []
// 1度代表多少米111319490.79327358,取值到小数点地7位
const degreeMillimeters = 111319490.7932735
for (let i = 0; i < this.tileMatrix.length; i++) {
const value = isGeographic
? (Number(this.tileMatrix[i].scaleDenominator) * pxRes) /
degreeMillimeters
: (Number(this.tileMatrix[i].scaleDenominator) * pxRes) / 1000
resolution.push(value)
}
return resolution
}
/**
* @function TileMatrixSet.prototype.fromJSON
* @description 将JSON格式的图块矩阵集参数转换为JS对象
* @param {Object} json 图块矩阵集的实例化JSON
*/
fromJSON(json) {
json = defaultValue(json, {})
this.extent = defaultValue(json.extent, undefined)
this.id = defaultValue(json.id, getGUID())
this.tileInfo = defaultValue(json.tileInfo, undefined)
this.layer = defaultValue(json.layer, undefined)
}
/**
* @function TileMatrixSet.prototype.toJSON
* @description 将JS对象转换为JSON格式
* @returns {Object} 图块矩阵集的实例化JSON
*/
toJSON() {
return {
extent: this.extent && this.extent.toJSON(),
id: this.id,
tileInfo: this.tileInfo && this.tileInfo.toJSON(),
tileMatrix: this.tileMatrix,
identifier: this.identifier,
supportedCRS: this.supportedCRS
}
}
/**
* 克隆图块矩阵集对象
* @return {TileMatrixSet} 克隆后的图块矩阵集对象
*/
clone() {
return new TileMatrixSet(this.toJSON())
}
}
Zondy.TileMatrixSet = TileMatrixSet
export default TileMatrixSet