直接上代码:
loadModules([
"esri/Map",
"esri/views/MapView",
"esri/widgets/BasemapToggle",
"esri/widgets/BasemapGallery",
'esri/widgets/Zoom',
"esri/widgets/DistanceMeasurement2D",
"esri/widgets/Slider",
"esri/widgets/Legend",
"esri/views/draw/Draw",
"esri/Graphic",
"dojo/on",
"dojo/dom",
"dojo/request/xhr",
"esri/widgets/LayerList",
"esri/layers/BaseTileLayer",
"esri/config",
"esri/request",
"esri/Color",
"esri/layers/WebTileLayer",
"esri/layers/support/TileInfo",
"esri/layers/GeoJSONLayer",
"esri/geometry/Point",
"esri/layers/GraphicsLayer",
"esri/layers/MapImageLayer",
"esri/symbols/PictureMarkerSymbol",
"esri/layers/BaseDynamicLayer",
"esri/layers/support/MapImage",
"dojo/_base/array",
"dojo/json",
"dojo/domReady!"
])
.then(([
Map, MapView, BasemapToggle, BasemapGallery, Zoom, DistanceMeasurement2D,Slider,Legend, Draw, Graphic,
on, dom, xhr,LayerList,BaseTileLayer,esriConfig, esriRequest, Color,WebTileLayer,TileInfo,
GeoJSONLayer,Point,PictureMarkerSymbol,GraphicsLayer,
MapImageLayer,BaseDynamicLayer,MapImage,arrayUtils,Json]) => {
let tileInfo = new TileInfo({
dpi: 90.71428571427429, // 切片方案的每英寸点数(即像素)。
size: 256, // 设置每个瓷砖的高度和宽度为[256, 256]像素。
origin: { // 切片方案的原点。
type: "point",
x: -180,
y: 90,
spatialReference: {wkid: 4326}
},
spatialReference: {wkid: 4326},
lods: [ // 定义平铺方案的详细级别数组。
{level: 2, levelValue: 2, resolution: 0.3515625, scale: 147748796.52937502},
{level: 3, levelValue: 3, resolution: 0.17578125, scale: 73874398.264687508},
{level: 4, levelValue: 4, resolution: 0.087890625, scale: 36937199.132343754},
{level: 5, levelValue: 5, resolution: 0.0439453125, scale: 18468599.566171877},
{level: 6, levelValue: 6, resolution: 0.02197265625, scale: 9234299.7830859385},
{level: 7, levelValue: 7, resolution: 0.010986328125, scale: 4617149.8915429693},
{level: 8, levelValue: 8, resolution: 0.0054931640625, scale: 2308574.9457714846},
{level: 9, levelValue: 9, resolution: 0.00274658203125, scale: 1154287.4728857423},
{level: 10, levelValue: 10, resolution: 0.001373291015625, scale: 577143.73644287116},
{level: 11, levelValue: 11, resolution: 0.0006866455078125, scale: 288571.86822143558},
{level: 12, levelValue: 12, resolution: 0.00034332275390625, scale: 144285.93411071779},
{level: 13, levelValue: 13, resolution: 0.000171661376953125, scale: 72142.967055358895},
{level: 14, levelValue: 14, resolution: 8.58306884765625e-005, scale: 36071.483527679447},
{level: 15, levelValue: 15, resolution: 4.291534423828125e-005, scale: 18035.741763839724},
{level: 16, levelValue: 16, resolution: 2.1457672119140625e-005, scale: 9017.8708819198619},
{level: 17, levelValue: 17, resolution: 1.0728836059570313e-005, scale: 4508.9354409599309},
{level: 18, levelValue: 18, resolution: 5.3644180297851563e-006, scale: 2254.4677204799655},
{level: 19, levelValue: 19, resolution: 2.68220901489257815e-006, scale: 1127.23386023998275},
{level: 20, levelValue: 2, resolution: 1.341104507446289075e-006, scale: 563.616930119991375}
]
});
let tk = "4267820f43926eaf808d61dc07269beb";
// 1.矢量底图(T=vec_c) vectorBasemap
let vectorBasemapLayer = new WebTileLayer({
id: "vectorBasemapMap",
title: "vectorBasemapMap",
spatialReference: {
wkid: 4326
},
urlTemplate: 'http://{subDomain}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk='+ tk,
subDomains: ["t0"],
tileInfo: tileInfo
});
// 2.矢量注记(T=cva_c) vectorNote
let vectorNoteLayer = new WebTileLayer({
id: "vectorNoteMap",
title: "vectorNoteMap",
spatialReference: {
wkid: 4326
},
urlTemplate: 'http://{subDomain}.tianditu.gov.cn/cva_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=' + tk,
subDomains: ["t0"],
tileInfo: tileInfo
});// 3.影像底图(T=img_c) imageBasemap
let imageBasemapLayer = new WebTileLayer({
urlTemplate: 'http://{subDomain}.tianditu.gov.cn/img_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=' + tk,
subDomains: ["t0"],
spatialReference: {
wkid: 4326
},
tileInfo: tileInfo
});
// 4.影像注记(T=cia_c) imageNote
let imageNoteLayer = new WebTileLayer({
id: "imageNoteMap",
title: "imageNoteMap",
urlTemplate: 'http://{subDomain}.tianditu.gov.cn/cia_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=' + tk,
subDomains: ["t0"],
spatialReference: {
wkid: 4326
},
tileInfo: tileInfo
});// 5.地形晕渲(T=ter_c) terrainShading。
let terrainShadingLayer = new WebTileLayer({
urlTemplate: 'http://{subDomain}.tianditu.gov.cn/ter_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ter&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=' + tk,
subDomains: ['t0'],
spatialReference: {
wkid: 4326
},
// 该层的平铺方案信息。
tileInfo: tileInfo
});
// 6.地形注记(T=cta_c) terrainNote
let terrainNoteLayer = new WebTileLayer({
id: "terrainNoteMap",
title: "terrainNoteMap",
urlTemplate: 'http://{subDomain}.tianditu.com/DataServer?T=cta_c&x={col}&y={row}&l={level}&tk=' + tk
subDomains: ["t0"],
spatialReference: {
wkid: 4326
},
tileInfo: tileInfo
});// 7.全球境界(T=ibo_c) globalRealm。
let globalRealmLayer = new WebTileLayer({
urlTemplate: "http://{subDomain}.tianditu.com/DataServer?T=ibo_c&X={col}&Y={row}&L={level}&tk=" + tk
subDomains: ['t0'],
spatialReference: {
wkid: 4326
},
// 该层的平铺方案信息。
tileInfo: tileInfo
});
slef.$map = new Map({
basemap: {
baseLayers: [imageBasemapLayer,vectorNoteLayer]
}
});
slef.$view = new MapView({
container: "viewDiv",
map: slef.$map,
spatialReference: {
wkid: 4326
},
center: [106.82568, 28.13806],
zoom: 11
});slef.$zoom = new Zoom({
view: slef.$view
});
slef.$measureWidget = new DistanceMeasurement2D({
view: slef.$view
});
slef.$view.ui.add(slef.$measureWidget, "top-right");
slef.$draw = new Draw({
view: slef.$view
});var basemapToggle = new BasemapToggle({
view: slef.$view,
nextBasemap: "streets"
});
slef.$view.ui.add(basemapToggle, "bottom-right");
})
.catch(err => {
console.error("mapUtils.js:"+err);
}
因为使用vue esri-loader进行的编写,所以在引用上不是require,不影响代码的使用,集成效果如下: