You can use graphics
Graphics and graphics overlays allow you to do things like:
- Show updated locations for objects in the scene view, such as moving vehicles.
- Display results from an analysis
Analysis is a systematic examination of a problem that provides new information. , geocodingGeocoding is the process of converting text for an address or place to a complete address with a location. , or routingA route is a polyline that defines the best path between two or more points in a street network. operation. - Allow the user to draw temporary sketches on top of the scene.
- 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. to visit. - Show ad hoc text labels to describe things on the scene.
How graphics work
A scene view has a graphics overlay collection that may contain zero or more graphics overlays
Graphics in map views and scene views
The pattern for working with graphics is the same whether in a map view
Additional API and symbols for 3D display are discussed in the Render features and graphics in 3D topic.
-
Layer scene properties: Properties of a layer or graphics overlay that are only evaluated for display in 3D. This includes surface placement, which controls how z-values (elevation or altitude, for example) are evaluated relative to the data in the scene view.
-
Renderer scene properties: Renderer properties that are only evaluated for display in 3D. Use these properties to extract two-dimensional geometries vertically (on the z-axis) or to define heading, pitch, and roll for geoelements.
-
3D-specific symbols: Create symbols used exclusively for 3D display, such as 3D shapes (for example sphere, cylinder, and cube) and 3D model symbols that provide a realistic display of 3D objects.
Graphics overlays
A GraphicsOverlay is a container for temporary graphics
The following code shows how to create a new graphics overlay and add it to your scene view.
// Create a graphics overlay.
final graphicsOverlay = GraphicsOverlay();
// Add graphics overlay to the scene view controller.
sceneViewController.graphicsOverlays.add(graphicsOverlay);
Unlike a feature layer
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
A Graphic uses the following to represent an object on the scene view:
- Geometry: a point, line, or polygon that represents the object's location and shape (curve geometries are not supported).
- 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. In the scene view, when the graphics overlay is displayed in dynamic rendering mode
If using static rendering mode in a scene view and the z-index is not set, the graphics will render in the order in which they were added to the graphics overlay
Work with graphics
Because they are both geoelements
Add a graphics overlay and a graphic
The following example shows how to create a graphics overlay
-
Create a new
GraphicsOverlay. -
Create a
Geometryto define the graphic's shape and geographic location. -
Create a symbol
A symbol defines the properties used to display a geometry or text. to display the graphic.- You can also do this by defining a
Rendererfor the graphics overlayA graphics overlay is a client-side, temporary container of graphics to display on a map view or scene view. . See for more information about symbolizing geoelementsA geoelement refers to any geographic element in a map or map view that can be identified by its location to return attribute information. .
- You can also do this by defining a
-
Create a new
Graphicusing 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. for the graphicA graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. .
- Optionally, you can define a set of attributes
-
Add the graphic to the graphics overlay.
-
Add the graphics overlay to the scene view.
// Create a map point for the Santa Monica pier.
final pierPoint = ArcGISPoint(
x: -118.4978,
y: 34.0086,
spatialReference: SpatialReference.wgs84,
);
// Create a red sphere simple marker scene symbol.
final redSphereSymbol = SimpleMarkerSceneSymbol(
style: SimpleMarkerSceneSymbolStyle.sphere,
color: Colors.red,
height: 500,
width: 500,
depth: 500,
anchorPosition: SceneSymbolAnchorPosition.center,
);
// Create a graphic from the point and symbol.
final pierTextGraphic = Graphic(geometry: pierPoint, symbol: redSphereSymbol);
// Add an attribute to the graphic where the key is 'type' and the value
// is 'pier'. Use this attribute in the code below for the Select section.
pierTextGraphic.attributes['type'] = 'pier';
// Add the new graphic to the graphics overlay.
graphicsOverlay.graphics.add(pierTextGraphic);
Symbolize
A comprehensive API for creating and modifying symbols
There are two ways to symbolize a graphic
- Apply a symbol directly to the graphic. Graphics expose a symbol property that you can use to define the symbol.
- 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. 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 attributeAttributes 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. 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.
§ This capability has not yet been implemented in ArcGIS Maps SDK for Flutter, but will be added in a future release. See this page for more details.Display text
To display text on the scene 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 a map point for the Santa Monica pier.
final pierPoint = ArcGISPoint(
x: -118.4978,
y: 34.0086,
z: 500,
spatialReference: SpatialReference.wgs84,
);
// Create the text symbol.
final pierTextSymbol = TextSymbol(
text: 'Santa Monica Pier',
color: Colors.red,
size: 20,
verticalAlignment: VerticalAlignment.bottom,
)
..angle = -45
..haloColor = Colors.white
..offsetX = -40
..offsetY = 15;
// Create a graphic from the point and symbol.
final pierTextGraphic =
Graphic(geometry: pierPoint, symbol: pierTextSymbol);
// Add an attribute to the graphic where the key is 'type' and the value
// is 'pier'. Use this attribute in the code below for the Select section.
pierTextGraphic.attributes['type'] = 'pier';
// Add new graphic to the graphics overlay.
graphicsOverlay.graphics.add(pierTextGraphic);
Identify
A graphic can contain descriptive information in the form of attributes
The following example shows how you can identify a graphics overlay in response to a tap on the scene view.
// Identify the graphics overlay at the tapped location.
// Offset is provided by the onTap callback on the ArcGISSceneView widget.
final identifyGraphicsOverlay =
await sceneViewController.identifyGraphicsOverlay(
graphicsOverlay,
screenPoint: offset,
tolerance: 12.0,
maximumResults: 1,
);
// Check that an identified graphic is tapped.
if (identifyGraphicsOverlay.graphics.isNotEmpty) {
// Retrieve the identified graphic.
final identifiedGraphic = identifyGraphicsOverlay.graphics.first;
if (mounted) {
showDialog(
context: context,
builder: (context) {
// Display an alert dialog when the graphic is tapped.
return AlertDialog(
alignment: Alignment.center,
content: Column(
children: [
const Text('Tapped on Graphic'),
Text(
'${identifiedGraphic.attributes['type']}',
),
],
),
); // AlertDialog
},
); // showDialog
}
}
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 property that is either true or false.
The following example finds all graphics in the graphics overlay that have a 'type' attribute of 'pier' and selects them on the display.
// Retrieve all the graphics from the graphics overlay.
final graphics = graphicsOverlay.graphics;
// Select all graphics with a 'type' attribute of 'pier'.
for (final graphic in graphics) {
if (graphic.attributes['type'] == 'pier') {
graphic.isSelected = true;
}
}
Move
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
See Follow a graphic in a scene view for more information about following a moving graphic with the camera
final currentPosition = boatGraphic.geometry as ArcGISPoint;
const deltaX = -0.01;
const deltaY = -0.01;
// Define new x and y coordinates by applying the deltas.
final newX = currentPosition.x + deltaX;
final newY = currentPosition.y + deltaY;
// Update the point with the new coordinates.
final updatePosition =
ArcGISPoint(x: newX, y: newY, spatialReference: SpatialReference.wgs84);
boatGraphic.geometry = updatePosition;