Apply a unique value with alternate symbols at different scales.
Use case
When a layer is symbolized with unique value symbology, you can specify the visible scale range for each unique value. This is an effective strategy to limit the amount of detailed data at smaller scales without having to make multiple versions of the layer, each with a unique definition query.
Once scale ranges are applied to unique values, you can further refine the appearance of features within those scale ranges by establishing alternate symbols to different parts of the symbol class scale range.
How to use the sample
Zoom in and out of the map to see alternate symbols at each scale. The symbology changes according to the following scale ranges: 0-5000, 5000-10000, 10000-20000. To go back to the initial viewpoint, press "Reset Viewpoint".
How it works
-
Create a
featureLayer
using the service url and add it to the map's list of operational layers. -
Create two alternate symbols (a blue square and a yellow diamond) to be used as alternate symbols. To create an alternate symbol:
a. Create a symbol using
SimpleMarkerSymbol
.b. Convert the simple marker symbol to a
MultilayerSymbol
usingSimpleMarkerSymbol.toMultilayerSymbol()
.c. Set the valid scale range through reference properties on the multilayer point symbols blue square and yellow diamond by calling
MultilayerSymbol.referenceProperties
. -
Create a third multilayer symbol to be used to create a
UniqueValue
class. -
Create a unique value using the red triangle from step 3 and the list of alternate symbols from step 2.
-
Create a
UniqueValueRenderer
and add the unique value from step 4 to it. -
Create a purple diamond simple marker and convert it to a multilayer symbol to be used as the default symbol.
-
Set the default symbol on the unique value renderer to the purple diamond from step 6 using
setDefaultSymbol
. -
Set the
fieldNames
on the unique value renderer to "req_type". -
Apply this unique value renderer to the renderer on feature layer.
Relevant API
- MultilayerSymbol
- SimpleMarkerSymbol
- SymbolReferenceProperties
- UniqueValue
- UniqueValueRenderer
About the data
The San Francisco 311 incidents layer in this sample displays point features related to crime incidents such as grafitti and tree damage that have been reported by city residents.
Tags
alternate symbols, multilayer symbol, scale based rendering, simple marker symbol, symbol reference properties, unique value, unique value renderer
Sample Code
// [WriteFile Name=ApplyUniqueValuesWithAlternateSymbols, Category=Layers]
// [Legal]
// Copyright 2022 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.
// [Legal]
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Esri.ArcGISRuntime 100.15
import Esri.ArcGISExtras 1.1
Rectangle {
id: rootRectangle
clip: true
width: 800
height: 600
MapView {
id: mapView
anchors.fill: parent
Component.onCompleted: {
// Set and keep the focus on MapView to enable keyboard navigation
forceActiveFocus();
}
Map {
initBasemapStyle: Enums.BasemapStyleArcGISTopographic
FeatureLayer {
id: featureLayer
ServiceFeatureTable {
id: featureTable
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/0"
}
}
onLoadStatusChanged: {
if (loadStatus === Enums.LoadStatusLoaded) {
mapView.setViewpoint(initialViewpoint);
}
// Create the class breaks renderer with alternate symbols and assign it to the feature layer renderer
featureLayer.renderer = createUniqueValueRenderer();
}
}
}
ViewpointCenter {
id: initialViewpoint
center: Point {
x: -13631205.660131
y: 4546829.846004
}
targetScale: 25000
}
Rectangle {
anchors {
margins: 5
left: parent.left
top: parent.top
}
width: childrenRect.width
height: childrenRect.height
color: "#000000"
opacity: .75
radius: 5
ColumnLayout {
Text {
color: "#ffffff"
text: "Current scale: 1:" + Math.round(mapView.mapScale)
Layout.fillWidth: true
Layout.margins: 3
font {
weight: Font.DemiBold
pointSize: 10
}
}
Button {
text: qsTr("Reset Viewpoint")
font {
weight: Font.DemiBold
pointSize: 10
}
Layout.margins: 3
Layout.fillWidth: true
onClicked: mapView.setViewpointAndSeconds(initialViewpoint, 5);
}
}
}
function createUniqueValueRenderer() {
// Create the default symbol
const purpleDiamond = ArcGISRuntimeEnvironment.createObject("SimpleMarkerSymbol", {
color: "purple",
size: 15,
style: Enums.SimpleMarkerSymbolStyleDiamond
});
const purpleDiamondMultilayer = purpleDiamond.toMultilayerSymbol();
const redTriangle = ArcGISRuntimeEnvironment.createObject("SimpleMarkerSymbol", {
color: "red",
size: 30,
style: Enums.SimpleMarkerSymbolStyleTriangle
});
const redTriangleMultilayer = redTriangle.toMultilayerSymbol();
redTriangleMultilayer.referenceProperties = ArcGISRuntimeEnvironment.createObject("SymbolReferenceProperties", {minScale: 5000, maxScale: 0});
const alternateSymbols = createAlternateSymbols();
const uniqueValue = ArcGISRuntimeEnvironment.createObject("UniqueValue", {label: "unique value", description: "unique value with alternate symbols", values: ["Damaged Property"], symbol: redTriangleMultilayer});
uniqueValue.alternateSymbols.append(alternateSymbols[0]);
uniqueValue.alternateSymbols.append(alternateSymbols[1]);
// Create the unique value renderer using the class break created above
const uniqueValueRenderer = ArcGISRuntimeEnvironment.createObject("UniqueValueRenderer");
uniqueValueRenderer.defaultSymbol = purpleDiamondMultilayer;
uniqueValueRenderer.fieldNames = ["req_type"];
uniqueValueRenderer.uniqueValues.append(uniqueValue);
return uniqueValueRenderer;
}
function createAlternateSymbols() {
// Alternate symbol 1
const blueSquare = ArcGISRuntimeEnvironment.createObject("SimpleMarkerSymbol", {
color: "blue",
size: 45,
style: Enums.SimpleMarkerSymbolStyleSquare
});
const blueSquareMultilayer = blueSquare.toMultilayerSymbol();
blueSquareMultilayer.referenceProperties = ArcGISRuntimeEnvironment.createObject("SymbolReferenceProperties", {minScale: 10000, maxScale: 5000});
// Alternate symbol 2
const yellowDiamond = ArcGISRuntimeEnvironment.createObject("SimpleMarkerSymbol", {
color: "yellow",
size: 30,
style: Enums.SimpleMarkerSymbolStyleDiamond
});
const yellowDiamondMultilayer = yellowDiamond.toMultilayerSymbol();
yellowDiamondMultilayer.referenceProperties = ArcGISRuntimeEnvironment.createObject("SymbolReferenceProperties", {minScale: 20000, maxScale: 10000});
return [blueSquareMultilayer, yellowDiamondMultilayer];
}
}