require(["esri/layers/MapImageLayer",
"esri/Map",
"esri/views/MapView",
"esri/core/watchUtils",
"dojo/dom",
"dojo/promise/all",
"dojo/query",
"dojo/on",
"dojo/domReady!"
], function (MapImageLayer, Map, MapView, watchUtils, dom, all, query, on) {
var layersData = [];
var layerList = new Array();
map = new Map({
// basemap: "satellite",
ground: "world-elevation"
});
var layer = new MapImageLayer({
url: "http://192.168.1.210:6080/arcgis/rest/services/XXX/MapServer",
sublayers: [
{
id: 8,
title: "XX",
visible: true,
},
{
id: 7,
title: "yy",
visible: true,
},
{
id: 6,
title: "zz",
visible: true,
},
{
id: 5,
title: "kk",
visible: true,
},
{
id: 4,
title: "jj",
visible: true,
},
{
id: 3,
title: "ii",
visible: true,
},
{
id: 2,
title: "oo",
visible: true,
},
{
id: 1,
title: "pp",
visible: true,
},
{
id: 0,
title: "qq",
visible: true,
},
]
});
map.add(layer);
MapView = new MapView({
center: [106.9191005, 27.6883712],//地图中心坐标
container: "viewDiv",
map: map
});
for (var i = 0; i < layer.sublayers.items.length; i++) {
var layersData = { "id": layer.sublayers.items[i].id, "text": layer.sublayers.items[i].title, "checked": true };
layerList.push(layersData);
}
$('#toc').tree({
data: layerList,
checkbox: true, //使节点增加选择框
onCheck: function (node, checked) {
alert(1111);
for (var i = 0; i < layer.sublayers.items.length; i++) {
if (node.id == layer.sublayers.items[i].id) {
if (checked)
layer.sublayers.items[i].visible = true;
else
layer.sublayers.items[i] = false;
}
}
var visible = [];
var nodes = $('#toc').tree("getChecked");
dojo.forEach(nodes, function (node) {
visible.push(node.id);
});
if (visible.length === 0) {
visible.push(-1);
}
}
})
});