AnsweredAssumed Answered

How to use dynamic layers in js api 4.4

Question asked by roemhildtg on Aug 17, 2017
Latest reply on Aug 17, 2017 by roemhildtg

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: 

{
                id: 'assets',
                url: `${url}/internal/assets/MapServer`,
                // sublayers: [{
                //     id: 12,
                //     visible: true
                // }, {
                //     id: 13,
                //     visible: true
                // }],
                popupTemplate: {
                    title: 'cid: {cid}'
                }
            }

 

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

 

With one sublayer:

layers:show:12

 

With two sublayers: 

dynamicLayers:[{"id":13,"source":{"mapLayerId":13,"type":"mapLayer"}},{"id":12,"source":{"mapLayerId":12,"type":"mapLayer"}}]

 

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

Outcomes