define([ "dojo/data/ItemFileWriteStore" ], function ( ItemFileWriteStore) { /* take a dynamic service's layerInfos Json and recursive subLayers a typical layerInfos Json is listed at the bottom */ function recursiveSubLayers(index, layerInfos) { var layerInfo = layerInfos[index]; var dataStoreLayer = {}; dataStoreLayer.name = layerInfo.name; dataStoreLayer.id = layerInfo.id; dataStoreLayer.visible = layerInfo.defaultVisibility; var children = []; var isGroupLayer; if ((layerInfo.subLayerIds !== null) && (layerInfo.subLayerIds.length > 0)) { dataStoreLayer.type = 'grouplayer'; isGroupLayer = true; } else { dataStoreLayer.type = 'layer'; isGroupLayer = false; } if (isGroupLayer) { for (var i = 0, len = layerInfo.subLayerIds.length; i < len; i++) { children.push(recursiveSubLayers(layerInfo.subLayerIds[i], layerInfos)); } dataStoreLayer.children = children; } return dataStoreLayer; } /* for map layer does want to show sub layers * apply only to dynamic layer without sublayer * the input is a dynamic layer's layerinfos, the output is a store with nested nodes */ function adaptLayerInfoToDataStore(layerInfos) { var data = []; for (var i = 0, len = layerInfos.length; i < len; i++) { var layer; // if ( (layerInfos[i].subLayerIds !== null) && (layerInfos[i].subLayerIds.length>0) && (layerInfos[i].parentLayerId === -1) ){ // var layer=recursiveSubLayers(i, layerInfos); // data.push(layer); // } if ((layerInfos[i].parentLayerId === -1)) { layer = recursiveSubLayers(i, layerInfos); data.push(layer); } } var storeData = { identifier: 'id', label: 'name', items: data }; var store = new ItemFileWriteStore({ data: storeData }); return store; } /* for map layer does not want to show sub layers * apply to dynamic layer, graphic layer, wms layer * Some times, even the layer is dynamic layers with sub layers, the requirement does not want to * display the sub layers * the input is a layer's information, the output is a store with single object * id could be any number because one layer tree only has one node, so the id is always unique */ function adaptLayerToDataStore(/*layer visibility*/visible, /*layer title*/title, /*a number to identify the tree node*/id) { var data = []; var dataStoreLayer = {}; dataStoreLayer.name = title; dataStoreLayer.id = id; dataStoreLayer.visible = visible; dataStoreLayer.showSubLayers = false; data.push(dataStoreLayer); var storeData = { identifier: 'id', label: 'name', items: data }; var store = new ItemFileWriteStore({ data: storeData }); return store; } // function adaptGraphicLayerToDataStore(visible, title, id){ // var data=[]; // var dataStoreLayer={}; // dataStoreLayer.name=title; // dataStoreLayer.id=id; // dataStoreLayer.visible=visible; // dataStoreLayer.showSubLayers=false; // dataStoreLayer.layerType="graphic"; // data.push(dataStoreLayer); // var storeData= { // identifier: 'id', // label: 'name', // items: data // }; // var store=new dojo.data.ItemFileWriteStore({data:storeData}); // return store; // } // a typical layer's layerInfo structure // var layerInfos= // [ // { // "id": 0, // "name": "Public Safety", // "parentLayerId": -1, // "defaultVisibility": true, // "subLayerIds": [ // 1, // 2, // 3, // 4, // 5, // 6, // 7, // 8 // ], // "minScale": 0, // "maxScale": 0 // }, // { // "id": 1, // "name": "Fire Stations", // "parentLayerId": 0, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 50000, // "maxScale": 0 // }, // { // "id": 2, // "name": "Police Stations", // "parentLayerId": 0, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 50000, // "maxScale": 0 // }, // { // "id": 3, // "name": "Shelters", // "parentLayerId": 0, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 36000, // "maxScale": 0 // }, // { // "id": 4, // "name": "Schools", // "parentLayerId": 0, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 36000, // "maxScale": 0 // }, // { // "id": 5, // "name": "Hospitals", // "parentLayerId": 0, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 50000, // "maxScale": 0 // }, // { // "id": 6, // "name": "Pet Collection Areas", // "parentLayerId": 0, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 36000, // "maxScale": 0 // }, // { // "id": 7, // "name": "Resources", // "parentLayerId": 0, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 36000, // "maxScale": 0 // }, // { // "id": 8, // "name": "Traffic Cameras", // "parentLayerId": 0, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 36000, // "maxScale": 0 // }, // { // "id": 9, // "name": "Emergency Operations", // "parentLayerId": -1, // "defaultVisibility": true, // "subLayerIds": [ // 10 // ], // "minScale": 0, // "maxScale": 0 // }, // { // "id": 10, // "name": "Event Information", // "parentLayerId": 9, // "defaultVisibility": true, // "subLayerIds": [ // 11, // 12, // 13, // 14, // 15, // 16, // 17, // 18, // 19, // 20, // 21 // ], // "minScale": 0, // "maxScale": 0 // }, // { // "id": 11, // "name": "Event Grids", // "parentLayerId": 10, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // }, // { // "id": 12, // "name": "Damage Assessment", // "parentLayerId": 10, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // }, // { // "id": 13, // "name": "Road Blocks", // "parentLayerId": 10, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 36000, // "maxScale": 0 // }, // { // "id": 14, // "name": "Access Points", // "parentLayerId": 10, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 36000, // "maxScale": 0 // }, // { // "id": 15, // "name": "Incident Point", // "parentLayerId": 10, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // }, // { // "id": 16, // "name": "Incident Operations", // "parentLayerId": 10, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // }, // { // "id": 17, // "name": "Incident Line", // "parentLayerId": 10, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // }, // { // "id": 18, // "name": "Incident Area", // "parentLayerId": 10, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // }, // { // "id": 19, // "name": "Evacuation Area", // "parentLayerId": 10, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // }, // { // "id": 20, // "name": "Exclusion Hot Zones", // "parentLayerId": 10, // "defaultVisibility": false, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // }, // { // "id": 21, // "name": "Plumes", // "parentLayerId": 10, // "defaultVisibility": true, // "subLayerIds": null, // "minScale": 0, // "maxScale": 0 // } // ]; return { adaptLayerInfoToDataStore: adaptLayerInfoToDataStore, adaptLayerToDataStore: adaptLayerToDataStore }; });