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 Maps SDK 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 simple renderer is applied, it displays the location of the trees simply as points with random color.
How it works
- Create a
FeatureLayer
from a portal item. - Create a new renderer (in this case, a
SimpleRenderer
). - Change the feature layer's renderer.
Relevant API
- FeatureLayer
- SimpleRenderer
About the data
This sample displays a Landscape Trees 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 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 ArcGIS
import SwiftUI
struct ApplySimpleRendererToFeatureLayerView: View {
@State private var map: Map = {
let map = Map(basemapStyle: .arcGISTopographic)
let featureLayer = FeatureLayer(
item: PortalItem(
portal: .arcGISOnline(connection: .anonymous),
id: PortalItem.ID("6d41340931544829acc8f68c27e69dec")!
)
)
map.addOperationalLayer(featureLayer)
map.initialViewpoint = Viewpoint(latitude: 35.61, longitude: -82.44, scale: 1e4)
return map
}()
/// The feature layer in the map.
private var featureLayer: FeatureLayer {
map.operationalLayers.first as! FeatureLayer
}
var body: some View {
MapView(map: map)
.toolbar {
ToolbarItem(placement: .bottomBar) {
Button("Change Renderer") {
setRenderer()
}
}
}
}
/// Sets the renderer for the feature layer.
private func setRenderer() {
// Creates a simple marker symbol for the renderer.
let symbol = SimpleMarkerSymbol(
style: .circle,
color: [UIColor.red, .yellow, .blue, .green].randomElement()!,
size: 10
)
// Creates a new renderer using the symbol just created.
let renderer = SimpleRenderer(symbol: symbol)
// Assigns the new renderer to the feature layer.
featureLayer.renderer = renderer
}
}
#Preview {
ApplySimpleRendererToFeatureLayerView()
}