Skip to content
View inMAUIWPFWinUIView on GitHub

Explore details of a building scene by using filters and sublayer visibility.

Image of a building scene layer

Use case

Buildings and their component parts (in this example, structural, electrical, or architectural) can be difficult to explain and visualize. An architectural firm might share a 3D building model visualization with clients and contractors to let them explore these components by floor and component type.

How to use the sample

Once the scene is loaded, tap the "Building Filter Settings" button to view the filtering options.

  • Select a floor from the "Floor" menu to view the internal details of each floor or "All" to view the entire model. Selecting a floor applies a filter that hides all floors above the selected floor and gives the floors below a transparent, X-ray renderer.
  • Expand the categories under the top-level disciplines to show or hide individual categories in the building model. The entire discipline may be shown or hidden as well.
  • Tap on any features in the building to view the attributes of the feature.

How it works

  1. Create a Scene with the URL to a Building Scene Layer service.
  2. Create a LocalSceneView and add the scene.
  3. Retrieve the BuildingSceneLayer from the scene's operational layers.
  4. When a floor is selected:
    1. A new BuildingFilter is created with two BuildingFilterBlock items.
    2. One block defines the solid renderer for features on the selected floor.
    3. The second block defines the X-ray filter for features on the floors below the selected floor.
    4. Features that exist on floors above the selected floor are not rendered.
    5. If "All" is selected, the ActiveFilter property on the building scene layer is set to null so all features are rendered according to their default settings.
  5. Architectural disciplines and categories are represented by BuildingGroupSublayer and BuildingSublayer objects containing features within a building scene layer. When checked or unchecked, the visibility of the group or sublayer is set to true (visible) or false (hidden).
  6. When a building feature is tapped on:
    1. A call to IdentifyLayerAsync on the LocalSceneView is initiated based on the screen offset of the click.
    2. The SublayerResults property of the returned IdentifyLayerResult will contain the identified features. Note that the building scene layer features are NOT returned in the GeoElements property of the results.
    3. The details of the first identified feature are shown in a popup.

Relevant API

  • BuildingComponentSublayer
  • BuildingFilter
  • BuildingFilterBlock
  • BuildingSceneLayer
  • LocalSceneView
  • Scene

About the data

This sample uses the Esri Building E Local Scene web scene, which contains a Building Scene Layer representing Building E on the Esri Campus in Redlands, CA. The Revit BIM model was brought into ArcGIS using the BIM capabilities in ArcGIS Pro and published to the web as a Building Scene Layer.

Additional information

Buildings in a Building Scene Layer can be very complex models composed of sublayers containing internal and external features of the structure. Sublayers may include structural components like columns, architectural components like floors and windows, and electrical components.

Applying filters to the Building Scene Layer can highlight features of interest in the model. Filters are made up of filter blocks, which contain several properties that allow control over the filter's function. Setting the filter mode to X-Ray, for instance, will render features with a semi-transparent white color so other interior features can be seen. In addition, toggling the visibility of sublayers can show or hide all the features of a sublayer.

Tags

3D, building scene layer, layers

Sample Code

FilterBuildingSceneLayer.xaml.csFilterBuildingSceneLayer.xaml.csFilterBuildingSceneLayer.xaml
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// Copyright 2025 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;

namespace ArcGIS.Samples.FilterBuildingSceneLayer
{
    [ArcGIS.Samples.Shared.Attributes.Sample(
        name: "Filter building scene layer",
        category: "Layers",
        description: "Explore details of a building scene by using filters and sublayer visibility.",
        instructions: "In the filter controls, select floor and category options to filter what parts of the Building Scene Layer are displayed in the scene. Tap on any of the building features to identify them.",
        tags: new[] { "3D", "building scene layer", "layers" })]
    public partial class FilterBuildingSceneLayer : ContentPage
    {
        // Hold a reference to the building scene layer.
        private BuildingSceneLayer _buildingSceneLayer;

        // Store the list of floors in the building.
        private List<string> _floorList = new List<string>();

        // Track the currently selected feature's sublayer for clearing selection.
        private BuildingComponentSublayer _selectedSublayer;

        public FilterBuildingSceneLayer()
        {
            InitializeComponent();
            _ = Initialize();
        }

