更新时间:2026/07/27 10:37
您当前查看的是 JSAPI GL 历史版本文档。该版本仅用于维护现有项目,不建议用于新项目开发。新项目请使用 JSAPI 4.0,如需升级现有项目,请参考升级指南。
You are viewing the legacy JSAPI GL documentation. This version is maintained for existing projects only and is not recommended for new development. For new projects, use the JSAPI 4.0 documentation. If you are upgrading an existing project, please refer to the Migration Guide.
You are viewing the legacy JSAPI GL documentation. This version is maintained for existing projects only and is not recommended for new development. For new projects, use the JSAPI 4.0 documentation. If you are upgrading an existing project, please refer to the Migration Guide.
三方标准图层
简介
JSAPI GL提供XYZLayer类支持加载EPSG3857 坐标系统的 WMS 图层、WMTS图层、TMS图层以及自定义栅格图层。
XYZLayer类参考
构造函数:
options属性变量:
XYZLayer方法
WMS图层示例
使用服务示例代码如下:
JavaScript
// 创建位置点var map = new BMapGL.Map('allmap');var point = new BMapGL.Point(-99.41413316281799, 39.82354027110903);map.centerAndZoom(point, 4);// tileUrlTemplate 包含OGC标准的WMS地图服务的GetMap接口的参数var wms = BMapGL.XYZLayer({ tileUrlTemplate: 'https://ahocevar.com/geoserver/wms?REQUEST=GetMap&SERVICE=WMS&layers=topp:states&version=1.3.0&CRS=EPSG:3857&WIDTH=256&HEIGHT=256&FORMAT=image/png&TRANSPARENT=true&BBOX=[b] ',});map.addTileLayer(wms);WMTS图层示例
使用服务示例代码如下:
JavaScript
// 创建位置点var map = new BMapGL.Map('allmap');var point = new BMapGL.Point(-99.41413316281799, 39.82354027110903);map.centerAndZoom(point, 4);// tileUrlTemplate 包含OGC标准的WMTS地图服务的GetTile接口的参数var wmts = BMapGL.XYZLayer({ tileUrlTemplate: ' https://mrdata.usgs.gov/mapcache/wmts?layer=sgmc2&style=default&tilematrixset=GoogleMapsCompatible&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix=[z]&TileCol=[x]&TileRow=[y]', useThumbData: true,});map.addTileLayer(wmts);TMS图层示例
使用服务示例代码如下:
JavaScript
// 创建位置点var map = new BMapGL.Map('allmap');var point = new BMapGL.Point(116.59141044992062, 40.30466588726649);map.centerAndZoom(point, 4);// tileUrlTemplate 包含tms服务瓦片请求地址var tms = BMapGL.XYZLayer({ tileUrlTemplate: ' https://mapopen-pub-jsapigl.cdn.bcebos.com/tms-bj/[z]/[x]/[y].png', tms: true, useThumbData: true, // 如果不设置tms:true,可以采用以下方式 // yTemplate: function (x, y, z) { // return Math.pow(2, z) - y - 1; // }});
map.addTileLayer(tms);自定义栅格图层示例
使用服务示例代码如下:
JavaScript
// 创建位置点var map = new BMapGL.Map('allmap');var point = new BMapGL.Point(116.0970093263384, 49.9429305258067);map.centerAndZoom(point, 7);var custom = new BMapGL.XYZLayer({ useThumbData: true, // 自定义图层瓦片请求地址,可使用xTemplate,yTemplate,zTemplate匹配自定义网格编号规则 tileUrlTemplate: 'http://c.tile.opencyclemap.org/cycle/[z]/[x]/[y].png', // xTemplate: function (x, y, z) { // return x; // }, // yTemplate: function (x, y, z) { // return y; // }, // zTemplate: function (x, y, z) { // return z; // }});var bd = new BMapGL.Boundary();bd.get('河北', function (rs) { custom.addBoundary(rs.boundaries);});map.addTileLayer(custom);本篇文章对您是否有帮助?