View on GitHub Sample viewer app

Change a graphic’s fill color, outline color, and fill style properties.

Image of simple fill symbol

Use case

Customize the appearance of a graphic with a color and style scheme suitable for the data. For example, a polygon with a brown ‘forward-diagonal’ fill style could represent an area of artificial ground mapped on a geological map.

How to use the sample

Use the drop down menus in the control panel to change the fill color, outline color and fill style of the polygon.

How it works

  1. Create a Polygon using a PointCollection to define its boundaries.
  2. Create a SimpleLineSymbol(SimpleLineSymbol.Style, color, width).
  3. Create a SimpleFillSymbol(SimpleFillSymbol.Style, color, outline).
  4. Set the color, outline and style of the simple fill symbol object with:
    • setColor();
    • setOutline(simpleLineSymbol);
    • setStyle();
  5. Create a new Graphic object, passing in the polygon and simple fill symbol as parameters, and add the graphic to the graphics overlay with graphicsOverlay.getGraphics().add(new Graphic(polygon, fillSymbol)).

Relevant API

  • Graphic
  • GraphicsOverlay
  • PointCollection
  • Polygon
  • SimpleFillSymbol
  • SimpleLineSymbol

Tags

fill, line, graphic, symbol

Sample Code

module-info.java module-info.java SimpleFillSymbolSample.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.simple_fill_symbol {
// 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.simple_fill_symbol;
}