I added GraphicLayer to the LayerList Widget sameple and get "Untitled layer." I wonder is there a ways to hide "Untitled layer" or hide MapImageLayer. See code below.
<!DOCTYPE html>
<html>
<head><meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>LayerList widget - 4.3</title><link rel="stylesheet" href="https://js.arcgis.com/4.3/esri/css/main.css">
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style><script src="https://js.arcgis.com/4.3/"></script>
<script>
require([
"esri/views/SceneView", "esri/layers/GraphicsLayer",
"esri/widgets/LayerList",
"esri/WebScene","dojo/domReady!"
], function(
SceneView, GraphicsLayer, LayerList, WebScene
) {var scene = new WebScene({
portalItem: { // autocasts as new PortalItem()
id: "66adfe99eeaf40fc82ad1e94751cff0b"
}
});var view = new SceneView({
container: "viewDiv",
map: scene
});
var parcelGL;
parcelGL = new GraphicsLayer();
scene.add(parcelGL);view.then(function() {
var layerList = new LayerList({
view: view
});// Add widget to the top right corner of the view
view.ui.add(layerList, "top-right");
});
});
</script></head>
Thank you.
Solved! Go to Solution.
Set the listMode on the layer to "hide". See the link below
James,
If you add a "title" property to your parcelGL layer then it would not show as Untitled layer.
You'd have to use the operationalItems property to the collection of layers you want to include
Can you show me how do you add that to the code?
I really appreciated that.
Thank you.
I find that I have to add some code to prevent graphics layers from being added to operationalItems:
layerList.operationalItems.on("before-add", function(event){ if (event.item.layer.type == "graphics") { event.preventDefault(); } });
Whenever layerList tries to add a graphics layer to the list, this cancels that operation. A bit of a hack, hopefully ESRI will come up with a better way of dealing with this!
Set the listMode on the layer to "hide". See the link below
Ah, that's a much better way. Thank you! I wouldn't have thought of looking under Layer properties rather than LayerList for that.