Change the appearance of a feature layer with a renderer.
Use case
A feature layer hosted on ArcGIS Online has a preset renderer and will display in an ArcGIS Runtime application with that renderer. However, for example, the color associated with the original renderer may be unsuitable for a company with staff or clients who are color blind, or for presentation with a different set of basemap and operational layers. In these cases, the renderer on the feature layer's data can be set to a more suitable color.
How to use the sample
Use the button in the control panel to change the renderer on the feature layer. The original renderer displays orange circles, the diameters of which are proportional to carbon storage of each tree. When the blue renderer in this sample is applied, it displays the location of the trees simply as blue points.
How it works
- Create a
ServiceFeatureTable
from a URL. - Create a
FeatureLayer
from the service feature table. - Create a new renderer (in this case, a
SimpleRenderer
). - Change the feature layer's renderer using
FeatureLayer.setRenderer(SimpleRenderer)
.
Relevant API
- FeatureLayer.setRenderer
- ServiceFeatureTable
- SimpleRenderer
About the data
This sample displays a feature layer in Warren Wilson College, North Carolina, showing carbon storage of trees on campus. The size of each circle is proportional to that particular tree's carbon storage total.
Tags
feature layer, renderer, visualization
Sample Code
//
// Copyright 2024 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:flutter/material.dart';
import '../../utils/sample_state_support.dart';
class ApplySimpleRendererToFeatureLayer extends StatefulWidget {
const ApplySimpleRendererToFeatureLayer({super.key});
@override
State<ApplySimpleRendererToFeatureLayer> createState() =>
_ApplySimpleRendererToFeatureLayerState();
}
class _ApplySimpleRendererToFeatureLayerState
extends State<ApplySimpleRendererToFeatureLayer> with SampleStateSupport {
// The feature layer that will host the symbolized features.
late final FeatureLayer _featureLayer;
// Create the map view controller.
final _mapViewController = ArcGISMapView.createController();
// A flag for when the map view is ready and controls can be used.
var _ready = false;
// State variable indicating if the default renderer is currently being used.
var _usingDefaultRenderer = true;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
top: false,
child: Stack(
children: [
Column(
children: [
Expanded(
// Add a map view to the widget tree and set a controller.
child: ArcGISMapView(
controllerProvider: () => _mapViewController,
onMapViewReady: onMapViewReady,
),
),
Center(
child: ElevatedButton(
onPressed: _usingDefaultRenderer
? overrideRenderer
: resetRenderer,
child: _usingDefaultRenderer
? const Text('Blue Renderer')
: const Text('Orange Renderer'),
),
),
],
),
// Display a progress indicator and prevent interaction before state is ready.
Visibility(
visible: !_ready,
child: SizedBox.expand(
child: Container(
color: Colors.white30,
child: const Center(child: CircularProgressIndicator()),
),
),
),
],
),
),
);
}
void onMapViewReady() {
// Initialize the feature layer with a feature table web service.
final uri = Uri.parse(
'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0',
);
final serviceFeatureTable = ServiceFeatureTable.withUri(uri);
_featureLayer = FeatureLayer.withFeatureTable(serviceFeatureTable);
// Initialize the ArcGISMap.
final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISTopographic)
..operationalLayers.add(_featureLayer)
..initialViewpoint = Viewpoint.fromCenter(
ArcGISPoint(
x: -9177343,
y: 4247283,
spatialReference: SpatialReference.webMercator,
),
scale: 4750,
);
// Add the map to the MapViewController.
_mapViewController.arcGISMap = map;
// Set the ready state variable to true to enable the sample UI.
setState(() => _ready = true);
}
void overrideRenderer() {
// Set a new renderer for the feature layer
final markerSymbol = SimpleMarkerSymbol(
style: SimpleMarkerSymbolStyle.circle,
color: Colors.blue,
size: 5,
);
_featureLayer.renderer = SimpleRenderer(symbol: markerSymbol);
setState(() => _usingDefaultRenderer = false);
}
void resetRenderer() {
// Reset the feature layer renderer
_featureLayer.resetRenderer();
setState(() => _usingDefaultRenderer = true);
}
}