Skip to content

Show extruded features

View on GitHub

Extrude features based on their attributes.

Image of show extruded features

Use case

Extrusion is the process of stretching a flat, 2D shape vertically to create a 3D object in a scene. For example, you can extrude building polygons by a height value to create three-dimensional building shapes.

How to use the sample

Tap the button to switch between using population density and total population for extrusion. Higher extrusion directly corresponds to higher attribute values.

How it works

  1. Create a ServiceFeatureTable from a URL.
  2. Create a feature layer from the service feature table.
    • Make sure to set the rendering mode to dynamic, featureLayer.renderingMode = FeatureRenderingMode.dynamic.
  3. Apply a SimpleRenderer to the feature layer.
  4. Set ExtrusionMode of renderer, sceneProperties.extrusionMode = ExtrusionMode.absoluteHeight.
  5. Set extrusion expression of renderer, sceneProperties.extrusionExpression = '[POP2007]/ 10'.

Relevant API

  • ExtrusionExpression
  • ExtrusionMode
  • FeatureLayer
  • SceneProperties
  • ServiceFeatureTable
  • SimpleRenderer

Tags

3D, extrude, extrusion, extrusion expression, height, renderer, scene

Sample Code

show_extruded_features.dart
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
// 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
//
//   https://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.
//

import 'package:arcgis_maps/arcgis_maps.dart';
import 'package:arcgis_maps_sdk_flutter_samples/common/common.dart';
import 'package:flutter/material.dart';

class ShowExtrudedFeatures extends StatefulWidget {
  const ShowExtrudedFeatures({super.key});

  @override
  State<ShowExtrudedFeatures> createState() => _ShowExtrudedFeaturesState();
}

class _ShowExtrudedFeaturesState extends State<ShowExtrudedFeatures>
    with SampleStateSupport {
  // Create a controller for the scene view.
  final _sceneViewController = ArcGISSceneView.createController();
  // A flag for when the scene view is ready and controls can be used.
  var _ready = false;
  // An enum representing types of population statistics.
  var _filterType = FilterType.totalPopulation;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: false,
        left: false,
        right: false,
        child: Stack(
          children: [
            Column(
              children: [
                Expanded(
                  // Add a scene view to the widget tree and set a controller.
                  child: ArcGISSceneView(
                    controllerProvider: () => _sceneViewController,
                    onSceneViewReady: onSceneViewReady,
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  // Create a set of evenly spaced buttons for each FilterType value, and when a button is pressed,
                  // it triggers the changeExtrusionExpression function with the selected filter.
                  children: FilterType.values
                      .map(
                        (filterType) => ElevatedButton(
                          onPressed: () =>
                              changeExtrusionExpression(filterType),
                          child: Text(filterType.name),
                        ),
                      )
                      .toList(),
                ),
              ],
            ),
            // Display a progress indicator and prevent interaction until state is ready.
            LoadingIndicator(visible: !_ready),
          ],
        ),
      ),
    );
  }

  void onSceneViewReady() {
    // Define the Uri for the service feature table (US state polygons).
    final serviceFeatureTableUri = Uri.parse(
      'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3',
    );

    // Create a service feature table from the Uri.
    final featureTable = ServiceFeatureTable.withUri(serviceFeatureTableUri);

    // Create a feature layer from the service feature table.
    final featureLayer = FeatureLayer.withFeatureTable(featureTable);
    // Set the rendering mode of the feature layer to be dynamic (needed for extrusion to work).
    featureLayer.renderingMode = FeatureRenderingMode.dynamic;

    // Create a simple line symbol for the feature layer.
    final simpleLineSymbol = SimpleLineSymbol(
      color: Colors.white.withAlpha(100),
    );
    // Create a simple fill symbol for the feature layer.
    final simpleFillSymbol = SimpleFillSymbol(
      color: const Color(0xFF2727f1),
      outline: simpleLineSymbol,
    );

    // Create a simple renderer for the feature layer.
    final simpleRenderer = SimpleRenderer(symbol: simpleFillSymbol);
    // Get the scene properties from the simple renderer.
    final sceneProperties = simpleRenderer.sceneProperties;

    // Set the renderer scene properties.
    sceneProperties.extrusionMode = ExtrusionMode.absoluteHeight;
    sceneProperties.extrusionExpression = _filterType.extrusionExpression;

    // Set the feature layer's renderer to the defined simple renderer.
    featureLayer.renderer = simpleRenderer;

    // Create a scene with a topographic basemap style.
    final scene = ArcGISScene.withBasemapStyle(BasemapStyle.arcGISTopographic);
    _sceneViewController.arcGISScene = scene;

    // Add the feature layer to the scene's operational layer collection.
    scene.operationalLayers.add(featureLayer);

    // Set the scene view's viewpoint specified by the camera position.
    final point = ArcGISPoint(
      x: -10974490,
      y: 4814376,
      z: 0,
      spatialReference: SpatialReference.webMercator,
    );

    // Create an orbit location camera controller.
    final cameraController =
        OrbitLocationCameraController.withTargetPositionAndCameraDistance(
          targetLocation: point,
          distance: 20000000,
        );

    // Set the scene view's camera controller to the orbit location camera controller.
    _sceneViewController.cameraController = cameraController;

    // Set the ready state variable to true to enable the sample UI.
    setState(() => _ready = true);
  }

  void changeExtrusionExpression(FilterType filterType) {
    setState(() => _filterType = filterType);

    // Get the first layer from the scene view's operational layers.
    final featureLayer =
        _sceneViewController.arcGISScene!.operationalLayers[0] as FeatureLayer;

    // Update the renderer's scene properties to the selected extrusion expression.
    featureLayer.renderer!.sceneProperties.extrusionExpression =
        _filterType.extrusionExpression;
  }
}

// An enum representing different types of population statistics filters.
enum FilterType {
  totalPopulation(
    name: 'Total Population',
    extrusionExpression: '[POP2007] / 10',
  ),

  populationDensity(
    name: 'Population Density',
    extrusionExpression: '[POP07_SQMI] * 5000 + 100000',
  );

  const FilterType({required this.name, required this.extrusionExpression});

  final String name;
  final String extrusionExpression;
}

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