1. 在引用天地图时, 我们要自定义一个相关的比例尺转换类
1 const tileInfoObj = { 2 rows: 256, 3 cols: 256, 4 compressionQuality: 0, 5 origin: { 6 x: -180, 7 y: 90, 8 }, 9 spatialReference: { 10 wkid: 4326, 11 }, 12 lods: [ 13 { 14 level: 2, 15 resolution: 0.3515625, 16 scale: 147748796.52937502, 17 }, 18 19 { 20 level: 3, 21 resolution: 0.17578125, 22 scale: 73874398.264687508, 23 }, 24 25 { 26 level: 4, 27 resolution: 0.087890625, 28 scale: 36937199.132343754, 29 }, 30 31 { 32 level: 5, 33 resolution: 0.0439453125, 34 scale: 18468599.566171877, 35 }, 36 37 { 38 level: 6, 39 resolution: 0.02197265625, 40 scale: 9234299.7830859385, 41 }, 42 43 { 44 level: 7, 45 resolution: 0.010986328125, 46 scale: 4617149.8915429693, 47 }, 48 49 { 50 level: 8, 51 resolution: 0.0054931640625, 52 scale: 2308574.9457714846, 53 }, 54 55 { 56 level: 9, 57 resolution: 0.00274658203125, 58 scale: 1154287.4728857423, 59 }, 60 61 { 62 level: 10, 63 resolution: 0.001373291015625, 64 scale: 577143.73644287116, 65 }, 66 67 { 68 level: 11, 69 resolution: 0.0006866455078125, 70 scale: 288571.86822143558, 71 }, 72 73 { 74 level: 12, 75 resolution: 0.00034332275390625, 76 scale: 144285.93411071779, 77 }, 78 79 { 80 level: 13, 81 resolution: 0.000171661376953125, 82 scale: 72142.967055358895, 83 }, 84 85 { 86 level: 14, 87 resolution: 8.58306884765625e-005, 88 scale: 36071.483527679447, 89 }, 90 91 { 92 level: 15, 93 resolution: 4.291534423828125e-005, 94 scale: 18035.741763839724, 95 }, 96 97 { 98 level: 16, 99 resolution: 2.1457672119140625e-005,100 scale: 9017.8708819198619,101 },102 103 {104 level: 17,105 resolution: 1.0728836059570313e-005,106 scale: 4508.9354409599309,107 },108 109 {110 level: 18,111 resolution: 5.3644180297851563e-006,112 scale: 2254.4677204799655,113 },114 ],115 };
2.使用dojo的方式引入调用天地图要使用的插件
dojo.require('esri.layers.WebTiledLayer'); // 加载天地图
3.调用天地图插件引用天地图
1 // 加载天地图底图 2 function LoadingTianDiMap() { 3 const tileInfo = new esri.layers.TileInfo(tileInfoObj); // 这是我们自定义的比例尺转换工具类 4 // 电子底图 5 myDtLayer = new esri.layers.WebTiledLayer("https://${subDomain}.tianditu.com/DataServer?T=vec_c&X=${col}&Y=${row}&L=${level}", { 6 copyright: 'Tianditu', 7 id: 'Tianditu0', 8 subDomains: ['t0', 't1', 't2'], 9 tileInfo,10 });11 // 卫星底图12 mySatelliteLayer = new esri.layers.WebTiledLayer("https://${subDomain}.tianditu.com/DataServer?T=img_c&X=${col}&Y=${row}&L=${level}", {13 copyright: 'Tianditu',14 id: 'Tianditu',15 subDomains: ['t0', 't1', 't2'],16 tileInfo,17 });18 mySatelliteLayer.hide(); // 默认隐藏19 // 标注图层20 baseMapMarker = new esri.layers.WebTiledLayer("https://${subDomain}.tianditu.com/DataServer?T=cva_c&X=${col}&Y=${row}&L=${level}", {21 copyright: 'Tianditu',22 id: 'Tianditu2',23 subDomains: ['t0', 't1', 't2'],24 tileInfo,25 });26 map.addLayer(myDtLayer, 0);27 map.addLayer(mySatelliteLayer, 1); // 添加卫星图28 map.addLayer(baseMapMarker, 2);29 zoom = 11;30 }