MapImageLayer, 100s of not-visible sublayers

02-26-2019 03:16 AM
New Contributor III


We are in the process of re-writing a large internal web application that has 100's of users a day. I originally wrote this many years back using v3 (flex) and it is still functioning perfectly today. We are now in the process of a re-write using VueJS and so I am slowly getting intimate with the documentation for v4 but I am unfortunately not finding everything I need.

Onto my question:

We are loading in many MapImageLayers, some with 100's of layers/sublayers. Each of these MapServices have every single sublayer with a default visibility of false so that a user can fire up a LayerList/TOC component and switch them on or off. 

The issue, which is probably due to my poor understanding, is that these sublayers do not exist in 

mapImageLayer.subLayers.items unless I explicitly define them in the constructor with a visibility of false. I assume this is where findSubLayerById() looks?

Obviously I am unable to know these layer id's up-front so am I missing something obvious on how to add these sublayers correctly without having to specify them?

I can see all the sublayers  in mapImageLayer.serviceSublayers but I have not been able to find this property documented so wonder if I should not be touching it?

Thanks for any help 


0 Kudos
2 Replies
New Contributor III

Ok, I think I have worked it out but I will leave this here in case I am doing something bad or someone else hits the issue.

It looks like I need to reset sublayers by cloning the service's sublayers.
There is a method called mapImageLayer.createServiceSubLayers documented here: 

MapImageLayer | API Reference | ArcGIS API for JavaScript 4.10 

0 Kudos
New Contributor III

Ignore all this nonsense, the dynamic building of the MapImageLayers were passing in an empty array to baselayers if none were to be displayed which was clearing it!


0 Kudos