I want to get existing layers from map and toggle on the visibility of the layers. The map has multiple services. I have the rest url for the service or the layer. And able to access the layer by using let fLayer = new FeatureLayer(url,....).

But when I tried on set visibility by using

fLayer.setVisibility(true) or fLayer.show()

didn't work for me.

I have the information on the required layer names or ids in the respective services and the service urls.

Is there any possibility to get a layer from map using the service url and the layer name/id in that service? Please suggest.

  • I suggest you try remove it from the map and re-add it when needed. – NettaB Oct 5 '19 at 21:01
  • But I think, to remove also I should pass layer information to map. I want to know how to get required layer from map in the above condition. – Venkat Oct 6 '19 at 1:48
  • can you share your code so we can help fixing it ? – LMokrane Oct 14 '19 at 10:41
  • Hi LMokrane, I got the solution and the same posted below – Venkat Oct 16 '19 at 5:56

I got the solution by doing similarly as in below link: https://community.esri.com/thread/27093

I need to get the map service as dynamic layer from map, set the visibility of that dynamic layer and send the array of ids of the required layers inside it for setVisibleLayers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.