        private async Task Initialize()
        {
            // Create a scene from a web scene portal item.
            var sceneUri = new Uri("https://arcgisruntime.maps.arcgis.com/home/item.html?id=b7c387d599a84a50aafaece5ca139d44");
            var scene = new Scene(sceneUri);

            // Load the scene.
            await scene.LoadAsync();

            // Set the scene to the scene view.
            MySceneView.Scene = scene;

            // Get the building scene layer from the scene's operational layers.
            _buildingSceneLayer = scene.OperationalLayers
                .OfType<BuildingSceneLayer>()
                .FirstOrDefault();

            if (_buildingSceneLayer != null)
            {
                // Load the building scene layer to access sublayers and statistics.
                await _buildingSceneLayer.LoadAsync();

                // Get the statistics to retrieve floor information.
                var statistics = await _buildingSceneLayer.FetchStatisticsAsync();

                // Note: BldgLevel values are numeric in the dataset.
                if (statistics.ContainsKey("BldgLevel"))
                {
                    // Get the floor values and sort them in descending order (top floor first).
                    var floorStats = statistics["BldgLevel"];
                    _floorList = floorStats.MostFrequentValues.ToList();
                    _floorList.Sort((a, b) => int.Parse(b).CompareTo(int.Parse(a)));
                }

                // Populate the UI controls.
                PopulateFloorPicker();
                PopulateCategoryControls();

                // Listen for taps on the scene view to identify features.
                MySceneView.GeoViewTapped += MySceneView_GeoViewTapped;
            }
        }

        private void PopulateFloorPicker()
        {
            // Add "All" option followed by each floor.
            FloorPicker.Items.Add("All");
            foreach (var floor in _floorList)
            {
                FloorPicker.Items.Add(floor);
            }

            FloorPicker.SelectedIndex = 0;
        }

        private void FloorPicker_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (FloorPicker.SelectedIndex < 0) return;

            ApplyFloorFilter(FloorPicker.Items[FloorPicker.SelectedIndex]);
        }

        private void ApplyFloorFilter(string selectedFloor)
        {
            // If "All" is selected, remove any active filter.
            if (string.IsNullOrEmpty(selectedFloor) || selectedFloor == "All")
            {
                _buildingSceneLayer.ActiveFilter = null;
                return;
            }

            // Create a building filter with two blocks:
            // 1. Solid mode for the selected floor.
            // 2. X-ray mode for floors below (semi-transparent).
            var filter = new BuildingFilter(
                "Floor filter",
                "Show selected floor and x-ray filter for lower floors.",
                new[]
                {
                    new BuildingFilterBlock(
                        "solid block",
                        $"BldgLevel = {selectedFloor}",
                        new BuildingSolidFilterMode()
                    ),
                    new BuildingFilterBlock(
                        "xray block",
                        $"BldgLevel < {selectedFloor}",
                        new BuildingXrayFilterMode()
                    )
                });

            _buildingSceneLayer.ActiveFilter = filter;
        }

        private void PopulateCategoryControls()
        {
            CategoriesStackLayout.Children.Clear();

            if (_buildingSceneLayer == null) return;

            // Get the "Full Model" sublayer group which contains all categories.
            var fullModelSublayer = _buildingSceneLayer.Sublayers
                .OfType<BuildingGroupSublayer>()
                .FirstOrDefault(s => s.Name == "Full Model");

            if (fullModelSublayer == null) return;

            // Create expandable UI for each category (e.g., Architectural, Structural, Electrical).
            foreach (BuildingGroupSublayer categorySublayer in fullModelSublayer.Sublayers)
            {
                CategoriesStackLayout.Children.Add(CreateCategoryItem(categorySublayer));
            }
        }

