forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTiandituTileLayer.js
More file actions
92 lines (89 loc) · 3.99 KB
/
TiandituTileLayer.js
File metadata and controls
92 lines (89 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import L from 'leaflet';
import '../core/Base';
import { WMTSLayer } from './TileLayer.WMTS';
import Attributions from '../core/Attributions';
/**
* @class L.supermap.tiandituTileLayer
* @classdesc 天地图图层类。
* @category ThirdPartyMap
* @extends L.supermap.wmtsLayer
* @param {Object} options - 切片图层参数。
* @param {string} [options.url='https://t{s}.tianditu.gov.cn/{layer}_{proj}/wmts?'] - 地图地址。
* @param {string} options.key - 天地图服务密钥。详见{@link https://lbs.tianditu.gov.cn/server/MapService.html}
* @param {string} [options.layerType='vec'] - 图层类型。(vec:矢量图层,img:影像图层,ter:地形图层)
* @param {string} [options.style='default'] - 图层风格。
* @param {string} [options.format='tiles'] - 格式。
* @param {boolean} [options.isLabel=false] - 是否是标注图层。
* @param {Array.<number>} [options.subdomains=[0, 1, 2, 3, 4, 5, 6, 7]] - 子域名数组。
* @param {string} [options.attribution='Map Data <a href='https://www.tianditu.gov.cn' target='_blank'><img style='background-color:transparent;bottom:2px;opacity:1;' src='https://api.tianditu.gov.cn/img/map/logo.png' width='53px' height='22px' opacity='0'></a>'] - 版权信息
* @param {string} [options.noWrap=true] - 图层是否X方向平铺。
*/
export var TiandituTileLayer = WMTSLayer.extend({
layerLabelMap: {
vec: 'cva',
ter: 'cta',
img: 'cia'
},
layerZoomMap: {
vec: 18,
ter: 14,
img: 18
},
options: {
layerType: 'vec', //(vec:矢量图层,vec:矢量标签图层,img:影像图层,cia:影像标签图层,ter:地形,cta:地形标签图层)
isLabel: false,
attribution: Attributions.Tianditu.attribution,
url: 'https://t{s}.tianditu.gov.cn/{layer}_{proj}/wmts?',
zoomOffset: 1,
key: '',
dpi: 96,
style: 'default',
format: 'tiles',
subdomains: [0, 1, 2, 3, 4, 5, 6, 7],
bounds: [
[-90, -180],
[90, 180]
],
noWrap: true
},
initialize: function (options) {
options = options || {};
L.setOptions(this, options);
this.options.layer = this.options.isLabel ? this.layerLabelMap[this.options.layerType] : this.options.layerType;
this.options.maxZoom = this.layerZoomMap[this.options.layerType] - 1;
WMTSLayer.prototype.initialize.call(this, this.options.url, this.options);
L.stamp(this);
if (this.options.key) {
this._url = `${this._url}tk=${this.options.key}`;
}
},
onAdd: function (map) {
this.options.tilematrixSet = map.options.crs.code === "EPSG:4326" ? "c" : "w";
this._url = this._url.replace("{layer}", this.options.layer).replace("{proj}", this.options.tilematrixSet);
WMTSLayer.prototype.onAdd.call(this, map);
},
_isValidTile: function (coords) {
const crs = this._map.options.crs;
if (!crs.infinite) {
const bounds = this._globalTileRange;
if (
((!crs.wrapLng || this.options.noWrap) && (coords.x < bounds.min.x || coords.x > bounds.max.x)) ||
(!crs.wrapLat && (coords.y < bounds.min.y || coords.y > bounds.max.y))
) {
return false;
}
}
if (!this.options.bounds) {
return true;
}
const tileBounds = this._tileCoordsToBounds(coords);
return L.latLngBounds(this.options.bounds).overlaps(tileBounds);
}
});
export var tiandituTileLayer = function (options) {
return new TiandituTileLayer(options);
};
L.supermap.tiandituTileLayer = tiandituTileLayer;