arcgis api for js 4.x 加载另类wmts地图

首先使用WebTileLayer类的createSubclass方法创建并重写一个TileLayer的图层类:

define(['dojo/_base/declare', "dojo/_base/lang", "dojo/_base/url", "dojo/string", "esri/layers/WebTileLayer", "esri/layers/TileLayer",
"esri/layers/MapImageLayer", "esri/core/urlUtils", "esri/layers/support/LOD", "esri/geometry/SpatialReference", "esri/core/JSONSupport"],
function (declare, lang, url, string, WebTileLayer, TileLayer, MapImageLayer, urlUtils, LOD,SpatialReference, JSONSupport) {
var WMTSMeratorLayer2 = WebTileLayer.createSubclass([JSONSupport], {
        declaredClass: "WMTSMeratorLayer",
        normalizeCtorArgs: function (b, c) {
            return "string" === typeof b ? lang.mixin({ urlTemplate: b }, c || {}) : b
        },
        getDefaults: function (b) {
            var sp = new SpatialReference({
                "wkid": 102100
            });
            var cornerCoordinate = 20037508.3427892;
            var c = new Extent(-cornerCoordinate, -cornerCoordinate, cornerCoordinate, cornerCoordinate, sp);
            return lang.mixin(this.inherited(arguments), {
                fullExtent: c,
                tileInfo: new TileInfo({
                    rows: 256,
                    cols: 256,
                    dpi: 90.71428571428571,
                    format: "PNG8",
                    compressionQuality: 0,
                    origin: new Point({ x: -20037508.342787, y: 20037508.342787, spatialReference: sp }),
                    spatialReference: sp,
                    lods: [
                        new LOD({ level: 0, resolution: 156543.03392800014, scale: 591657527.591555 }),
                        new LOD({ level: 1, resolution: 78271.516963999937, scale: 295828763.79577702 }),
                        new LOD({ level: 2, resolution: 39135.758482000092, scale: 147914381.89788899 }),
                        new LOD({ level: 3, resolution: 19567.879240999919, scale: 73957190.948944002 }),
                        new LOD({ level: 4, resolution: 9783.9396204999593, scale: 36978595.474472001 }),
                        new LOD({ level: 5, resolution: 4891.9698102499797, scale: 18489297.737236001 }),
                        new LOD({ level: 6, resolution: 2445.9849051249898, scale: 9244648.8686180003 }),
                        new LOD({ level: 7, resolution: 1222.9924525624949, scale: 4622324.4343090001 }),
                        new LOD({ level: 8, resolution: 611.49622628137968, scale: 2311162.2171550002 }),
                        new LOD({ level: 9, resolution: 305.74811314055756, scale: 1155581.108577 }),
                        new LOD({ level: 10, resolution: 152.87405657041106, scale: 577790.55428899999 }),
                        new LOD({ level: 11, resolution: 76.437028285073239, scale: 288895.27714399999 }),
                        new LOD({ level: 12, resolution: 38.21851414253662, scale: 144447.638572 }),
                        new LOD({ level: 13, resolution: 19.10925707126831, scale: 72223.819285999998 }),
                        new LOD({ level: 14, resolution: 9.5546285356341549, scale: 36111.909642999999 }),
                        new LOD({ level: 15, resolution: 4.7773142679493699, scale: 18055.954822 }),
                        new LOD({ level: 16, resolution: 2.3886571339746849, scale: 9027.9774109999998 }),
                        new LOD({ level: 17, resolution: 1.1943285668550503, scale: 4513.9887049999998 }),
                        new LOD({ level: 18, resolution: 0.59716428355981721, scale: 2256.994353 }),
                        new LOD({ level: 19, resolution: 0.29858214164761665, scale: 1128.4971760000001 }),
                        new LOD({ level: 20, resolution: 0.1492910708238083, scale: 564.248588 })
                    ]
                })
            })
        },
        properties: {
            copyright: "",
            legendEnabled: {
                json: {
                    readFrom: ["showLegend"], read: function (b, c) {
                        return null != c.showLegend ? c.showLegend : !0
                    }
                }
            },
            levelValues: {
                dependsOn: ["tileInfo"], get: function () {
                    var b = [];
                    if (!this.tileInfo) return null;
                    this.tileInfo.lods.forEach(function (c) {
                        b[c.level] = c.levelValue || c.level
                    }, this);
                    return b
                }
            },
            popupEnabled: {
                json: {
                    readFrom: ["disablePopup"], read: function (b, c) {
                        return null != c.disablePopup ? !c.disablePopup : !0
                    }
                }
            },
            spatialReference: new SpatialReference({ "wkid": 4326 }),
            subDomains: null,
            tileServers: {
                value: null,
                dependsOn: ["urlTemplate", "subDomains", "urlPath"],
                get: function () {
                    var b = new url(this.urlTemplate),
                            c = b.scheme ? b.scheme + "://" : "//",
                            a = c + b.authority + "/",
                            e = this.subDomains,
                            d, f = [];
                    -1 === b.authority.indexOf("{subDomain}") && f.push(a);
                    e && (0 < e.length && 1 < b.authority.split(".").length) && e.forEach(function (a, e) {
                        -1 < b.authority.indexOf("{subDomain}") && (d = c + b.authority.replace(/\{subDomain\}/gi, a) + "/");
                        f.push(d)
                    }, this);
                    return f = f.map(function (b) {
                        "/" !== b.charAt(b.length - 1) && (b +=
                                "/");
                        return b
                    })
                }
            },
            urlPath: {
                dependsOn: ["urlTemplate"], get: function () {
                    if (!this.urlTemplate) return null;
                    var b = this.urlTemplate,
                            a = new url(b);
                    return b.substring(((a.scheme ? a.scheme + "://" : "//") + a.authority + "/").length)
                }
            },
            urlTemplate: null
        },
        getTileUrl: function (b, a, d) {
            b = this.levelValues[b];
            var tileUrl = this.subDomains[0] + "?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=" + this.id + "&STYLE=default&FORMAT=image/png&TILEMATRIXSET=satImage&TILEMATRIX=" + b + "&TileRow=" + a + "&TileCol=" + d;
            return urlUtils.addProxy(tileUrl)
        }
    });
});

 声明WMTSMeratorLayer变量图层后,下面是调用

 var options = {
                "id": id,
                "label": "信息中心影像地图",
                "visible": true,
                "opacity": 1,
                "style": "default",
                "wmtslayer": "vec",
                "tileMatrixSet": "c",
                "format": "tiles",
                //"urlTemplate": "http://{subDomain}.tianditu.com/DataServer?T=vec_c&x={col}&y={row}&l={level}",
                "urlTemplate": "http://{subDomain}?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=" + id + "&STYLE=default&FORMAT=image/png&TILEMATRIXSET=satImage&TILEMATRIX={level}&TileRow={row}&TileCol={col}",
                "copyright": "TiandituWMTS",
                subDomains: [yxtData.yxtUrl]
            };
var  selectLayer = new WMTSMeratorLayer2(options);
var myImgMap = new Basemap({
            id: "imgmap",
            baseLayers: [selectLayer]
        });
map.basemap = myImgMap;

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值