        private View CreateCategoryItem(BuildingGroupSublayer categorySublayer)
        {
            var mainStack = new VerticalStackLayout { Spacing = 4, Margin = new Thickness(0, 4) };

            // Category header with expand button, name, and visibility checkbox.
            var headerLayout = new HorizontalStackLayout { Spacing = 8 };

            var expandButton = new Button
            {
                Text = "▶",
                FontSize = 12,
                WidthRequest = 30,
                HeightRequest = 30,
                Padding = 0,
                BackgroundColor = Colors.Transparent
            };

            var categoryCheckBox = new CheckBox { IsChecked = categorySublayer.IsVisible };
            categoryCheckBox.CheckedChanged += (s, e) => categorySublayer.IsVisible = e.Value;

            var nameLabel = new Label
            {
                Text = categorySublayer.Name,
                FontAttributes = FontAttributes.Bold,
                VerticalOptions = LayoutOptions.Center
            };

            headerLayout.Add(expandButton);
            headerLayout.Add(categoryCheckBox);
            headerLayout.Add(nameLabel);

            mainStack.Children.Add(headerLayout);

            // Component sublayers (collapsed by default).
            var componentsStack = new VerticalStackLayout
            {
                Margin = new Thickness(40, 4, 0, 0),
                Spacing = 4,
                IsVisible = false
            };

            foreach (BuildingComponentSublayer componentSublayer in categorySublayer.Sublayers)
            {
                var componentLayout = new HorizontalStackLayout { Spacing = 8 };

                var componentCheckBox = new CheckBox { IsChecked = componentSublayer.IsVisible };
                componentCheckBox.CheckedChanged += (s, e) => componentSublayer.IsVisible = e.Value;

                var componentLabel = new Label
                {
                    Text = componentSublayer.Name,
                    VerticalOptions = LayoutOptions.Center
                };

                componentLayout.Add(componentCheckBox);
                componentLayout.Add(componentLabel);
                componentsStack.Children.Add(componentLayout);
            }

            mainStack.Children.Add(componentsStack);

            // Toggle expand/collapse when button is clicked.
            expandButton.Clicked += (s, e) =>
            {
                componentsStack.IsVisible = !componentsStack.IsVisible;
                expandButton.Text = componentsStack.IsVisible ? "▼" : "▶";
            };

            return mainStack;
        }

        private async void MySceneView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Maui.GeoViewInputEventArgs e)
        {
            // Clear any previous selection.
            if (_selectedSublayer != null)
            {
                _selectedSublayer.ClearSelection();
                _selectedSublayer = null;
            }

            // Reset panel visibility.
            FeaturePanel.IsVisible = false;
            SettingsPanel.IsVisible = true;

            if (_buildingSceneLayer == null) return;

            // Identify features at the tapped location.
            var identifyResult = await MySceneView.IdentifyLayerAsync(
                _buildingSceneLayer,
                e.Position,
                5,
                false);

            // Process the first identified feature.
            if (identifyResult.SublayerResults.Any())
            {
                var sublayerResult = identifyResult.SublayerResults.First();

                if (sublayerResult.GeoElements.Any())
                {
                    var identifiedFeature = sublayerResult.GeoElements.First() as Feature;
                    var sublayer = sublayerResult.LayerContent as BuildingComponentSublayer;

                    if (identifiedFeature != null && sublayer != null)
                    {
                        // Select the feature and display its attributes.
                        sublayer.SelectFeature(identifiedFeature);
                        _selectedSublayer = sublayer;
                        DisplayFeatureAttributes(identifiedFeature);
                    }
                }
            }
        }

        private void DisplayFeatureAttributes(Feature feature)
        {
            FeatureAttributesCollection.ItemsSource = feature.Attributes
                .Select(a => new BuildingSceneFeatureAttribute(a.Key, a.Value?.ToString() ?? "N/A"))
                .ToList();

            SettingsPanel.IsVisible = false;
            FeaturePanel.IsVisible = true;
        }

        private void CloseFeatureButton_Clicked(object sender, EventArgs e)
        {
            if (_selectedSublayer != null)
            {
                _selectedSublayer.ClearSelection();
                _selectedSublayer = null;
            }

            FeaturePanel.IsVisible = false;
            FeatureAttributesCollection.ItemsSource = null;
            SettingsPanel.IsVisible = true;
        }
    }

    /// <summary>
    /// This class represents a key-value pair for displaying feature attributes. It is used instead of a
    /// KeyValuePair generic to help data binding in the xaml file.
    /// </summary>
    public sealed class BuildingSceneFeatureAttribute
    {
        public string Key { get; set; }
        public string Value { get; set; }

        public BuildingSceneFeatureAttribute(string key, string value)
        {
            Key = key;
            Value = value;
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.