Layer List Window, change colors of individual services listed

1280
7
Jump to solution
01-31-2020 06:36 AM
GeorgeKatsambas
Occasional Contributor III

Is there a way that map services in the layer list can be separated with different colors. I have attached an example.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

George,

   Sure here is a rough solution.

In the LayerList widget.js find this function and make this change:

      showLayers: function() {
        // summary:
        //    create a LayerListView module used to draw layers list in browser.
        this.layerListView = new LayerListView({
          operLayerInfos: this.operLayerInfos,
          layerListWidget: this,
          layerFilter: this.layerFilter,
          config: this.config
        }).placeAt(this.layerListBody);

//RJS code changes begin
        setTimeout(lang.hitch(this, function(){
          var nodes = query('div[class^="layer-title-div"]');
          nodes.map(function(node){
            var randomColor = Math.floor(Math.random()*16777215).toString(16);
            html.setStyle(node, 'color', "#"+randomColor);
          });
        }), 1000);
//RJS code changes end

        if(this.config.expandAllLayersByDefault) {
          this.layerListView.foldOrUnfoldAllLayers(false);
        }
      },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

7 Replies
RobertScheitlin__GISP
MVP Emeritus

George,

   Sure here is a rough solution.

In the LayerList widget.js find this function and make this change:

      showLayers: function() {
        // summary:
        //    create a LayerListView module used to draw layers list in browser.
        this.layerListView = new LayerListView({
          operLayerInfos: this.operLayerInfos,
          layerListWidget: this,
          layerFilter: this.layerFilter,
          config: this.config
        }).placeAt(this.layerListBody);

//RJS code changes begin
        setTimeout(lang.hitch(this, function(){
          var nodes = query('div[class^="layer-title-div"]');
          nodes.map(function(node){
            var randomColor = Math.floor(Math.random()*16777215).toString(16);
            html.setStyle(node, 'color', "#"+randomColor);
          });
        }), 1000);
//RJS code changes end

        if(this.config.expandAllLayersByDefault) {
          this.layerListView.foldOrUnfoldAllLayers(false);
        }
      },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
GeorgeKatsambas
Occasional Contributor III

Thanks Robert, That did what I wanted but font size was made smaller and some colors hard to see, can I add Bold or larger font and better colors?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Sure that is just a matter of adding the correct style to the text.

CSS font-weight property 

GeorgeKatsambas
Occasional Contributor III

p.thicker {
  font-weight: 900;
}

Where would I add this in the widget.js , after RJS code changes ?

showLayers: function() {
// summary:
// create a LayerListView module used to draw layers list in browser.
this.layerListView = new LayerListView({
operLayerInfos: this.operLayerInfos,
layerListWidget: this,
layerFilter: this.layerFilter,
config: this.config
}).placeAt(this.layerListBody);
//RJS code changes begin
setTimeout(lang.hitch(this, function(){
var nodes = query('div[class^="layer-title-div"]');
nodes.map(function(node){
var randomColor = Math.floor(Math.random()*16777215).toString(16);
html.setStyle(node, 'color', "#"+randomColor);
});
}), 1000);
//RJS code changes end

0 Kudos
RobertScheitlin__GISP
MVP Emeritus
//RJS code changes begin
        setTimeout(lang.hitch(this, function(){
          var nodes = query('div[class^="layer-title-div"]');
          nodes.map(function(node){
            var randomColor = Math.floor(Math.random()*16777215).toString(16);
            html.setStyle(node, 'color', "#"+randomColor);
            html.setStyle(node, 'font-weight', 900);
          });
        }), 500);
//RJS code changes end
GeorgeKatsambas
Occasional Contributor III

Thanks, out of curiosity what does 900 and 500 refer to?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

900 is the font weight and 500 is a half second of time that the setTimeout is waiting for.