tencent
本文回答:腾讯地图 XYZ 地址与使用方式。与高德类似,都是 GCJ02。
一、瓦片地址
腾讯地图使用 GCJ02 坐标系:
| 用途 | URL |
|---|---|
| 矢量 | https://rt{s}.map.gtimg.com/realtimerender?z={z}&x={x}&y={y}&type=vector&style=0 |
| 影像 | https://p{s}.map.gtimg.com/sateTiles/{z}/{sx}/{sy}/{x}_{y1}.jpg({sx}/{sy}/{y1} 不是引擎支持的占位符,不能直接作 raster source) |
腾讯瓦片 Y 轴上下反,要特殊处理 y1 = 2^z - 1 - y。直接作 raster source 时设 scheme: "tms" 让引擎翻转 Y;走后端代理时用 svc.webMapUrl({ tileFlipY: true })。引擎 tiles 模板只认 {x} {y} {z} {quadkey} {prefix} {bbox-epsg-3857},{s} 也要写成具体子域。
二、作为底图
const prj = new vjmap.LnglatProjection();
const map = new vjmap.Map({
container: "map",
style: {
version: svc.styleVersion(),
sources: {
tencent: {
type: "raster",
tileSize: 256, // 不写按默认 512 处理会发糊
scheme: "tms", // Y 轴反向
tiles: ["https://rt3.map.gtimg.com/realtimerender?z={z}&x={x}&y={y}&type=vector&style=0"]
}
},
layers: [{ id: "tencent", type: "raster", source: "tencent" }]
},
center: [0, 0], zoom: 12,
renderWorldCopies: false
});
map.attach(svc, prj);
叠 CAD WMS 时 webMapType: "GCJ02"(同高德)。
三、实践建议
腾讯地图公网域名 QPS 严格限制,生产环境需要:
- 申请腾讯地图 Key(JSAPI 用)。
- 或用
svc.webMapUrl走后端代理。 - 很多项目直接用高德代替(视觉类似、API 更稳定)。
四、常见坑
- Y 轴不反:raster source 加
scheme: "tms",或用svc.webMapUrl({ tileFlipY: true })。 - 注记缺失:矢量瓦片的 style=0 是底图+道路,注记要另叠 WMTS。
- CORS:腾讯 gtimg 没有返 CORS 头,直接加载可能失败;走后端代理。