其实ArcGIS API for JavaScript 也已经有两个例子了,不过就是在一些参数方面,没有解释清楚。Arcgis的例子是以Geoserver发布的服务作为举例的,而这里是用独立的GeoWebCache服务WMTS服务的,地址是http://localhost:8080/geowebcache/service/wmts,按照ArcGIS给出的例子调了两天也没调出来,例子如下(这已经是我改过的):
<script>
var map, wmtsLayer;
require([
"esri/map", "esri/layers/WMTSLayer", "esri/layers/WMTSLayerInfo",
"esri/geometry/Extent", "esri/layers/TileInfo", "esri/SpatialReference",
"dojo/parser",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function (
Map, WMTSLayer, WMTSLayerInfo,
Extent, TileInfo, SpatialReference,
parser
) {
parser.parse();
map = new Map("map", {
logo: false
});
var tileInfo1 = new TileInfo({
"dpi": 96,
"format": "image/png",
"compressionQuality": 0,
"spatialReference": new SpatialReference({
"wkid": 3857
}),
"rows": 256,
"cols": 256,
"origin": {
"x": -20037508.342787001,
"y": 20037508.342787001
},
"lods": [{
"level": "EPSG:3857_ArcgisServerCn:0",
"scale": 591657527.591555,
"resolution": 156543.03392800014
}, {
"level": "EPSG:3857_ArcgisServerCn:1",
"scale": 295828763.79577702,
"resolution": 78271.516963999937
}, {
"level": "EPSG:3857_ArcgisServerCn:2",
"scale": 147914381.89788899,
"resolution": 39135.758482000092
}, {
"level": "EPSG:3857_ArcgisServerCn:3",
"scale": 73957190.948944002,
"resolution": 19567.879240999919
}, {
"level": "EPSG:3857_ArcgisServerCn:4",
"scale": 36978595.474472001,
"resolution": 9783.9396204999593
}, {
"level": "EPSG:3857_ArcgisServerCn:5",
"scale": 18489297.737236001,
"resolution": 4891.9698102499797
}, {
"level": "EPSG:3857_ArcgisServerCn:6",
"scale": 9244648.8686180003,
"resolution": 2445.9849051249898
}, {
"level": "EPSG:3857_ArcgisServerCn:7",
"scale": 4622324.4343090001,
"resolution": 1222.9924525624949
}, {
"level": "EPSG:3857_ArcgisServerCn:8",
"scale": 2311162.2171550002,
"resolution": 611.49622628137968
}, {
"level": "EPSG:3857_ArcgisServerCn:9",
"scale": 1155581.108577,
"resolution": 305.74811314055756
}]
});
//var tileExtent1 = new Extent(15458931.4659706, 2701989.00905778, 15477712.7689042, 2711695.89036901, new SpatialReference({
// wkid: 3857
//}));
var tileExtent1 = new Extent(13507034.394216927, 3656747.4331628317, 13519570.066855695, 3665308.3803307717, new SpatialReference({
wkid: 3857
}));
var layerInfo1 = new WMTSLayerInfo({
tileInfo: tileInfo1,
fullExtent: tileExtent1,
initialExtent: tileExtent1,
identifier: "ArcgisServerCn",
tileMatrixSet: "EPSG:3857_ArcgisServerCn",
format: "jpeg",
style: "_null"
});
var resourceInfo = {
version: "1.0.0",
layerInfos: [layerInfo1],
copyright: "open layer"
};
var options = {
serviceMode: "KVP",
resourceInfo: resourceInfo,
layerInfo: layerInfo1
};
wmtsLayer = new WMTSLayer("http://localhost:8080/geowebcache/service/wmts", options);
map.addLayer(wmtsLayer);
});
</script>
其实tileInfo1的dpi、format等参数对于独立geowebcache发布的服务并没有什么作用,主要是标红的地方需要注意了是发布服务的Grids Sets,如图,而不是简单的EPSG:3857。