Skip To Content ArcGIS for Developers Sign In Dashboard

Add graphics and text to graphics overlays

A graphic is a visible item on your map that can be seen as a point, line, polygon, or text. You can add graphics to your map view. These are contained in graphics overlays and are for showing temporary data that's not persisted once the application closes. For example, you may want to display a route between two locations or animate data items that change quickly.

This topic discusses adding graphics to your map in a way that generates a symbol instance for each graphic. If you're drawing a large number of graphics with the same symbology, then you should consider applying a renderer to the graphics overlay instead, which allows you to define the appearance of all the graphics in the overlay. Using renderers to add graphics is discussed in Symbols and renderers.

The image below shows an example of graphics drawn over a gray basemap. The graphics are showing:

  • Red markers showing location of buoys
  • Text symbols adding names to the islands of Craigleith and Bass Rock
  • A green cross hatched polygon showing a Gannet nesting ground on Bass Rock
  • A purple line showing the path of a boat trip.

Example of a map with multiple graphic overlays.

For more information on graphics and when to use them, see Features and graphics. For more information on graphics overlays, see Add graphics overlays to your app.

Create graphics in the graphics layer

This example demonstrates how to build graphics and add them into a graphics layer. Graphics include a geometry, and in this example they are symbolized by an associated symbol. You can see the complete code in the QML sample Add graphics with symbols.

  1. Define geometries for the buoys (points) and the anchor points for the text. Also create a geometry builder for the nesting area polygon. The geometry for the boat route is created later.

    // buoy location 1 (immutable once created)
        Point {
            x: -2.712642647560347
            y: 56.062812566811544
            spatialReference: SpatialReference.createWgs84()
            onComponentCompleted: {
        // buoy location 2 (immutable once created)
        Point {
            x: -2.6908416959572303
            y: 56.06444173689877
            spatialReference: SpatialReference.createWgs84()
            onComponentCompleted: {
        // text location 1: craigleith (immutable once created)
        Point {
            x: -2.640631
            y: 56.078083
            spatialReference: SpatialReference.createWgs84()
            onComponentCompleted: {
        // text location 2: bass rock (immutable once created)
        Point {
            x: -2.720324
            y: 56.073569
            spatialReference: SpatialReference.createWgs84()
            onComponentCompleted: {
        // polygon for nesting ground
        PolygonBuilder {
            id: nestingGroundPolygonBuilder
            spatialReference: SpatialReference.createWgs84()

  2. Define the symbols to use for the buoys, boat route, and nesting area.

    // marker symbol for buoys
        SimpleMarkerSymbol {
            id: buoyMarkerSymbol
            style: Enums.SimpleMarkerSymbolStyleCircle
            color: "red"
            size: 10
        // line symbol for boat route
        SimpleLineSymbol {
            id: boatRouteSymbol
            style: Enums.SimpleLineSymbolStyleDash
            color: Qt.rgba(0.5, 0.0, 0.5, 1)
            width: 4
            antiAlias: true
        // fill symbol for nesting ground
        SimpleFillSymbol {
            id: nestingGroundSymbol
            style: Enums.SimpleFillSymbolStyleDiagonalCross
            color: Qt.rgba(0.0, 0.31, 0.0, 1)
            // default property: ouline
            SimpleLineSymbol {
                style: Enums.SimpleLineSymbolStyleDash
                color: Qt.rgba(0.0, 0.0, 0.5, 1)
                width: 1
                antiAlias: true

  3. Create and add all the graphics to the graphics overlay. Create each graphic type and then add them to the overlay one at a time. Alternatively, you can create all of them and store in a list and add all of them by calling appendAll and pass in the list.

    Component.onCompleted: {  // The component is the containing Rectangle  
            // add buoy points
            buoyLocArray.forEach(function(buoyPoint) {
      , buoyMarkerSymbol));
            // add text symbols
            for (var i = 0; i < textLocArray.length; i++) {
                var textSymbol = ArcGISRuntimeEnvironment.createObject("TextSymbol");
                textSymbol.size = 10;
                textSymbol.color = Qt.rgba(0.1, 0.4, 0.9, 1);
                textSymbol.text = symbolTextArray[i];
                if (i === 1) {
                    textSymbol.horizontalAlignment = Enums.HorizontalAlignmentLeft;
                    textSymbol.verticalAlignment = Enums.VerticalAlignmentBottom;
                } else {
                    textSymbol.horizontalAlignment =  Enums.HorizontalAlignmentRight;
                    textSymbol.verticalAlignment =  Enums.VerticalAlignmentTop;
      [i], textSymbol));
            // add boat route
  , boatRouteSymbol));
            // add the nesting ground
  , nestingGroundSymbol));

  4. Notice that the code in the previous step uses helper functions to create the geometries. Using helper functions makes your code more flexible, easier to read, and easier to maintain.

    // create and return a graphic
        function createGraphic(geometry, symbol) {
            var graphic = ArcGISRuntimeEnvironment.createObject("Graphic");
            graphic.geometry = geometry;
            graphic.symbol = symbol;
            return graphic;

    Helper functions are especially useful when creating geometry objects with lots vertices. The helper function createNestingGround demonstrates one approach by creating and inserting points one-by-one into the polygon builder.

    // create the nesting ground polygon
        function createNestingGround() {
            // create the polygon using the builder class
            nestingGroundPolygonBuilder.addPointXY(-2.643077012566659, 56.077125346044475);
            nestingGroundPolygonBuilder.addPointXY(-2.6428195210159444, 56.07717324600376);
            nestingGroundPolygonBuilder.addPointXY(-2.6425405718360033, 56.07774804087097);
            nestingGroundPolygonBuilder.addPointXY(-2.6427122328698127, 56.077927662508635);
            nestingGroundPolygonBuilder.addPointXY(-2.642454741319098, 56.07829887790651);
            nestingGroundPolygonBuilder.addPointXY(-2.641853927700763, 56.078526395253725);
            nestingGroundPolygonBuilder.addPointXY(-2.6409741649024867, 56.078801809192434);
            nestingGroundPolygonBuilder.addPointXY(-2.6399871139580795, 56.07881378366685);
            nestingGroundPolygonBuilder.addPointXY(-2.6394077579689705, 56.07908919555142);
            nestingGroundPolygonBuilder.addPointXY(-2.638764029092183, 56.07917301616904);
            nestingGroundPolygonBuilder.addPointXY(-2.638485079912242, 56.07896945149566);
            nestingGroundPolygonBuilder.addPointXY(-2.638570910429147, 56.078203080726844);
            nestingGroundPolygonBuilder.addPointXY(-2.63878548672141, 56.077568418396);
            nestingGroundPolygonBuilder.addPointXY(-2.6391931816767085, 56.077197195961084);
            nestingGroundPolygonBuilder.addPointXY(-2.6399441986996273, 56.07675411934114);
            nestingGroundPolygonBuilder.addPointXY(-2.6406523004640934, 56.076730169108444);
            nestingGroundPolygonBuilder.addPointXY(-2.6406737580933193, 56.07632301287509);
            nestingGroundPolygonBuilder.addPointXY(-2.6401802326211157, 56.075999679860494);
            nestingGroundPolygonBuilder.addPointXY(-2.6402446055087943, 56.075844000034046);
            nestingGroundPolygonBuilder.addPointXY(-2.640416266542604, 56.07578412301025);
            nestingGroundPolygonBuilder.addPointXY(-2.6408883343855822, 56.075808073830935);
            nestingGroundPolygonBuilder.addPointXY(-2.6417680971838577, 56.076239186057734);
            nestingGroundPolygonBuilder.addPointXY(-2.642197249768383, 56.076251161328514);
            nestingGroundPolygonBuilder.addPointXY(-2.6428409786451708, 56.07661041772168);
            nestingGroundPolygonBuilder.addPointXY(-2.643077012566659, 56.077125346044475);
            return nestingGroundPolygonBuilder.geometry;

    The helper function createBoatRoute creates the geometry from its JSON representation.

    // create the boat route
        function createBoatRoute() {
            // create polyline using json
            return ArcGISRuntimeEnvironment.createObject("Polyline", {"json": boatRouteJson});
        property var boatRouteJson : {"paths":[[[-2.7184791227926772,56.06147084563517],

Select graphics

Selecting a graphic is a way of bringing it to the attention of a user by drawing a halo around it. Change the selection state of a graphic by using the selected property on the Graphic type.

Example of a graphic with a selection halo.

Update graphics

It's possible to update the geometry or attributes of a graphic by using the graphics collection of the graphics overlay. You can access and modify the list of graphics in a graphics overlay through its graphics property.

Remove graphics

To remove graphics you work with the graphics collection and call the remove method.