You can use graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more to display objects on top of the data in your map view A map view is a user interface that displays map layers and graphics in 2D. It controls the area (extent) of the map that is visible and supports user interactions such as pan and zoom. Learn more while your app is running. A graphic is a type of geoelement A geoelement refers to any geographic element in a map or map view that can be identified by its location to return attribute information. Learn more that has a shape (geometry) and attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more . A graphic can have its own symbol A symbol defines the properties used to display a geometry or text. Learn more , or can be displayed using a renderer A renderer is a collection of rules and symbols used to display the data in a layer. Learn more . Graphics are added to a graphics overlay A graphics overlay is a client-side, temporary container of graphics to display on a map view or scene view. Learn more for display in the map view.

Graphics displayed on a map view.

Graphics and graphics overlays allow you to do things like:

  • Show updated locations for objects in the map view, such as moving vehicles.
  • Display results from an analysis Analysis is a systematic examination of a problem that provides new information. Learn more , geocoding Geocoding is the process of converting text for an address or place to a complete address with a location. Learn more , or routing A route is a polyline that defines the best path between two or more points in a street network. Learn more operation.
  • Allow the user to draw temporary sketches on top of the map.
  • Store user input, such as a set of route stops A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more to visit.
  • Show ad hoc text labels to describe things on the map.

How graphics work

A map view has a graphics overlay collection that may contain zero or more graphics overlays A graphics overlay is a client-side, temporary container of graphics to display on a map view or scene view. Learn more . Each graphics overlay manages a collection of graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more that display on top of all data inside the map view. The graphics you add to a graphics overlay can have a mix of geometry types and attribute Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more fields. Because they offer so much flexibility, graphics and graphics overlays are ideal for working with temporary geoelements A geoelement refers to any geographic element in a map or map view that can be identified by its location to return attribute information. Learn more that you need to display as your app runs.

Graphics in map views and scene views

The pattern for working with graphics is the same whether in a map view A map view is a user interface that displays map layers and graphics in 2D. It controls the area (extent) of the map that is visible and supports user interactions such as pan and zoom. Learn more or scene view A scene view is a user interface that displays scene layers and graphics in 3D. It uses a camera to control the visible area of the scene and supports user interactions such as pan, zoom, tilt, and rotate. Learn more . In either case, the geoview A geoview is a base class for a map view and a scene view in ArcGIS Maps SDKs for Native Apps. Learn more has a collection of graphics overlays A graphics overlay is a client-side, temporary container of graphics to display on a map view or scene view. Learn more that contain a collection of graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more . When working with a scene view, additional 3D properties and symbol types are available that are not applicable when working with a map view.

For more information about working with graphics in 3D, see Add graphics to a scene view.

Graphics overlays

A GraphicsOverlay is a container for temporary graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more that display in your geoview A geoview is a base class for a map view and a scene view in ArcGIS Maps SDKs for Native Apps. Learn more . Graphics you add to graphics overlays A graphics overlay is a client-side, temporary container of graphics to display on a map view or scene view. Learn more are created at run time and are not persisted when the application closes.

The following code shows how to create a new graphics overlay and add it to your map view.

// Create a graphics overlay.
graphicsOverlay = new GraphicsOverlay();
// Add graphics overlay to the geo view (MapView or SceneView).
geoView.getGraphicsOverlays().add(graphicsOverlay);

Unlike a feature layer A feature layer (client-side) is a data layer that can access and display features from a feature service that has the same type of geometry and attribute fields. Learn more , which always contains features A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. Learn more of a single geometry A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more type, a graphics overlay A graphics overlay is a client-side, temporary container of graphics to display on a map view or scene view. Learn more can contain graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more with a variety of geometry types (a mix of points, lines, and polygons, in other words). A feature layer has a consistent schema (the same set of attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more ), while graphics in a graphics overlay can each have a distinct set of attributes.

For more information and a description of when to use each, see the Features and graphics topic.

Graphics

Graphics are created at run time and only persist for as long as the app is running. You can create them to show geocode Geocoding is the process of converting text for an address or place to a complete address with a location. Learn more candidates, routes A route is a polyline that defines the best path between two or more points in a street network. Learn more , results from analysis Analysis is a systematic examination of a problem that provides new information. Learn more operations, and so on. They are also commonly used to show input from the user, such as a click or touch on the display.

A Graphic uses the following to represent an object on the map view:

  • Geometry: a point, line, or polygon that represents the object’s location and shape.
  • Attributes: a collection of one or more pairs of fields and values that describe the object.
  • Symbol: an object that controls the visual representation of the graphic’s geometry on the display.

Draw order (z-index)

A graphic’s z-index defines the draw order of that graphic within its graphics overlay. It is primarily intended for use when working with graphics in a 2D map view.

If the z-index is not set, the graphics will render in the order in which they were added to the graphics overlay A graphics overlay is a client-side, temporary container of graphics to display on a map view or scene view. Learn more , the first graphic added is rendered lowermost and subsequent graphics on top. In rare cases, the rendering algorithm may change the display order to provide more efficient rendering. If ordering is important, set the z-index explicitly on each graphic. You can also place graphics of the same geometry type in their own graphics overlay and manage the order of the graphics overlays in the map view.

Work with graphics

Because they are both geoelements A geoelement refers to any geographic element in a map or map view that can be identified by its location to return attribute information. Learn more , you can work with graphics in much the same way as you would with features A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. Learn more . Graphics can be symbolized using attribute values, identified using a tap or click from the user, and selected in the display. You can update graphics’ geometry to move them on the view and update their attributes to reflect their current state. Unlike features, graphics are not persisted when the app closes.

