From f80831da30238b4725f9db11b4838b420975b585 Mon Sep 17 00:00:00 2001 From: htoo Date: Thu, 14 Apr 2022 00:18:31 +0800 Subject: [PATCH] feat: add Tencent map --- README.md | 5 +++ examples/indexTencent.html | 69 ++++++++++++++++++++++++++++++ src/leaflet.ChineseTmsProviders.js | 36 +++++++++++++++- 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 examples/indexTencent.html diff --git a/README.md b/README.md index 3d8ae1d..4100076 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ There are more examples at the examples folder like below. [./examples/indexBaidu.html](http://htoooth.github.io/Leaflet.ChineseTmsProviders/examples/indexBaidu.html) +[./examples/indexTencent.html](http://htoooth.github.io/Leaflet.ChineseTmsProviders/examples/indexBaidu.html) Above all maps use Coordinate Reference Systems (CRS), which are EPSG:3857. @@ -73,6 +74,10 @@ Current options suitable for tile layers are: * Baidu.Normal.Map * Baidu.Satellite.Map (exclude Annotion) * Baidu.Satellite.Annotion +* Tencent + * Tencent.Normal.Map + * Tencent.Satellite.Map + * Tencent.Terrain.Map ## Options diff --git a/examples/indexTencent.html b/examples/indexTencent.html new file mode 100644 index 0000000..0186204 --- /dev/null +++ b/examples/indexTencent.html @@ -0,0 +1,69 @@ + + + + + + + + + + + + > + + + + +
+ + + + diff --git a/src/leaflet.ChineseTmsProviders.js b/src/leaflet.ChineseTmsProviders.js index c923713..4d39250 100644 --- a/src/leaflet.ChineseTmsProviders.js +++ b/src/leaflet.ChineseTmsProviders.js @@ -38,7 +38,28 @@ L.TileLayer.ChinaProvider = L.TileLayer.extend({ } L.TileLayer.prototype.initialize.call(this, url, options); - } + }, + + getTileUrl: function (coords) { + var data = { + s: this._getSubdomain(coords), + x: coords.x, + y: coords.y, + z: this._getZoomForUrl(), + }; + if (this._map && !this._map.options.crs.infinite) { + var invertedY = this._globalTileRange.max.y - coords.y; + if (this.options.tms) { + data['y'] = invertedY; + } + data['-y'] = invertedY; + } + + data.sx = data.x >> 4 + data.sy = (( 1 << data.z) - data.y) >> 4 + + return L.Util.template(this._url, L.Util.extend(data, this.options)); + }, }); L.TileLayer.ChinaProvider.providers = { @@ -111,6 +132,19 @@ L.TileLayer.ChinaProvider.providers = { }, Subdomains: '0123456789', tms: true + }, + + Tencent: { + Normal: { + Map: "//rt{s}.map.gtimg.com/tile?z={z}&x={x}&y={-y}&type=vector&styleid=3", + }, + Satellite: { + Map: "//p{s}.map.gtimg.com/sateTiles/{z}/{sx}/{sy}/{x}_{-y}.jpg", + }, + Terrain: { + Map: "//p{s}.map.gtimg.com/demTiles/{z}/{sx}/{sy}/{x}_{-y}.jpg" + }, + Subdomains: '0123', } };