Select to view content in your preferred language

LayerList 4.x hide layer

5084
6
Jump to solution
03-13-2017 01:44 PM
jamesa
by
Occasional Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
MattDriscoll
Esri Contributor

Set the listMode on the layer to "hide". See the link below

Layer | API Reference | ArcGIS API for JavaScript 4.3 

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

James,

   If you add a "title" property to your parcelGL layer then it would not show as Untitled layer.

0 Kudos
KenBuja
MVP Esteemed Contributor

You'd have to use the operationalItems property to the collection of layers you want to include

0 Kudos
jamesa
by
Occasional Contributor

Can you show me how do you add that to the code?

I really appreciated that.

Thank you.

0 Kudos
JimNoel
Occasional Contributor

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!

0 Kudos
MattDriscoll
Esri Contributor

Set the listMode on the layer to "hide". See the link below

Layer | API Reference | ArcGIS API for JavaScript 4.3 

JimNoel
Occasional Contributor

Ah, that's a much better way.  Thank you!  I wouldn't have thought of looking under Layer properties rather than LayerList for that.

0 Kudos