Add a graphics overlay and a graphic

The following example shows how to create a graphics overlay A graphics overlay is a client-side, temporary container of graphics to display on a map view or scene view. Learn more , add a single graphic, and add the overlay to a map view.

  1. Create a new GraphicsOverlay.

  2. Create a Geometry to define the graphic’s shape and geographic location.

  3. Create a symbol A symbol defines the properties used to display a geometry or text. Learn more to display the graphic.

  4. Create a new Graphic using the geometry and symbol.

    • Optionally, you can define a set of attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more for the graphic A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more .
  5. Add the graphic to the graphics overlay.

  6. Add the graphics overlay to the map view.

// Create a graphics overlay.
graphicsOverlay = new GraphicsOverlay();
// Create a map point for the Santa Monica pier.
Point pierPoint = new Point(-118.4978, 34.0086, SpatialReferences.getWgs84());
// Create a red circle simple marker symbol.
SimpleMarkerSymbol redCircleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10);
// Create a graphic from the point and symbol.
Graphic pierGraphic = new Graphic(pierPoint, redCircleSymbol);
// Add the graphic to the graphics overlay.
graphicsOverlay.getGraphics().add(pierGraphic);
// Add graphics overlay to the geo view (MapView or SceneView).
geoView.getGraphicsOverlays().add(graphicsOverlay);

Symbolize

A comprehensive API for creating and modifying symbols A symbol defines the properties used to display a geometry or text. Learn more for every type of geometry A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more is provided. Symbols define properties such as color, size, and style that define how the graphic is displayed. There are specialized symbols for representing objects with text or images and you can create advanced symbols that combine multiple symbol layers. See Styles and data visualization to learn about the available symbol types.

There are two ways to symbolize a graphic A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more .

  1. Apply a symbol directly to the graphic. Graphics expose a symbol property that you can use to define the symbol.
  2. Apply a renderer to the graphics overlay. A renderer A renderer is a collection of rules and symbols used to display the data in a layer. Learn more is a collection of one or more symbols that are applied to all graphics in the graphics overlay. A renderer allows you to do things like control symbology based on attribute Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more values.

If you define a renderer for a graphics overlay, you do not need to assign symbols to the individual graphics it contains. Assigning a symbol directly to a graphic overrides the symbology defined by the renderer of the graphics overlay.

Display text

To display text on the map view as a graphic, create a graphic with a point, line, or polygon to define the location for your text. You can then provide a TextSymbol that defines the font, color, size, and text to display.

// Create text symbol.
TextSymbol pierTextSymbol =
new TextSymbol(10, "Santa Monica Pier", Color.BLUE,
TextSymbol.HorizontalAlignment.LEFT,
TextSymbol.VerticalAlignment.BOTTOM);
// Create a text graphic from the previous pier point defined earlier and text symbol.
Graphic pierTextGraphic = new Graphic(pierPoint, pierTextSymbol);

Identify

A graphic can contain descriptive information in the form of attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more . Attributes are a collection of pairs of keys (field names) and values that are defined when you create a graphic. Your app can identify Identify is a query based on a point on a map or scene that is used to find feature, graphic, or raster cell data. Learn more a graphic in the view from a click or tap and return its attributes. You can then display these attributes in a suitable UI element, such as a callout A callout is a container view that can be added over the map and anchored to a coordinate with a leader. Learn more , pop-up A pop-up is a visual element used to display data for features or graphics in a map. Learn more , or dialog.

The following example shows how you can identify a graphics overlay in response to a tap on the map view.

// Identify a limited number of graphics in the specified graphics overlay, at the given screen point.
final ListenableFuture<IdentifyGraphicsOverlayResult> identifyFuture =
geoView.identifyGraphicsOverlayAsync(graphicsOverlay, screenPoint, 10, false, 10);
identifyFuture.addDoneListener(new Runnable() {
@Override
public void run() {
try {
// Get the list of graphics returned by identify.
List<Graphic> identifiedGraphics = identifyFuture.get().getGraphics();
// Iterate the graphics.
for (Graphic graphic : identifiedGraphics) {
// Use identified graphics as required, for example access attributes or
// geometry, select, build a table, and so on.
graphic.setSelected(true);
}
} catch (InterruptedException | ExecutionException ex) {
dealWithException(ex);
}
}
});

Select

Select graphics to highlight them on the display. You can select zero, one, or several graphics in a graphics overlay. Each graphic’s selection state is represented with an isSelected() property that is either true or false.

Use setSelected(true) to select a graphic in the view.

// Iterate the graphics.
for (Graphic graphic : identifiedGraphics) {
// Use identified graphics as required, for example access attributes or
// geometry, select, build a table, and so on.
graphic.setSelected(true);
}

Move graphics

To move a graphic, you only need to update its geometry. This is much more efficient than creating a new graphic and replacing the existing one. Updating a graphic’s geometry will cause it to immediately display at the new location. Use this technique to animate the display of moving geoelements A geoelement refers to any geographic element in a map or map view that can be identified by its location to return attribute information. Learn more .

The following example moves a selected graphic to the location specified by the user.

// Enable dragging of the identified graphic to move its location.
mapView.setOnMouseDragged(event -> {
if (identifiedGraphic.isSelected() && identifiedGraphic != null) {
// Create a point from the dragged location.
geoViewPoint = new Point2D(event.getX(), event.getY());
// Converts a JavaFX local coordinate to a location in map coordinates.
Point mapPoint = mapView.screenToLocation(geoViewPoint);
// Update the location of the graphic to the dragged location.
identifiedGraphic.setGeometry(mapPoint);
}
});