I have found that if we add a Feature Layer to a map with visible property set to false like so, we cannot toggle the layer back on by just setting the visible property back to true:
// If visible is false when adding the feature layer, cannot toggle the layer back on by clicking the button
var featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",
visible: false
});
map.add(featureLayer);
However, if we set the visible property to true while adding the layer, the layer can be toggled on/off by setting visible property true/false.
Here is a JS Fiddle showing visible property false when adding the layer (Here is the bug): JSFiddle
Here is a JS Fiddle showing visible property true when adding the layer: JSFiddle
Is there a workaround around this? Is the fix for this bug in the Esri backlog?
Note: some other layers (eg: vector tile layers) do seem to work ok even though the visible property is false when adding the layer. I have seen this bug only in the feature layer so far.
Solved! Go to Solution.
Hi there,
It is a bug.
This workaround works for me and hope it does for you. Don't set the visible property to false in the feature layer's constructor. Instead set the FeatureLayer.visible = false when layerview is created as shown below.
view.whenLayerView(featureLayer)
.then(function(layerView) {
featureLayer.visible = false;
})
.otherwise(function(error) {
// An error occurred during the layerview creation
});
Mukta,
I see the same thing here. I even tried to set the visibility on the layerView as well.
Maybe Rene Rubalcava or Undral Batsukh could help
Hi there,
It is a bug.
This workaround works for me and hope it does for you. Don't set the visible property to false in the feature layer's constructor. Instead set the FeatureLayer.visible = false when layerview is created as shown below.
view.whenLayerView(featureLayer)
.then(function(layerView) {
featureLayer.visible = false;
})
.otherwise(function(error) {
// An error occurred during the layerview creation
});