🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一、WMS图层 官方示例:https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=layers-wms ~~~ require([ 'esri/config', 'esri/Map', 'esri/views/MapView', 'esri/layers/WMSLayer', 'esri/layers/WMTSLayer', 'dojo/domReady!' ], function(esriConfig, Map, MapView, WMSLayer, WMTSLayer) { // 配置允许的服务器域名 esriConfig.request.corsEnabledServers.push('http://map.xxx.com', 'https://map.xxx.com'); var map = new Map({ basemap: 'streets' // dark-gray-vector }); var mapView = new MapView({ map: map, container: 'js_map', center: [102.9331224074, 25.1049040686], zoom: 6, // rotation: -127.7 }); // 添加WMS图层 var wmsLayer = new WMSLayer({ url: 'http://map.xxx.com/geoserver/kmg/wms', imageFormat: 'image/png', sublayers: [{ name: 'kmg:vector' }] }); map.layers.add(wmsLayer); }); ~~~ ## 二、WMTS图层(在上面的基础上) 官方示例:https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=layers-wmts ~~~ // 添加WMTS图层 var wmtsLayer = new WMTSLayer({ url: 'https://map.xxx.com/geoserver/gwc/service/wmts', serviceMode: 'KVP', version: '1.1.1', activeLayer: { id: 'kmg:vector', } }); map.layers.add(wmtsLayer); ~~~ 参数: serviceMode:WMTS层的服务模式。如果没有指定,API将首先使用RESTful来创建一个getCapabilities请求。如果失败,它将尝试使用KVP。