在项目中需要加载天地图的底图,但SDK 中并没有加载天地图的原生接口,因此在经历询问了客服,寻找demo中的bug后,实现了swift3.0加载天地图地图,现记录如下。
TianDiTuLayerInfo.swift
import Foundation
import ArcGIS
enum TianDiTuLayerType{
case TDT_VECTOR ///<天地图矢量服务>
case TDT_IMAGE ///<天地图影像务>
case TDT_TERRAIN ///<天地图地形服务>
}
enum TianDiTuLanguageType{
case TDT_CN ///<天地图中文标注服务>
case TDT_EN ///<天地图英文标注服务>
}
enum TianDiTuSpatialReferenceType{
case TDT_MERCATOR ///<天地图墨卡托服务>
case TDT_2000 ///<天地图2000服务>
}
class TianDiTuLayerInfo{
let kURLGetTile = "http://t0.tianditu.com/%@/wmts?service=wmts&request=gettile&version=1.0.0&layer=%@&format=tiles&tilematrixset=%@"
let tiandituURL = "http://t0.tianditu.com/%@/wmts"
let X_MIN_MERCATOR = -20037508.3427892
let Y_MIN_MERCATOR = -20037508.3427892
let X_MAX_MERCATOR = 20037508.3427892
let Y_MAX_MERCATOR = 20037508.3427892
let X_MIN_2000 = -180.0
let Y_MIN_2000 = -90.0
let X_MAX_2000 = 180.0
let Y_MAX_2000 = 90.0
let _minZoomLevel = 0
let _maxZoomLevel = 16
let _tileWidth = 256
let _tileHeight = 256
let _dpi = 96
let _WebMercator = 102100
let _GCS2000 = 4490//demo中写的是2000,一定要改过来,切记!!!!!!!!!!
let kTILE_MATRIX_SET_MERCATOR = "w"
let kTILE_MATRIX_SET_2000 = "c"
private var layername:String!
private var servicename:String!
private var tilematrixset:String!
private var sp:AGSSpatialReference!
public var fullExtent: AGSEnvelope!
private var origin: AGSPoint!
private var lods:NSArray!
public var tileInfo:AGSTileInfo!
init(layerType:TianDiTuLayerType, spttype:TianDiTuSpatialReferenceType) {
self.layername = ""
switch layerType{
case TianDiTuLayerType.TDT_VECTOR :
self.layername = "vec"
case TianDiTuLayerType.TDT_IMAGE :
self.layername = "img"
case TianDiTuLayerType.TDT_TERRAIN:
self.layername = "ter"
}
self.setSpatialReference(sptype: spttype)
self.tileInfo = self.getTianDiTuLayerInfo()
}
init(layerType:TianDiTuLayerType, lan:TianDiTuLanguageType, spttype:TianDiTuSpatialReferenceType){
self.layername = ""
switch layerType{
case TianDiTuLayerType.TDT_VECTOR :
switch lan {
case TianDiTuLanguageType.TDT_CN:
self.layername = "cva"
case TianDiTuLanguageType.TDT_EN:
self.layername = "eva"
}
case