Colouring the layers in my LayerList widet

2499
25
Jump to solution
12-15-2023 09:04 AM
DavidShearan
New Contributor III

I am learning more and more all the time with help from this community. With help I have now been able to display the LayerList widget in an HTML div and hide individual layers if there is nothing displayed on the map for the layer.

I would now like to colour the layers to match the graphic symbol I am using on the map. See the attached screenshot so you can understand what I am trying to do.

Thank you in advance

Tags (2)
0 Kudos
25 Replies
DavidShearan
New Contributor III

That’s very good of you, much appreciated 

0 Kudos
Sage_Wall
Esri Contributor

Hi David,

I was finally able to get some time to look at this.  The listItemCreated function actually gets called multiple times (map initialization and at other times) and this is likely why you are seeing the misleading layer count info.  We've actually fixed this in the next version of the API where the function will only be called once.  I moved the log statement to the bottom and have it simply logging out the layers collection and there is only one layer for each category.

To remove the layers without any sightings from the layer list you can simply set the listMode to hide for that layer.  I modified your logic slightly to show this on line 299 of the codepen below.  I hope this helps.

Here is the codepen I was playing with.  https://codepen.io/sagewall/pen/abMNeZQ

DavidShearan
New Contributor III

Hello again. I have adapted my code now for the changes you have made and it works 😊

Thank you so much for al your help. It has made so much difference to my project but also to my understanding. You are very kind

One final question. Is SpatialReference required? I notice you built it in to your working example

0 Kudos
Sage_Wall
Esri Contributor

A spatial reference is required, but if one is not provided the API will infer one based on the geometry of the features. It's best practice to define a spatial reference if possible.

0 Kudos
DavidShearan
New Contributor III

Thank you

AbdulRaufs
New Contributor II

Hi @Sage_Wall ,

I really like your solutions and since being new to Map SDK reaching out to you. I am working on this codepen: https://codepen.io/vntbstgk-the-decoder/pen/ZEPJBEE.

My questions are:

Can we add feature count in front of each legend?

My data is a tree data and I want to get top 5 species in legend in custom legend. Since the data gets updated overtime, I want the legends to be dynamic.

This is a static ExB that i created. https://experience.arcgis.com/experience/d5a32539f144401f946629fdfa2894a7/ I want to create a  dynamic version of this using Map SDK.

0 Kudos