easyui加载树型控件数据一例
//=============================================================================
//获取hbase geowave的图层列表功能 OK
function initHbaseTableName() {
api_db_layerList(function (tablenameList) {
var arr = new Array();
if (tablenameList) {
var layer;
for (var i = 0; i < tablenameList.length; i++) {
layer = tablenameList[i]; //顶层目录
var cdirs = getChildCatalogs(layer);
//
arr.push({
"id": layer.id,
"text": layer.name,
"checked": false,
"state": "open",
"attributes": "dir",
children: cdirs
});
}
}
layerCtrl.loadData(arr);
});
};
function getChildThematic(layer) {
var cArray = new Array();
if (layer.Thematics.length > 0) {
for (var c = 0; c < layer.Thematics.length; c++) {
var cLayer = layer.Thematics[c];
cArray.push({
"id": cLayer.name,
"text": cLayer.title,
"checked": false,
"attributes": cLayer.url,
});
}
}
return cArray;
};
function getChildCatalogs(layer) {
var cArray = new Array();
if (layer.Catalogs.length > 0) {
for (var c = 0; c < layer.Catalogs.length; c++) {
var cLayer = layer.Catalogs[c];
var childdirs = getChildCatalogs(cLayer);
if (childdirs && childdirs.length > 0) {
cArray.push({
"id": cLayer.id,
"text": cLayer.name,
"checked": false,
"attributes": "dir",
children: childdirs
});
}
else {
var childThematics = getChildThematic(cLayer);
cArray.push({
"id": cLayer.id,
"text": cLayer.name,
"checked": false,
"attributes": "dir",
children: childThematics
});
}
}
}
if (layer.Thematics.length > 0) {
for (var c = 0; c < layer.Thematics.length; c++) {
var cLayer = layer.Thematics[c];
cArray.push({
"id": cLayer.name,
"text": cLayer.title,
"checked": false,
"attributes": cLayer.url,
});
}
}
return cArray;
};
//=============================================================================
//初始化目录树(调用微服务中的目录catalog/catalog服务)
function initCloudCatalogs() {
var params = new FormData();
var cateStd = webconfig.catalog_cateStd;
execute_get("/catalog/catalog/getAllInfo/" + cateStd, params, function (data) {
//ShowJsonEq(data);
var arr = new Array();
if (data) {
var layer;
for (var i = 0; i < data.length; i++) {
layer = data[i]; //顶层目录
var cdirs = getChildCatalogs_cloud(layer);
//
arr.push({
"id": layer.id,
"text": layer.text,
"checked": false,
"state": "open",
"attributes": "dir",
children: cdirs
});
}
}
layerCtrl.loadData(arr);
layerCtrl.setCheckedALL(true);
});
};
function getChildCatalogs_cloud(layer) {
var cArray = new Array();
if (layer.children && layer.children.length > 0) {
for (var c = 0; c < layer.children.length; c++) {
var cLayer = layer.children[c];
var childdirs = getChildCatalogs_cloud(cLayer);
if (childdirs && childdirs.length > 0) {
cArray.push({
"id": cLayer.id,
"text": cLayer.text,
"checked": false,
"attributes": "dir",
children: childdirs
});
}
else {
var childThematics = getChildResNodes(cLayer);
cArray.push({
"id": cLayer.id,
"text": cLayer.text,
"checked": false,
"attributes": "dir",
children: childThematics
});
}
}
}
if (layer.object && layer.object.ldapRes && layer.object.ldapRes.length > 0) {
var childResArray = getChildResNodes(layer);
return childResArray;
}
return cArray;
};
function getChildResNodes(layer) {
var cArray = new Array();
if (layer.object && layer.object.ldapRes && layer.object.ldapRes.length > 0) {
for (var c = 0; c < layer.object.ldapRes.length; c++) { //资源集合
var cLayer = layer.object.ldapRes[c];
var childMaps = getChildMapNodes(cLayer);
/*cArray.push({
"id": cLayer.id,
"text": cLayer.resName,
"checked": false,
"attributes": "res",
children: childMaps
});*/
for(var index=0;index<childMaps.length;index++){
cArray.push(childMaps[index]);
}
}
}
return cArray;
};
function getChildMapNodes(cLayer)
{
var cArray=new Array();
if(cLayer.ldapResMaps.length>0)
{
//http://192.168.30.23:8080/geoserver
var mapUrl=cLayer.dbUrl;
for(var c=0;c<cLayer.ldapResMaps.length;c++)
{ //地图集合
var mapLayer=cLayer.ldapResMaps[c];
cArray.push({
"id": mapLayer.id,
"text": mapLayer.mapTitle,
"checked": false,
"attributes": "map|"+mapLayer.mapName+"|"+mapUrl
});
}
}
return cArray;
};
//=============================================================================
//初始化数据树 (调用微服务中的目录服务) tree_data
function initCloudTables()
{
var params = new FormData();
var cateStd ="001"; //矢量数据表集合
execute_get("/catalog/catalog/getCatalogTableByStd/" + cateStd, params, function (data) {
//ShowJsonEq(data);
var arr = new Array();
if (data) {
var layer;
for (var i = 0; i < data.length; i++) {
layer = data[i]; //顶层目录
var cdirs = getChildTables_cloud(layer);
//
arr.push({
"id": layer.id,
"text": layer.text,
"checked": false,
"state": "open",
"attributes": "dir",
children: cdirs
});
}
}
treeData.loadData(arr);
});
};
function getChildTables_cloud(layer) {
var cArray = new Array();
if (layer.children && layer.children.length > 0) {
for (var c = 0; c < layer.children.length; c++) {
var cLayer = layer.children[c];
var childdirs = getChildTables_cloud(cLayer);
if (childdirs && childdirs.length > 0) {
cArray.push({
"id": cLayer.id,
"text": cLayer.text,
"checked": false,
"attributes": "dir",
children: childdirs
});
}
else {
var childThematics = getChildResTables(cLayer);
cArray.push({
"id": cLayer.id,
"text": cLayer.text,
"checked": false,
"attributes": "dir",
children: childThematics
});
}
}
}
if (layer.object && layer.object.ldapRes && layer.object.ldapRes.length > 0) {
var childResArray = getChildResTables(layer);
return childResArray;
}
return cArray;
};
function getChildResTables(layer) {
var cArray = new Array();
if (layer.object && layer.object.ldapRes && layer.object.ldapRes.length > 0) {
for (var c = 0; c < layer.object.ldapRes.length; c++) { //资源集合
var cLayer = layer.object.ldapRes[c];
var childMaps = getChildTableNodes(cLayer);
/*cArray.push({
"id": cLayer.id,
"text": cLayer.resName,
"checked": false,
"attributes": "res",
children: childMaps
});*/
for(var index=0;index<childMaps.length;index++){
cArray.push(childMaps[index]);
}
}
}
return cArray;
};
function getChildTableNodes(cLayer)
{
var cArray=new Array();
if(cLayer.ldapResTables.length>0)
{
//http://192.168.30.23:8080/geoserver
var mapUrl=cLayer.dbUrl;
for(var c=0;c<cLayer.ldapResTables.length;c++)
{ //地图集合
var tableObj=cLayer.ldapResTables[c];
cArray.push({
"id": tableObj.id,
"text": tableObj.tableAlias+"("+tableObj.tableType+")",
"checked": false,
"attributes": "table|"+tableObj.tableName+"|"+tableObj.tableType+"|"+mapUrl
});
}
}
return cArray;
};
//=============================================================================
//初始化加载图层树 功能 /auth/layertree/getTreeByStd/{std}
function initCloudLayerTree()
{
var params ={};// new FormData();
var cateStd = webconfig.catalog_cateStd;
execute_ajax("/api/layertree/getTreeByStd/" + cateStd,"get", params, function (r) {
//ShowJsonEq(r);
var arr = new Array();
if (r.data) {
var layer;
var data=r.data;
for (var i = 0; i < data.length; i++) {
layer = data[i]; //顶层目录
var cdirs = getChildLayerTree(layer);
//
arr.push({
"id": layer.id,
"text": layer.text,
"checked": false,
"state": "open",
"attributes": layer.object,
children: cdirs
});
}
}
layerCtrl.loadData(arr);
//layerCtrl.setCheckedALL(true);
getInitLayerArray(layerCtrl);
loadLayers_LayerTree();
setInitCheckedTree(layerCtrl);
});
};
function getChildLayerTree(layer) {
var cArray = new Array();
if (layer.children && layer.children.length > 0) {
for (var c = 0; c < layer.children.length; c++) {
var cLayer = layer.children[c];
var childdirs = getChildLayerTree(cLayer);
if (childdirs && childdirs.length > 0) {
cArray.push({
"id": cLayer.id,
"text": cLayer.text,
"checked": false,
"state": "closed",
"attributes": cLayer.object,
children: childdirs
});
}
else
{ //无子节点
cArray.push({
"id": cLayer.id,
"text": cLayer.text,
"checked": false,
"attributes": cLayer.object
});
}
}
}
return cArray;
};
//全局变量
var maphash=new Hash();
var mapArray=new Array();
//-------------------------
function getInitLayerArray(layerCtrl){
maphash=new Hash();
mapArray=new Array();
var rootNodes = layerCtrl.getRoots();
if (rootNodes) {
var t_node = null;
for (var index in rootNodes) {
t_node = rootNodes[index];
//
getInitChildrenLayerArray(t_node,layerCtrl);
}
}
};
function getInitChildrenLayerArray(node,layerCtrl) {
if (node) {
if(node.attributes && node.attributes.is_layer=="1")
{
var layerName=node.attributes.layername;
var conn=node.attributes.conn;
if(maphash.containsKey(layerName)==false)
{
mapArray.push(layerName);
var connJson=getConnJsonUrl(conn);
maphash.add(layerName,connJson.url);
}
}
//子节点
if (node.children && node.children.length > 0) {
for (var index in node.children) {
getInitChildrenLayerArray(node.children[index],layerCtrl);
}
}
}
};
//-------------------------
function setInitCheckedTree(layerCtrl) {
var rootNodes = layerCtrl.getRoots();
if (rootNodes) {
var t_node = null;
for (var index in rootNodes) {
t_node = rootNodes[index];
//
setInitCheckedNodeChildren(t_node,layerCtrl);
}
}
};
//设置一个节点及子节点选中功能
function setInitCheckedNodeChildren(node,layerCtrl) {
if (node) {
if (node.attributes && node.attributes.is_visible=="1") {
layerCtrl.setChecked(node.id); //设为选中
}
else {
layerCtrl.setUnChecked(node.id); //取消选中
}
//子节点
if (node.children && node.children.length > 0) {
for (var index in node.children) {
setInitCheckedNodeChildren(node.children[index],layerCtrl);
}
}
}
};
//-------------------------
function loadLayers_LayerTree()
{
for(var i=mapArray.length-1;i>=0;i--)
{ //倒序加载图层顺序
var layerName=mapArray[i];
var geoserver_url =maphash.getValue(layerName);
map.removeLayer(layerName);
map.addLayer(map.createLayer2(layerName, geoserver_url));
}
};
//=============================================================================