I'm confused on how I can use dynamic layers in the 4.4 api. I have a group of layers published from arcmap like this:


By default, all of the group layers are off, some of the child layers are on, and nothing is visible until the user toggles a group layer on. (this is how it works in 3.x).
In 4.4, I set up some layer like this:
<SPAN class="punctuation token">{</SPAN>
id<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'assets'</SPAN><SPAN class="punctuation token">,</SPAN>
url<SPAN class="punctuation token">:</SPAN> <SPAN class="template-string token"><SPAN class="string token">`</SPAN><SPAN class="interpolation token"><SPAN class="interpolation-punctuation punctuation token">${</SPAN>url<SPAN class="interpolation-punctuation punctuation token">}</SPAN></SPAN><SPAN class="string token">/internal/assets/MapServer`</SPAN></SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="comment token">// sublayers: [{</SPAN>
<SPAN class="comment token">// id: 12, </SPAN>
<SPAN class="comment token">// visible: true</SPAN>
<SPAN class="comment token">// }, {</SPAN>
<SPAN class="comment token">// id: 13, </SPAN>
<SPAN class="comment token">// visible: true</SPAN>
<SPAN class="comment token">// }],</SPAN>
popupTemplate<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
title<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'cid: {cid}'</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>When the map loads, all of the child layers that are visible are displayed. The map looks crazy busy.

So just to test what happens I uncomment the above code to show only sublayer 12.
This works, only sublayer 12 is shown:

Now if I uncomment both sublayers 12 and 13 from the block above, it stops working. I get no image from the server. I checked the network logs.
In the version with no sublayers, the network image request looks like this:
layers:show:43,44,51,50,36,37,38,1,2,3,53,54,6,8,9,10,55,13,14,15,16,17,22,58,59,25,30,31,32,33<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
With one sublayer:
layers<SPAN class="punctuation token">:</SPAN>show<SPAN class="punctuation token">:</SPAN><SPAN class="number token">12</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
With two sublayers:
dynamicLayers<SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">"id"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">13</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"source"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">"mapLayerId"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">13</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">"mapLayer"</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">"id"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">12</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"source"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">"mapLayerId"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">12</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">"mapLayer"</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>My questions are:
- Why does providing no sublayers display the layer incorrectly (ie ignoring group layer visibility)?
- Why do the parameters change from layers to dynamicLayers when switching from one sublayer to two sublayers? - a similar problem is observed here: https://codepen.io/anon/pen/zdpGLL?&editors=100