Azure maps group layers in layer control

Brenda Olsen 21 Reputation points
2022-08-08T14:04:54.157+00:00

Hi all, I have an Azure map with many layers. Is it possible to group them, preferably tree-wise, and add those groups to the layer control?

//Create the layer control.  
layerControl = new atlas.control.LayerControl({  
                                //title: 'Layers',  
  
                                //Attach the legend control.  
                                legendControl: legend,  
  
                                dynamicLayerGroup: {  
                                    groupTitle: 'Group 1',  
                                    layout: 'checkbox',  
                                }  
});  
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
595 questions
0 comments No comments
{count} votes

Accepted answer
  1. rbrundritt 15,386 Reputation points Microsoft Employee
    2022-08-08T14:51:14.153+00:00

    The dynamic layer group automatically creates a list of all the user defined layers in the map. You can limit the layers that the dynamic layer group lists, however you can only have one dynamic layer list per layer control. For your scenario, you would most likely have to specify the layers items explicitly in the layer control. You can then create groups of layers, however layer groups can't have sub-groupings, so you can't go multiple groupings deep. You can however make the groups radio or check box lists which may help depending on your scenario.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Brenda Olsen 21 Reputation points
    2022-08-09T07:52:59.147+00:00

    thank you. I made it work like this now:

    layerControl = new atlas.control.LayerControl({  
                                    legendControl: legend,  
                                    layerGroups: [  
                                        {  
                                            layout: 'checkbox',  
                                            groupTitle: 'groupTitle1',  
                                            layers: ['layer1', 'layer2'],  
                                            items: [{  
                                                label: 'layerTitle1',  
                                                layout: 'checkbox',  
                                                enabledStyle: {  
                                                    visible: true  
                                                },  
                                                disabledStyle: {  
                                                    visible: false  
                                                }  
                                                },  
                                                {  
                                                label: 'layerTitle2',  
                                                layout: 'checkbox',  
                                                enabledStyle: {  
                                                    visible: true  
                                                },  
                                                disabledStyle: {  
                                                    visible: false  
                                                }  
                                                }     
                                            ]  
                                        },  
                                        {  
                                            layout: 'checkbox',  
                                            groupTitle: 'group Title 2',  
                                            layers: ['layer3', 'layer4'],  
                                            items: [{  
                                                label: 'layerTitle3',  
                                                layout: 'checkbox',  
                                                enabledStyle: {  
                                                    visible: true  
                                                },  
                                                disabledStyle: {  
                                                    visible: false  
                                                } },  
                                                {  
                                                label: 'layerTitle4',  
                                                layout: 'checkbox',  
                                                enabledStyle: {  
                                                    visible: true  
                                                },  
                                                disabledStyle: {  
                                                    visible: false  
                                                } }     
                                            ]  
                                        }  
                                    ]  
                                });  
    
    0 comments No comments