Custom feature layer does not show in Legend.

539
4
Jump to solution
08-09-2023 12:28 PM
EugeneStaten
New Contributor III

Hi,

I am trying to extend FeatureLayer in order to add minor, but important to me, functions and properties.

When I do create and instance of the FeatureLayer sublayer, I can see no legend, where I do see a legend when I use the generic FeatureLayer.

Even this example of a Sublayer for Feature layer does not show any symbols in the legend:

 

@subclass("myproj.classes.layers.CustomFeatureLayer")
export class CustomFeatureLayer extends FeatureLayer {
       //Purposely left empty to test legend
}

 

 

EugeneStaten_0-1691608953400.png

 

What should I do to make a subclass of a FeatureLayer recognizable by the legend?


Is there a function I can override in the Legend?

Is there something I can add in the ActiveLayerInfo object to make the Legend pay attention?

 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

The Legend determines internally what layers it supports and doesn't via the layer's declaredClass property.  If it isn't a recognized type (e.g. "myproj.classes.layers.CustomFeatureLayer"), then the layer won't be supported.

If you don't have any custom logic driven by the declaredClass property, and none of your added properties or methods contain anything terribly conflicting with the default implementation, you can just reset it (preferably with your constructor);

this.declaredClass = "esri.layers.FeatureLayer";

 

View solution in original post

4 Replies
JoelBennett
MVP Regular Contributor

The Legend determines internally what layers it supports and doesn't via the layer's declaredClass property.  If it isn't a recognized type (e.g. "myproj.classes.layers.CustomFeatureLayer"), then the layer won't be supported.

If you don't have any custom logic driven by the declaredClass property, and none of your added properties or methods contain anything terribly conflicting with the default implementation, you can just reset it (preferably with your constructor);

this.declaredClass = "esri.layers.FeatureLayer";

 

EugeneStaten
New Contributor III

Thanks Joel,

 

That worked!

Now, the obvious, next question:  Can we add a list of custom layer declarations to the Legend's current list of declarations?

0 Kudos
JoelBennett
MVP Regular Contributor

It doesn't look like it; conditional logic based upon the declaredClass property is spread amongst at least 4 supporting modules (none of which is the Legend module itself).

AddisonShaw
New Contributor III

I'd absolutely love if there were controlled versions of some of the widgets, or at least not fully implicit.