View on GitHub Sample viewer app

Apply a unique value with alternate symbols at different scales.

ApplyUniqueValuesWithAlternateSymbols

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: 1:0-1:5000, 1:5000-1:10000, 1:10000-1:20000. To go back to the initial viewpoint, click “Reset Viewpoint”.

How it works

  1. Create a FeatureLayer using the service url and add it to the map’s list of operational layers.
  2. Create two alternate symbols:
    • Create a symbol using SimpleMarkerSymbol.
    • Convert the simple marker symbol to a MultilayerPointSymbol using SimpleMarkerSymbol.toMultilayerSymbol().
    • Set the valid scale range through reference properties on the multilayer point symbols by calling multilayerPointSymbol.setReferenceProperties(new SymbolReferenceProperties(double minScale, double maxScale)).
  3. Create a new UniqueValue, and add it to a new UniqueValueRenderer with uniqueValueRenderer.getUniqueValues.add(uniqueValue).
  4. Set the field name, unique values, and the default symbol on the unique value renderer with new UniqueValueRenderer(List.of("req_type"), List.of(uniqueValue), "", multilayerPurpleDiamondSymbol);.
  5. Apply this unique value renderer to the feature layer with featureLayer.setRenderer(uniqueValueRenderer).

Relevant API

  • MultilayerPointSymbol
  • SimpleMarkerSymbol
  • SymbolReferenceProperties
  • UniqueValue
  • UniqueValueRenderer

About the data

The San Francisco 311 incidents layer used in this sample displays point features related to crime incidents such as graffiti and tree damage that have been reported by city residents.

Tags

alternate symbols, multilayer symbol, scale based rendering, simple marker symbol, symbol reference properties, symbology, unique value, unique value renderer

Sample Code

module-info.java module-info.java ApplyUniqueValuesWithAlternateSymbolsSample.java
/*
* 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.
*/
module com.esri.samples.apply_unique_values_with_alternate_symbols {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
exports com.esri.samples.apply_unique_values_with_alternate_symbols;
}