(opt_options)
| 28 | */ |
| 29 | export class Tianditu extends WMTS { |
| 30 | constructor(opt_options) { |
| 31 | var layerLabelMap = { |
| 32 | "vec": "cva", |
| 33 | "ter": "cta", |
| 34 | "img": "cia" |
| 35 | } |
| 36 | var layerZoomMap = { |
| 37 | "vec": 18, |
| 38 | "ter": 14, |
| 39 | "img": 18 |
| 40 | } |
| 41 | var options = opt_options || {}; |
| 42 | var attributions = options.attributions || "Map Data <a href='https://www.tianditu.gov.cn' target='_blank'><img style='background-color:transparent;bottom:2px;opacity:1;' " + |
| 43 | "src='https://api.tianditu.gov.cn/img/map/logo.png' width='53px' height='22px' opacity='0'></a> with " + |
| 44 | "<span>© SuperMap iClient</span>" |
| 45 | options.layerType = options.layerType || "vec"; |
| 46 | options.layerType = options.isLabel ? layerLabelMap[options.layerType] : options.layerType; |
| 47 | options.matrixSet = (options.projection === 'EPSG:4326' || options.projection === 'EPSG:4490') ? "c" : "w"; |
| 48 | if (!options.url && !options.urls) { |
| 49 | options.url = "https://t{0-7}.tianditu.gov.cn/{layer}_{proj}/wmts?" |
| 50 | } |
| 51 | if (options.key) { |
| 52 | options.url = `${options.url}tk=${options.key}`; |
| 53 | } |
| 54 | options.url = options.url.replace("{layer}", options.layerType).replace("{proj}", options.matrixSet); |
| 55 | var tileGrid = options.tileGrid || Tianditu.getTileGrid(options.projection || 'EPSG:3857'); |
| 56 | |
| 57 | var crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous'; |
| 58 | |
| 59 | var superOptions = { |
| 60 | version: options.version || '1.0.0', |
| 61 | format: options.format || 'tiles', |
| 62 | dimensions: options.dimensions || {}, |
| 63 | layer: options.layerType, |
| 64 | matrixSet: options.matrixSet, |
| 65 | tileGrid: tileGrid, |
| 66 | style: options.style || 'default', |
| 67 | attributions: attributions, |
| 68 | cacheSize: options.cacheSize, |
| 69 | crossOrigin: crossOrigin, |
| 70 | opaque: options.opaque === undefined ? true : options.opaque, |
| 71 | maxZoom: layerZoomMap[options.layerType], |
| 72 | reprojectionErrorThreshold: options.reprojectionErrorThreshold, |
| 73 | url: options.url, |
| 74 | urls: options.urls, |
| 75 | projection: options.projection || 'EPSG:3857', |
| 76 | wrapX: options.wrapX |
| 77 | }; |
| 78 | //需要代理时走自定义 tileLoadFunction,否则走默认的tileLoadFunction |
| 79 | if (options.tileProxy) { |
| 80 | superOptions.tileLoadFunction = tileLoadFunction; |
| 81 | } |
| 82 | super(superOptions); |
| 83 | |
| 84 | if (options.tileProxy) { |
| 85 | this.tileProxy = options.tileProxy; |
| 86 | } |
| 87 | //需要代理时,走以下代码 |
nothing calls this directly
no test coverage detected