Description |
This function returns the list of Layers present in a CAD document in a JSON List. It is possible to bind the JSON list and turn on or off the particular layer(s). The function is a JavaScript Promise. Below is a sample code snippet that describes how to bind the layer data in your web page. |
$('#DivToShowLayers').html("");
$('#DivToShowLayers').append('<ul><li><h2>Layer Color<span style="margin-left:85px;">Layer Name</span></h2></li></ul>')
var ext = PanoramaAPI.fileName.split('.').pop().toLowerCase();
if (ext == "dxf" || ext == "dwg" || ext == "dgn") {
PanoramaAPI.getCadLayerJSON().then(function (data) {
if (data == null) {
htm = "Error to retrive CAD Layer"
$("#DivToShowLayers").html('<p class="api-error">' + htm + '</p>');
}
else {
var JsonCadLayerObj = JSON.parse(data);
var cadLayerName;
for (var key in JsonCadLayerObj) {
if (JsonCadLayerObj.hasOwnProperty(key)) {
cadLayerName = JsonCadLayerObj[key];
$('#DivToShowLayers').append('<ul><li><input class="api-checkbox" type="checkbox" id=" ' + cadLayerName.Name + 'chk" value="true" checked/><span class="api-vector-colorbox" style="background-color:rgb(' + cadLayerName.Color + ')"> </span><p>' + cadLayerName.Name + '</p></li></ul>');
}
}
//bind layer interactivity
$(document).ready(function () {
$("input[type='checkbox']").change(function () {
if (!this.checked) {
try {
var i;
var gTag = document.getElementsByTagName("g");
var totalGCount = gTag.length;
selectedLayer = $(this).attr('id').trim();
var selectedLayerName = selectedLayer.substring(0, selectedLayer.length - 3);
for (i = 0; i < totalGCount; i++) {
if (gTag[i].getAttribute("layername") == selectedLayerName) {
gTag[i].setAttribute("visibility", "hidden");
}
}
}
catch (ex) {
console.log(ex.name + ":" + ex.message);
}
} else {
var i;
var gTag = document.getElementsByTagName("g");
var totalGCount = gTag.length;
selectedLayer = $(this).attr('id').trim();
var selectedLayerName = selectedLayer.substring(0, selectedLayer.length - 3);
for (i = 0; i < totalGCount; i++) {
if (gTag[i].getAttribute("layername") == selectedLayerName) {
gTag[i].setAttribute("visibility", "visible");
}
}
}
});
});
}
}).catch(function (error) {
//handle error here
});
}
Syntax |
PanoramaAPI.getCadLayerJSON() |
|
Parameters |
NA |
|
Returns |
GetCadLayerResult:JavaScriptObject |
{
"GetCadLayerResult": [{
"Name": "0",
"Color": "255,255,255",
"isModified": "false",
"isFrozen": "false",
"isHidden": "false",
"isLocked": "false"
}, {
"Name": "POINT_NO",
"Color": "255,255,255",
"isModified": "false",
"isFrozen": "false",
"isHidden": "false",
"isLocked": "false"
}, {
"Name": "DESCRIPTION",
"Color": "255,255,255",
"isModified": "false",
"isFrozen": "false",
"isHidden": "false",
"isLocked": "false"
},
....
]
} |
Post your comment on this topic.