- All Implemented Interfaces:
GeoElement
GeoElement
that has a shape (geometry), symbol, and attributes and can be displayed in a map view or
scene view.
Graphics are used to represent temporary data that exists for the lifetime of the application. For example, you can:
- Show updated locations for objects in the map view, such as moving vehicles.
- Display results from an analysis, geocoding, or routing operation.
- Allow the user to draw temporary sketches on top of the map.
- Store user input, such as a set of route stops to visit.
- Show ad hoc text labels to describe things on the map.
To display a graphic, add it to a GraphicsOverlay.getGraphics()
collection and add the graphics overlay
to your map view or scene view.
Each graphic has a geometry describing its location and shape. To maximize performance, the geometry should
have the same SpatialReference
as the map view or scene view to which it is added. If the geometry has a
different SpatialReference
, it will be reprojected on-the-fly. This can be computationally expensive when
displaying a large number of graphics.
A graphic can have an associated Symbol
that defines the graphic's appearance. Alternatively, the
GraphicsOverlay
can be assigned a Renderer
that determines the appearance of all graphics in the
overlay. If a graphic has an associated symbol, the symbol will override the overlay's renderer for the
graphic's display. The symbol used depends on the geometry type associated with the graphic. A MarkerSymbol
is used for Point
and Multipoint
geometries, a SimpleLineSymbol
for Polyline
geometries, and a
SimpleFillSymbol
for Polygon
or Envelope
geometries.
You can select or deselect graphics (isSelected()
), change the visibility of a graphic (isVisible()
),
and manage the order in which they are displayed (getZIndex()
).
Each graphic can have a collection of attributes (as key-value pairs) to provide more information.
- Since:
- 100.0.0
- See Also:
-
Constructor Summary
ConstructorDescriptionGraphic()
Creates a new graphic with a null geometry and symbol.Graphic
(double latitude, double longitude) Creates a new graphic with a point defined in the WGS 84 SpatialReference.Creates a new graphic with the given geometry.Creates a new graphic with the given geometry and symbol.Creates a new graphic with the given geometry and attributes.Creates new graphic with the given geometry, attributes, and symbol.Creates a graphic with the given attributes. -
Method Summary
Modifier and TypeMethodDescriptionGets the attributes of the GeoElement as a collection of name/value pairs.Gets the geometry which defines the shape and location of the GeoElement.Gets the graphics overlay that contains this graphic.Gets the symbol that defines the graphic's appearance when displayed in a map view or scene view.int
Gets the Z-index that defines the draw order of a graphic.boolean
Checks if the graphic is selected.boolean
Checks if the graphic is visible.void
setGeometry
(Geometry geometry) Sets the geometry defines the shape and location of the GeoElement.void
setSelected
(boolean selected) Controls if the graphic is selected or notvoid
Sets the symbol that defines the graphic's appearance when displayed in a map view or scene view.void
setVisible
(boolean visible) Controls the visibility of the graphic.void
setZIndex
(int index) Sets the Z-index that defines the draw order of a graphic.
-
Constructor Details
-
Graphic
public Graphic()Creates a new graphic with a null geometry and symbol.- Since:
- 100.0.0
-
Graphic
Creates a graphic with the given attributes.- Parameters:
attributes
- the attributes of the graphic. Can be null.- Since:
- 200.2.0
-
Graphic
Creates a new graphic with the given geometry.- Parameters:
geometry
- the geometry- Throws:
IllegalArgumentException
- if the geometry is null- Since:
- 100.0.0
-
Graphic
public Graphic(double latitude, double longitude) Creates a new graphic with a point defined in the WGS 84 SpatialReference.- Parameters:
latitude
- the latitudelongitude
- the longitude- Since:
- 100.0.0
-
Graphic
Creates a new graphic with the given geometry and symbol.- Parameters:
geometry
- the geometrysymbol
- the symbol- Throws:
IllegalArgumentException
- if the geometry or symbol is null- Since:
- 100.0.0
-
Graphic
Creates a new graphic with the given geometry and attributes.- Parameters:
geometry
- the geometryattributes
- the attributes of the graphic. Note that the values are copied. To make changes use getAttributes.- Throws:
IllegalArgumentException
- if geometry or attributes is null- Since:
- 100.0.0
-
Graphic
Creates new graphic with the given geometry, attributes, and symbol.- Parameters:
geometry
- the geometryattributes
- the attributes of the graphic. Note that the values are copied. To make changes use getAttributes.symbol
- the symbol- Throws:
IllegalArgumentException
- if geometry, attributes, or symbol is null- Since:
- 100.0.0
-
-
Method Details
-
getAttributes
Description copied from interface:GeoElement
Gets the attributes of the GeoElement as a collection of name/value pairs.Attribute values are returned as Object instances, but the underlying value type is based on the
Field.Type
.- Specified by:
getAttributes
in interfaceGeoElement
- Returns:
- the attributes of the GeoElement as a collection of name/value pairs
-
getGeometry
Description copied from interface:GeoElement
Gets the geometry which defines the shape and location of the GeoElement.- Specified by:
getGeometry
in interfaceGeoElement
- Returns:
- the geometry defines the shape and location of the GeoElement, or null if none
-
setGeometry
Description copied from interface:GeoElement
Sets the geometry defines the shape and location of the GeoElement.- Specified by:
setGeometry
in interfaceGeoElement
- Parameters:
geometry
- the geometry defines the shape and location of the GeoElement
-
getSymbol
Gets the symbol that defines the graphic's appearance when displayed in a map view or scene view.For graphics to appear in a map view or scene view, they must have a
Symbol
or be added to a graphics overlay that has a renderer assigned. ASymbol
defines the properties used to display the graphic, such as color, outline, size, and style. There are many different types of symbols, such asSimpleMarkerSymbol
,SimpleLineSymbol
, andSimpleFillSymbol
. The symbol type must match theGeometryType
of the graphic. For example, aFillSymbol
is used with graphics that are based on polygon geometry. The rendering of a graphic's symbol takes precedence over theRenderer
that may be set on theGraphicsOverlay
.- Returns:
- the symbol
- Since:
- 100.0.0
-
setSymbol
Sets the symbol that defines the graphic's appearance when displayed in a map view or scene view.For graphics to appear in a map view or scene view, they must have a
Symbol
or be added to a graphics overlay that has a renderer assigned. ASymbol
defines the properties used to display the graphic, such as color, outline, size, and style. There are many different types of symbols, such asSimpleMarkerSymbol
,SimpleLineSymbol
, andSimpleFillSymbol
. The symbol type must match theGeometryType
of the graphic. For example, aFillSymbol
is used with graphics that are based on polygon geometry. The rendering of a graphic's symbol takes precedence over theRenderer
that may be set on theGraphicsOverlay
.- Parameters:
symbol
- the new symbol- Since:
- 100.0.0
-
isVisible
public boolean isVisible()Checks if the graphic is visible.- Returns:
- true if the graphic is visible; false otherwise.
- Since:
- 100.0.0
-
setVisible
public void setVisible(boolean visible) Controls the visibility of the graphic.- Parameters:
visible
- true, to make visible- Since:
- 100.0.0
-
isSelected
public boolean isSelected()Checks if the graphic is selected.- Returns:
- true, if is selected
- Since:
- 100.0.0
-
setSelected
public void setSelected(boolean selected) Controls if the graphic is selected or not- Parameters:
selected
- true, to select- Since:
- 100.0.0
-
getZIndex
public int getZIndex()Gets the Z-index that defines the draw order of a graphic. Graphics with higher Z-index values are drawn on top of lower Z-index graphics.A graphic's Z-index is mostly relevant for display in a two-dimensional map view. For dynamic 3D rendering (in a scene view), graphic display order is determined by the distance to the camera rather than by Z-index. The Z-index is considered, however, when using static rendering in a scene view (draping graphics on the surface, in other words).
If Z-index is not set, graphics will usually render in the order in which they were added to the graphics overlay, the first added is rendered first and subsequent ones 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 graphics. You can also place graphics of the same geometry type in their own graphics overlay and manage the order of the overlays in the
MapView
orSceneView
.- Returns:
- the z-index
- Since:
- 100.0.0
-
setZIndex
public void setZIndex(int index) Sets the Z-index that defines the draw order of a graphic. Graphics with higher Z-index values are drawn on top of lower Z-index graphics.A graphic's Z-index is mostly relevant for display in a two-dimensional map view. For dynamic 3D rendering (in a scene view), graphic display order is determined by the distance to the camera rather than by Z-index. The Z-index is considered, however, when using static rendering in a scene view (draping graphics on the surface, in other words).
If Z-index is not set, graphics will usually render in the order in which they were added to the graphics overlay, the first added is rendered first and subsequent ones 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 graphics. You can also place graphics of the same geometry type in their own graphics overlay and manage the order of the overlays in the
MapView
orSceneView
.- Parameters:
index
- the new z-index- Since:
- 100.0.0
-
getGraphicsOverlay
Gets the graphics overlay that contains this graphic. Will be null if the graphic is not in an overlay.- Returns:
- the graphics overlay
- Since:
- 100.0.0
-