高德地图JSAPI提供了WMS和WMTS图层,凡是符合OGC标准的支持EPSG3857坐标系统的WMS和WMTS地图服务均可通过这两个图层添加到地图中
AMap.TileLayer.WMS
用于加载OGC标准的WMS
地图服务的一种图层类,自v1.4.3新增,仅支持EPSG3857
坐标系统的WMS图层,查看WMS的OGC标准。
示例代码,前往示例中心:JavaScript
var map = new AMap.Map('container', {
zoom: 3,
// viewMode:'3D',
center:[-99.241291,39.51401]
});
var wms = new AMap.TileLayer.WMS({
url:'https://ahocevar.com/geoserver/wms',
blend:false,
tileSize:512,
params:{'LAYERS': 'topp:states',VERSION:'1.3.0'}
})
wms.setMap(map)
构造函数 | 说明 |
---|
AMap.TileLayer.WMS(opts:WMSOptions) | 创建WMS图层,WMSOptions为创建图层所需要的属性组对象 |
WMSOptions | 类型 | 说明 |
---|
url | String | wms服务的url地址,如'https://ahocevar.com/geoserver/wms' |
blend | Boolean | 地图级别切换时,不同级别的图片是否进行混合,如图层的图像内容为部分透明请设置为false |
zooms | [Number,Number] | 可见的级别范围 |
tileSize | Number | 加载WMS图层服务时,图片的分片大小,可自由设定,不易过大,建议[256,512] |
opacity | Number | 不透明度 |
zIndex | Number | 层级 |
visible | Boolean | 初始时时候是否显示 |
params | Object | OGC标准的WMS地图服务的GetMap 接口的参数,包括VERSION 、LAYERS 、STYLES 、FORMAT 、TRANSPARENT 等,CRS、BBOX、REQUEST、WIDTH、HEIGHT等参数请勿添加,例如:{ LAYERS: 'topp:states', VERSION:'1.3.0', FORMAT:'image/png' } |
方法 | 返回值 | 说明 |
---|
setMap(map:AMap.Map/null) |
| 设置图层所属的地图对象,传入null时从当前地图移除 |
getMap() | AMap.Map | 返回图层所属的地图对象 |
show() |
| 显示 |
hide() |
| 隐藏 |
setzIndex(zindex:Number) |
| 设置层级 |
getzIndex() | Number | 获取层级 |
setUrl(url:String) |
| 设置wms服务地址 |
getUrl() | String | 返回wms服务地址 |
setParams(params:Object) |
| 设置OGC标准的WMS getMap 接口的参数,包括VERSION 、LAYERS 、STYLES 、FORMAT 、TRANSPARENT 等 |
getParams() | Object |
|
AMap.TileLayer.WMTS
用于加载OGC标准的WMTS
地图服务的一种图层类,自v1.4.3新增,仅支持EPSG3857
坐标系统的WMTS图层,查看WMTS标准
示例代码,前往示例中心:JavaScript
var map = new AMap.Map('container', {
zoom: 3,
//viewMode:'3D',
center:[-99.241291,39.51401]
});
var wms = new AMap.TileLayer.WMTS({
url: 'https://services.arcgisonline.com/arcgis/rest/services/Demographics/USA_Population_Density/MapServer/WMTS/',
blend:false,
tileSize:256,
params:{'Layer': '0',Version:'1.0.0',Format: 'image/png'}
})
wms.setMap(map)
构造函数 | 说明 |
---|
AMap.TileLayer.WMTS(otps:WMTSOptions) | 创建WMTS图层,WMTSOptions为创建图层所需要的属性组对象 |
WMTSOptions | 类型 | 说明 |
---|
url | String | wmts服务的url地址,如:'https://services.arcgisonline.com/arcgis/rest/services/'+ 'Demographics/USA_Population_Density/MapServer/WMTS/' |
blend | Boolean | 地图级别切换时,不同级别的图片是否进行混合,如图层的图像内容为部分透明请设置为false |
tileSize | Number | WMTS图层的分片大小,需要和WMTS服务支持的大小一致 |
zooms | [Number,Number] | 可见的级别范围 |
opcaity | Number | 不透明度 |
zIndex | Number | 层级 |
visible | Boolean | 初始时时候是否显示 |
params | Object | OGC标准的WMTS地图服务的GetTile 接口的参数,包括Version 、Layer 、Style 、Format、Service 等,TileMatrixSet、TileRow、TileCol、Request等参数请勿添加,例如:{ Layer: '0', Version:'1.0.0', Format: 'image/png' } |
方法 | 返回值 | 说明 |
---|
setMap(map:AMap.Map/null) |
| 设置图层所属的地图对象,传入null时从当前地图移除 |
getMap() | AMap.Map | 返回图层所属的地图对象 |
show() |
| 显示 |
hide() |
| 隐藏 |
setzIndex(zindex:Number) |
| 设置层级 |
getzIndex() | Number | 获取层级 |
setUrl(url:String) |
| 设置wmts服务地址 |
getUrl() | String | 返回wmts服务地址 |
setParams(params:Object) |
| 设置OGC标准的WMTS getTile 接口的参数,包括Version、Layer、Style、Format、Service等 |
getParams() | Object |
|