1

Is it possible to change the design of the LayerList widget in this ESRI tutorial ?

I would like the LayerList with no checkboxes and to select one layer at a time just by clicking it’s name. I know you can hide the checkboxes with display: none but how do you select the layers?

Michelle.

enter image description here

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
Michelle
  • 99
  • 2
  • 9

1 Answers1

2

Well, Here is the working solution for this-

Use selection color to select/Unselect the layerList Items:-

enter image description here

JSFiddle:- https://jsfiddle.net/vikash2402/5dcLh450/3/

Below is the working code for this-

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Layer List Dijit</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.20/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css">

<style>
html, body, .container, #map {
    height:100%;
    width:100%;
    margin:0;
    padding:0;
    margin:0;
    font-family: "Open Sans";
}
#map {
    padding:0;
}
#layerListPane{
    width:25%;
}
.esriLayer{
  background-color: #fff;
}
.esriLayerList .esriList{
    border-top:none;
}
.esriLayerList .esriTitle {
  background-color: #fff;
  border-bottom:none;
}
.esriLayerList .esriList ul{
 
}

/* ****** Here you can change the selection color ******* */

.esriListVisible label{
   background-color: aqua !important;
}
.esriCheckbox{
  display: none !important;
}
</style>
<script>var dojoConfig = { parseOnLoad: true };</script>
<script src="https://js.arcgis.com/3.20/"></script>
<script>
require([
    "esri/arcgis/utils",
    "esri/dijit/LayerList",
    "dijit/layout/BorderContainer",
    "dijit/layout/ContentPane",
    "dojo/domReady!"
], function(
    arcgisUtils,
    LayerList
) {
    //Create a map based on an ArcGIS Online web map id
    arcgisUtils.createMap("f63fed3f87fc488489e27c026fa5d434", "map").then(function(response){
        var myWidget = new LayerList({
           map: response.map,
           layers: arcgisUtils.getLayerList(response)
        },"layerList");
        myWidget.startup();
    });

});
</script>
</head>
<body class="claro">
<div class="container" data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline',gutters:false">
<div id="layerListPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'">
    <div id="layerList"></div>
</div>
<div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"></div>
</div>
</body>
</html>

Hoping this will help you :)

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
  • Thank you @Developerrrr this is very helpful :) Is it possible each time you click on a layer, the previous one to deactivate? So you always have only one layer on the map? – Michelle Apr 17 '17 at 15:45
  • yeah..that is feasible.. I will updated that one too very soon.. however if this answers your first question, can u plz accept this as an answer... – Vikash Pandey Apr 17 '17 at 15:50
  • I checked the answer for accept. I can open a new ticket with the updated question if necessary. Sorry @Developerrrr , I am kind of new around here :) – Michelle Apr 17 '17 at 18:09
  • No problem.. it would be great if u can create a new question/ticket. and just me know the new link.. However i will update as soon as i find the answer... – Vikash Pandey Apr 17 '17 at 18:46
  • I created the new question [here](http://stackoverflow.com/questions/43457902/single-layer-visible-in-layerlist-widget-arcgis-javascript). I found a code for the [LayerToggle widget](https://github.com/tmcgee/cmv-widgets/blob/master/widgets/LayerToggle.js) that does the one layer visibility but it is designed for The Configurable Map Viewer, not for ArcGIS API for JavaScript. Not sure if the code can be adapted. – Michelle Apr 17 '17 at 19:16
  • Thank you @Developerrrr I will be waiting for your recommendations – Michelle Apr 20 '17 at 09:59