Skip To Content ArcGIS for Developers Sign In Dashboard

Unique Value Renderer


 * Copyright 2017 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
 * 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.

package com.esri.samples.symbology.unique_value_renderer;

import java.util.ArrayList;
import java.util.List;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import com.esri.arcgisruntime.geometry.Envelope;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.layers.FeatureLayer;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
import com.esri.arcgisruntime.symbology.UniqueValueRenderer;
import com.esri.arcgisruntime.symbology.UniqueValueRenderer.UniqueValue;

public class UniqueValueRendererSample extends Application {

  private MapView mapView;

  // colors for symbols
  private static final int GRAY = 0xFFD3D3D3;
  private static final int RED = 0xFFFF0000;
  private static final int GREEN = 0xFF00FF00;
  private static final int BLUE = 0xFF0000FF;

  public void start(Stage stage) {

    try {
      // create stack pane and application scene
      StackPane stackPane = new StackPane();
      Scene scene = new Scene(stackPane);

      // set title, size, and add scene to stage
      stage.setTitle("Unique Value Renderer Sample");

      // create ArcGISMap with topographic basemap
      final ArcGISMap map = new ArcGISMap(Basemap.createTopographic());

      // create a view and set ArcGISMap to it
      mapView = new MapView();

      // create service feature table
      String sampleServiceUrl = "";
      ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(sampleServiceUrl);

      // create the feature layer using the service feature table
      final FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);

      // override the feature layer renderer with a new unique value renderer
      UniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer();
      // field name is a key, in a key/value pair, of a feature's attributes
      // can be a list but only looking for one in this case

      // create the symbols to be used in the renderer
      SimpleFillSymbol defaultFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.NULL, 0x00000000,
          new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, GRAY, 2));
      SimpleFillSymbol californiaFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, RED,
          new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, RED, 2));
      SimpleFillSymbol arizonaFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, GREEN,
          new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, GREEN, 2));
      SimpleFillSymbol nevadaFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, BLUE, new SimpleLineSymbol(
          SimpleLineSymbol.Style.SOLID, BLUE, 2));

      // set the default symbol

      // set value for California, Arizona, and Nevada
      List<Object> californiaValue = new ArrayList<>();
      uniqueValueRenderer.getUniqueValues().add(new UniqueValue("State of California", "California",
          californiaFillSymbol, californiaValue));

      List<Object> arizonaValue = new ArrayList<>();
      uniqueValueRenderer.getUniqueValues().add(new UniqueValue("State of Arizona", "Arizona", arizonaFillSymbol,

      List<Object> nevadaValue = new ArrayList<>();
      uniqueValueRenderer.getUniqueValues().add(new UniqueValue("State of Nevada", "Nevada", nevadaFillSymbol,

      // set the renderer on the feature layer

      // add the layer to the ArcGISMap

      // create initial viewpoint using a envelope
      Envelope envelope = new Envelope(-13893029.0, 3573174.0, -12038972.0, 5309823.0, SpatialReferences

      // set viewpoint on ArcGISMap
      Viewpoint viewpoint = new Viewpoint(envelope);

      // add the map view and control panel to stack pane
    } catch (Exception e) {


   * Stops and releases all resources used in application.
  public void stop() {

    // release resources when the application closes
    if (mapView != null) {

   * Opens and runs application.
   * @param args arguments passed to this application
  public static void main(String[] args) {


In this topic
  1. Code