Style a feature layer

Learn how to apply renderers and label definitions to a feature layer based on attribute values.

style a feature layer

Applications can display feature layer data with different styles to enhance the visualization. The type of Renderer you choose depends on your application. A SimpleRenderer applies the same symbol to all features, a UniqueValueRenderer applies a different symbol to each unique attribute value, and a ClassBreaksRenderer applies a symbol to a range of numeric values. Renderers are responsible for accessing the data and applying the appropriate symbol to each feature when the layer draws. You can also use a LabelDefinition to show attribute information for features. Visit the Styles and data visualization documentation to learn more about styling layers.

You can also author, style and save web maps, web scenes, and layers as portal items and then add them to the map in your application. Visit the following tutorials to learn more about adding portal items.

In this tutorial, you will apply different renderers to enhance the visualization of three feature layers with data for the Santa Monica Mountains: Trailheads with a single symbol, Trails based on elevation change and bike use, and Parks and Open Spaces based on the type of park.

Prerequisites

The following are required for this tutorial:

  1. An ArcGIS account to access API keys. If you don't have an account, sign up for free.
  2. Your system meets the system requirements.
  3. The ArcGIS Runtime API for Qt is installed.

Steps

Open the project in Qt Creator

  1. To start this tutorial, complete the Display a map tutorial or download and unzip the solution.

  2. Open the display_a_map project in Qt Creator.

  3. If you downloaded the Display a map solution, set your API key.

    An API Key enables access to services, web maps, and web scenes hosted in ArcGIS Online.

    1. Go to your developer dashboard to get your API key. For these tutorials, use your default API key. It is scoped to include all of the services demonstrated in the tutorials.

    2. In the Projects window, in the Sources folder, open the main.cpp file.

    3. Modify the code to set the API key. Paste the API key, acquired from your dashboard, between the quotes. Then save and close the file.

      main.cpp
      Use dark colors for code blocks
      39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 40 41 42 43 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44
      Add line.Add line.Add line.Add line.Add line.
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      //   Copyright 2020 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
      //
      //   https://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.
      //
      
      #include "Display_a_map.h"
      
      #include "ArcGISRuntimeEnvironment.h"
      #include "MapQuickView.h"
      
      #include <QDir>
      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      //------------------------------------------------------------------------------
      
      using namespace Esri::ArcGISRuntime;
      
      int main(int argc, char *argv[])
      {
          QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          QGuiApplication app(argc, argv);
      
          // Use of Esri location services, including basemaps and geocoding, requires
          // either an ArcGIS identity or an API key. For more information see
          // https://links.esri.com/arcgis-runtime-security-auth.
      
          // 1. ArcGIS identity: An ArcGIS named user account that is a member of an
          // organization in ArcGIS Online or ArcGIS Enterprise.
      
          // 2. API key: A permanent key that gives your application access to Esri
          // location services. Create a new API key or access existing API keys from
          // your ArcGIS for Developers dashboard (https://links.esri.com/arcgis-api-keys).
      
          const QString apiKey = QString("");
      
          if (apiKey.isEmpty())
          {
              qWarning() << "Use of Esri location services, including basemaps, requires "
                            "you to authenticate with an ArcGIS identity or set the API Key property.";
          }
          else
          {
              ArcGISRuntimeEnvironment::setApiKey(apiKey);
          }
      
          // Production deployment of applications built with ArcGIS Runtime requires you to
          // license ArcGIS Runtime functionality. For more information see
          // https://links.esri.com/arcgis-runtime-license-and-deploy.
      
          // ArcGISRuntimeEnvironment::setLicense("Place license string in here");
      
          // Register the map view for QML
          qmlRegisterType<MapQuickView>("Esri.display_a_map", 1, 0, "MapView");
      
          // Register the Display_a_map (QQuickItem) for QML
          qmlRegisterType<Display_a_map>("Esri.display_a_map", 1, 0, "Display_a_map");
      
          // Initialize application view
          QQmlApplicationEngine engine;
      
          // Add the import Path
          engine.addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml"));
      
          // Set the source
          engine.load(QUrl("qrc:/qml/main.qml"));
      
          return app.exec();
      }
      
      //------------------------------------------------------------------------------

Add needed classes and declarations

  1. In the Projects window, open the Headers folder. Open the display_a_map.h file.

  2. Add the LabelDefinition and FeatureLayer classes to the namespace.

    Display_a_map.h
    Use dark colors for code blocks
    19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 20 21 22 23 24 25 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26
    Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    //   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
    //
    //   https://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.
    
    #ifndef DISPLAY_A_MAP_H
    #define DISPLAY_A_MAP_H
    
    namespace Esri
    {
    
    namespace ArcGISRuntime
    {
    class Map;
    class MapQuickView;
    
    class LabelDefinition;
    class FeatureLayer;
    
    }
    }
    
    #include <QObject>
    
    class Display_a_map : public QObject
    {
      Q_OBJECT
      Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged)
    public:
      explicit Display_a_map(QObject* parent = nullptr);
      ~Display_a_map() override;
    
    signals:
      void mapViewChanged();
    
    private:
      Esri::ArcGISRuntime::MapQuickView* mapView() const;
      void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
    
      void setupMap();
    
      void addOpenSpaceLayer();
      void addTrailsLayer();
      void addNoBikeTrailsLayer();
      void addBikeOnlyTrailsLayer();
      void addTrailheadsLayer();
      Esri::ArcGISRuntime::FeatureLayer* addFeatureLayer(const QUrl& url);
      Esri::ArcGISRuntime::LabelDefinition* makeLabelDefinition();
    
      Esri::ArcGISRuntime::Map* m_map = nullptr;
      Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr;
    };
    
    #endif // DISPLAY_A_MAP_H
  3. Add the declarations for methods you will create.

    Display_a_map.h
    Use dark colors for code blocks
    45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 46 47 48 49 50 51 52 53 54 55 56 57 58 58 58 58 58 58 58
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    //   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
    //
    //   https://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.
    
    #ifndef DISPLAY_A_MAP_H
    #define DISPLAY_A_MAP_H
    
    namespace Esri
    {
    
    namespace ArcGISRuntime
    {
    class Map;
    class MapQuickView;
    
    class LabelDefinition;
    class FeatureLayer;
    
    }
    }
    
    #include <QObject>
    
    class Display_a_map : public QObject
    {
      Q_OBJECT
      Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged)
    public:
      explicit Display_a_map(QObject* parent = nullptr);
      ~Display_a_map() override;
    
    signals:
      void mapViewChanged();
    
    private:
      Esri::ArcGISRuntime::MapQuickView* mapView() const;
      void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
    
      void setupMap();
    
      void addOpenSpaceLayer();
      void addTrailsLayer();
      void addNoBikeTrailsLayer();
      void addBikeOnlyTrailsLayer();
      void addTrailheadsLayer();
      Esri::ArcGISRuntime::FeatureLayer* addFeatureLayer(const QUrl& url);
      Esri::ArcGISRuntime::LabelDefinition* makeLabelDefinition();
    
      Esri::ArcGISRuntime::Map* m_map = nullptr;
      Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr;
    };
    
    #endif // DISPLAY_A_MAP_H
  4. Save and close the file.

Create a function to add a feature layer

A feature layer can be added from a feature service hosted in ArcGIS Online. Each feature layer contains features with a single geometry type (point, line, or polygon), and a set of attributes. Once added to the map, feature layers can be symbolized, styled, and labeled in a variety of ways.

Next, you will create a helper method to add a layer to the map's collection of operational layers. You will use this helper method throughout the tutorial as you add and symbolize various layers.

  1. Add a helper method named addFeatureLayer() that takes a feature service URL as an argument.

    Display_a_map.cpp
    Use dark colors for code blocks
    58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 34 33 34 35 36 37 38 39 39 39 39 39 39 39 39 39 39 40 41 42 43 44 45 46 47 48 49 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -78 -78 -78 -78 -78 -78 -78 -78 -78 -78 -78 -78 -78 -78 -78
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    //   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
    //
    //   https://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.
    
    #include "Display_a_map.h"
    #include "ArcGISRuntimeEnvironment.h"
    
    #include "Basemap.h"
    #include "Map.h"
    #include "MapQuickView.h"
    
    #include "FeatureLayer.h"
    #include "ServiceFeatureTable.h"
    
    #include <QUrl>
    #include "SimpleFillSymbol.h"
    #include "UniqueValueRenderer.h"
    
    #include "SimpleLineSymbol.h"
    #include <QList>
    #include "ClassBreaksRenderer.h"
    
    #include "SimpleRenderer.h"
    
    #include "LabelDefinition.h"
    #include "TextSymbol.h"
    #include "ArcadeLabelExpression.h"
    
    #include "PictureMarkerSymbol.h"
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_map::Display_a_map(QObject* parent /* = nullptr */):
        QObject(parent),
        m_map(new Map(BasemapStyle::ArcGISTopographic, this))
    {
    }
    
    Display_a_map::~Display_a_map()
    {
    }
    
    MapQuickView* Display_a_map::mapView() const
    {
        return m_mapView;
    }
    
    QUrl trailsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
    
    void Display_a_map::setupMap()
    {
        const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
        const Viewpoint viewpoint(center, 100000.0);
        m_mapView->setViewpoint(viewpoint);
    
        addOpenSpaceLayer();
    
        addTrailsLayer();
    
        addBikeOnlyTrailsLayer();
        addNoBikeTrailsLayer();
    
        addTrailheadsLayer();
    
    }
    
    // Create a new function that creates a feature layer and appends it to the operational layers and the m_map.
    FeatureLayer* Display_a_map::addFeatureLayer(const QUrl& url)
    {
        ServiceFeatureTable* serviceFeatureTable = new ServiceFeatureTable(url, this);
        FeatureLayer* featureLayer = new FeatureLayer(serviceFeatureTable, this);
        m_map->operationalLayers()->append(featureLayer);
        return featureLayer;
    }
    
    void Display_a_map::addOpenSpaceLayer()
    {
        // Create a parks and open spaces feature layer.
        QUrl parksAndOpenSpacesQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(parksAndOpenSpacesQUrl);
    
        // Create fill symbols.
        SimpleFillSymbol* purpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("purple"), this);
        SimpleFillSymbol* greenFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("green"), this);
        SimpleFillSymbol* blueFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("blue"), this);
        SimpleFillSymbol* redFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("red"), this);
    
        // Create a unique value for natural areas, regional open spaces, local parks & regional recreation parks.
        UniqueValue* naturalAreas = new UniqueValue("Natural Areas", "Natural Areas", {"Natural Areas"}, purpleFillSymbol, this);
        UniqueValue* regionalOpenSpace = new UniqueValue("Regional Open Space", "Regional Open Space", {"Regional Open Space"}, greenFillSymbol, this);
        UniqueValue* localPark = new UniqueValue("Local Park", "Local Park", {"Local Park"}, blueFillSymbol, this);
        UniqueValue* regionalRecreationPark = new UniqueValue("Regional Recreation Park", "Regional Recreation Park",
                                                              {"Regional Recreation Park"}, redFillSymbol, this);
    
        // Create and assign a unique value renderer to the feature layer.
        UniqueValueRenderer* openSpacesUniqueValueRenderer = new UniqueValueRenderer("Open Spaces", nullptr, {"TYPE"},
                                                                                     {naturalAreas, regionalOpenSpace, localPark, regionalRecreationPark }, this);
        featureLayer->setRenderer(openSpacesUniqueValueRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.25f);
    }
    
    void Display_a_map::addTrailsLayer()
    {
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
        // Create five line symbols to display class breaks.
        SimpleLineSymbol* firstClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 3, this);
        SimpleLineSymbol* secondClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 4, this);
        SimpleLineSymbol* thirdClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 5, this);
        SimpleLineSymbol* fourthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 6, this);
        SimpleLineSymbol* fifthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 7, this);
    
        // Create five class breaks.
        ClassBreak* firstClassBreak = new ClassBreak("Under 500", "0 - 500", 0.0, 500.0, firstClassSymbol, this);
        ClassBreak* secondClassBreak = new ClassBreak("501 to 1000", "501 - 1000", 501.0, 1000.0, secondClassSymbol, this);
        ClassBreak* thirdClassBreak = new ClassBreak("1001 to 1500", "1001 - 1500", 1001.0, 1500.0, thirdClassSymbol, this);
        ClassBreak* fourthClassBreak = new ClassBreak("1501 to 2000", "1501 - 2000", 1501.0, 2000.0, fourthClassSymbol, this);
        ClassBreak* fifthClassBreak = new ClassBreak("2001 to 2300", "2001 to 2300", 2001.0, 2300.0, fifthClassSymbol, this);
        QList<ClassBreak*> elevationBreaks = {firstClassBreak, secondClassBreak, thirdClassBreak, fourthClassBreak, fifthClassBreak};
    
        // Create and assign a class breaks renderer to the feature layer.
        ClassBreaksRenderer* elevationClassBreaksRenderer = new ClassBreaksRenderer("ELEV_GAIN", elevationBreaks, this);
        featureLayer->setRenderer(elevationClassBreaksRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.75);
    }
    
    void Display_a_map::addBikeOnlyTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'Yes'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* bikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("blue"), 2, this);
        SimpleRenderer* bikeTrailRenderer = new SimpleRenderer(bikeTrailSymbol, this);
        featureLayer->setRenderer(bikeTrailRenderer);
    }
    
    void Display_a_map::addNoBikeTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that don't permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'No'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* noBikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("red"), 2, this);
        SimpleRenderer* noBikeTrailRenderer = new SimpleRenderer(noBikeTrailSymbol, this);
        featureLayer->setRenderer(noBikeTrailRenderer);
    }
    
    LabelDefinition* Display_a_map::makeLabelDefinition()
    {
        // Create a new text symbol.
        TextSymbol* labelTextSymbol = new TextSymbol(this);
        labelTextSymbol->setColor(QColor("white"));
        labelTextSymbol->setSize(12.0);
        labelTextSymbol->setHaloColor (QColor("black"));
        labelTextSymbol->setHaloWidth(2.0);
        labelTextSymbol->setFontFamily("Arial");
        labelTextSymbol->setFontStyle(FontStyle::Italic);
        labelTextSymbol->setFontWeight(FontWeight::Normal);
    
        // Create a new Arcade label expression based on the field name: 'TRL_NAME'.
        ArcadeLabelExpression* labelExpression = new ArcadeLabelExpression("$feature.TRL_NAME", this);
    
        // Create and return the label definition.
        return new LabelDefinition(labelExpression, labelTextSymbol, this);
    }
    
    void Display_a_map::addTrailheadsLayer()
    {
        // Create a ServiceFeatureTable from the URL, create a FeatureLayer, and add that to the map's operational layers.
        QUrl trailheadsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(trailheadsQUrl);
    
        // Create a new picture marker symbol that uses the trailhead image.
        QUrl trailheadImageQUrl("https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png");
        PictureMarkerSymbol* pictureMarkerSymbol = new PictureMarkerSymbol(trailheadImageQUrl, this);
        pictureMarkerSymbol->setHeight(18.0);
        pictureMarkerSymbol->setWidth(18.0);
    
        // Create a new simple renderer based on the picture marker symbol.
        SimpleRenderer* simpleRenderer = new SimpleRenderer(pictureMarkerSymbol, this);
    
        // Set the feature layer's renderer and enable labels.
        featureLayer->setRenderer(simpleRenderer);
        featureLayer->setLabelsEnabled(true);
    
        // Create the label definition.
        LabelDefinition* trailHeadsDefinition = makeLabelDefinition();
    
        // Add the label definition to the layer's label definition collection.
        featureLayer->labelDefinitions()->append(trailHeadsDefinition);
    }
    
    // Set the view (created in QML)
    void Display_a_map::setMapView(MapQuickView* mapView)
    {
        if (!mapView || mapView == m_mapView)
        {
            return;
        }
    
        m_mapView = mapView;
        m_mapView->setMap(m_map);
    
        setupMap();
    
        emit mapViewChanged();
    }
    
  2. Add include statements to access the classes used in addFeatureLayer().

    Display_a_map.cpp
    Use dark colors for code blocks
    16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 17 18 19 20 21 22 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 21 20 20 20 20 20 20 20 19 18 17 16 15 14 13 12 11 11 11 11 11 11 11 11 11 11 11 11 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -116 -116 -116 -116 -116 -116 -116 -116 -116 -116 -116 -116 -116 -116 -116
    Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    //   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
    //
    //   https://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.
    
    #include "Display_a_map.h"
    #include "ArcGISRuntimeEnvironment.h"
    
    #include "Basemap.h"
    #include "Map.h"
    #include "MapQuickView.h"
    
    #include "FeatureLayer.h"
    #include "ServiceFeatureTable.h"
    
    #include <QUrl>
    #include "SimpleFillSymbol.h"
    #include "UniqueValueRenderer.h"
    
    #include "SimpleLineSymbol.h"
    #include <QList>
    #include "ClassBreaksRenderer.h"
    
    #include "SimpleRenderer.h"
    
    #include "LabelDefinition.h"
    #include "TextSymbol.h"
    #include "ArcadeLabelExpression.h"
    
    #include "PictureMarkerSymbol.h"
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_map::Display_a_map(QObject* parent /* = nullptr */):
        QObject(parent),
        m_map(new Map(BasemapStyle::ArcGISTopographic, this))
    {
    }
    
    Display_a_map::~Display_a_map()
    {
    }
    
    MapQuickView* Display_a_map::mapView() const
    {
        return m_mapView;
    }
    
    QUrl trailsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
    
    void Display_a_map::setupMap()
    {
        const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
        const Viewpoint viewpoint(center, 100000.0);
        m_mapView->setViewpoint(viewpoint);
    
        addOpenSpaceLayer();
    
        addTrailsLayer();
    
        addBikeOnlyTrailsLayer();
        addNoBikeTrailsLayer();
    
        addTrailheadsLayer();
    
    }
    
    // Create a new function that creates a feature layer and appends it to the operational layers and the m_map.
    FeatureLayer* Display_a_map::addFeatureLayer(const QUrl& url)
    {
        ServiceFeatureTable* serviceFeatureTable = new ServiceFeatureTable(url, this);
        FeatureLayer* featureLayer = new FeatureLayer(serviceFeatureTable, this);
        m_map->operationalLayers()->append(featureLayer);
        return featureLayer;
    }
    
    void Display_a_map::addOpenSpaceLayer()
    {
        // Create a parks and open spaces feature layer.
        QUrl parksAndOpenSpacesQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(parksAndOpenSpacesQUrl);
    
        // Create fill symbols.
        SimpleFillSymbol* purpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("purple"), this);
        SimpleFillSymbol* greenFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("green"), this);
        SimpleFillSymbol* blueFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("blue"), this);
        SimpleFillSymbol* redFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("red"), this);
    
        // Create a unique value for natural areas, regional open spaces, local parks & regional recreation parks.
        UniqueValue* naturalAreas = new UniqueValue("Natural Areas", "Natural Areas", {"Natural Areas"}, purpleFillSymbol, this);
        UniqueValue* regionalOpenSpace = new UniqueValue("Regional Open Space", "Regional Open Space", {"Regional Open Space"}, greenFillSymbol, this);
        UniqueValue* localPark = new UniqueValue("Local Park", "Local Park", {"Local Park"}, blueFillSymbol, this);
        UniqueValue* regionalRecreationPark = new UniqueValue("Regional Recreation Park", "Regional Recreation Park",
                                                              {"Regional Recreation Park"}, redFillSymbol, this);
    
        // Create and assign a unique value renderer to the feature layer.
        UniqueValueRenderer* openSpacesUniqueValueRenderer = new UniqueValueRenderer("Open Spaces", nullptr, {"TYPE"},
                                                                                     {naturalAreas, regionalOpenSpace, localPark, regionalRecreationPark }, this);
        featureLayer->setRenderer(openSpacesUniqueValueRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.25f);
    }
    
    void Display_a_map::addTrailsLayer()
    {
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
        // Create five line symbols to display class breaks.
        SimpleLineSymbol* firstClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 3, this);
        SimpleLineSymbol* secondClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 4, this);
        SimpleLineSymbol* thirdClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 5, this);
        SimpleLineSymbol* fourthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 6, this);
        SimpleLineSymbol* fifthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 7, this);
    
        // Create five class breaks.
        ClassBreak* firstClassBreak = new ClassBreak("Under 500", "0 - 500", 0.0, 500.0, firstClassSymbol, this);
        ClassBreak* secondClassBreak = new ClassBreak("501 to 1000", "501 - 1000", 501.0, 1000.0, secondClassSymbol, this);
        ClassBreak* thirdClassBreak = new ClassBreak("1001 to 1500", "1001 - 1500", 1001.0, 1500.0, thirdClassSymbol, this);
        ClassBreak* fourthClassBreak = new ClassBreak("1501 to 2000", "1501 - 2000", 1501.0, 2000.0, fourthClassSymbol, this);
        ClassBreak* fifthClassBreak = new ClassBreak("2001 to 2300", "2001 to 2300", 2001.0, 2300.0, fifthClassSymbol, this);
        QList<ClassBreak*> elevationBreaks = {firstClassBreak, secondClassBreak, thirdClassBreak, fourthClassBreak, fifthClassBreak};
    
        // Create and assign a class breaks renderer to the feature layer.
        ClassBreaksRenderer* elevationClassBreaksRenderer = new ClassBreaksRenderer("ELEV_GAIN", elevationBreaks, this);
        featureLayer->setRenderer(elevationClassBreaksRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.75);
    }
    
    void Display_a_map::addBikeOnlyTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'Yes'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* bikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("blue"), 2, this);
        SimpleRenderer* bikeTrailRenderer = new SimpleRenderer(bikeTrailSymbol, this);
        featureLayer->setRenderer(bikeTrailRenderer);
    }
    
    void Display_a_map::addNoBikeTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that don't permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'No'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* noBikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("red"), 2, this);
        SimpleRenderer* noBikeTrailRenderer = new SimpleRenderer(noBikeTrailSymbol, this);
        featureLayer->setRenderer(noBikeTrailRenderer);
    }
    
    LabelDefinition* Display_a_map::makeLabelDefinition()
    {
        // Create a new text symbol.
        TextSymbol* labelTextSymbol = new TextSymbol(this);
        labelTextSymbol->setColor(QColor("white"));
        labelTextSymbol->setSize(12.0);
        labelTextSymbol->setHaloColor (QColor("black"));
        labelTextSymbol->setHaloWidth(2.0);
        labelTextSymbol->setFontFamily("Arial");
        labelTextSymbol->setFontStyle(FontStyle::Italic);
        labelTextSymbol->setFontWeight(FontWeight::Normal);
    
        // Create a new Arcade label expression based on the field name: 'TRL_NAME'.
        ArcadeLabelExpression* labelExpression = new ArcadeLabelExpression("$feature.TRL_NAME", this);
    
        // Create and return the label definition.
        return new LabelDefinition(labelExpression, labelTextSymbol, this);
    }
    
    void Display_a_map::addTrailheadsLayer()
    {
        // Create a ServiceFeatureTable from the URL, create a FeatureLayer, and add that to the map's operational layers.
        QUrl trailheadsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(trailheadsQUrl);
    
        // Create a new picture marker symbol that uses the trailhead image.
        QUrl trailheadImageQUrl("https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png");
        PictureMarkerSymbol* pictureMarkerSymbol = new PictureMarkerSymbol(trailheadImageQUrl, this);
        pictureMarkerSymbol->setHeight(18.0);
        pictureMarkerSymbol->setWidth(18.0);
    
        // Create a new simple renderer based on the picture marker symbol.
        SimpleRenderer* simpleRenderer = new SimpleRenderer(pictureMarkerSymbol, this);
    
        // Set the feature layer's renderer and enable labels.
        featureLayer->setRenderer(simpleRenderer);
        featureLayer->setLabelsEnabled(true);
    
        // Create the label definition.
        LabelDefinition* trailHeadsDefinition = makeLabelDefinition();
    
        // Add the label definition to the layer's label definition collection.
        featureLayer->labelDefinitions()->append(trailHeadsDefinition);
    }
    
    // Set the view (created in QML)
    void Display_a_map::setMapView(MapQuickView* mapView)
    {
        if (!mapView || mapView == m_mapView)
        {
            return;
        }
    
        m_mapView = mapView;
        m_mapView->setMap(m_map);
    
        setupMap();
    
        emit mapViewChanged();
    }
    

Add a layer with a unique value renderer

Create a method that creates a variable to store a feature service URL. Create a Parks and Open Spaces feature layer using that variable and then apply a different symbol for each type of park area displayed.

  1. Add a new method named addOpenSpaceLayer(), after the newly added addFeatureLayer() method.

    Display_a_map.cpp
    Use dark colors for code blocks
    84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 67 66 66 66 66 66 66 66 65 64 63 62 61 60 59 58 57 57 57 57 57 57 57 57 57 57 57 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    //   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
    //
    //   https://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.
    
    #include "Display_a_map.h"
    #include "ArcGISRuntimeEnvironment.h"
    
    #include "Basemap.h"
    #include "Map.h"
    #include "MapQuickView.h"
    
    #include "FeatureLayer.h"
    #include "ServiceFeatureTable.h"
    
    #include <QUrl>
    #include "SimpleFillSymbol.h"
    #include "UniqueValueRenderer.h"
    
    #include "SimpleLineSymbol.h"
    #include <QList>
    #include "ClassBreaksRenderer.h"
    
    #include "SimpleRenderer.h"
    
    #include "LabelDefinition.h"
    #include "TextSymbol.h"
    #include "ArcadeLabelExpression.h"
    
    #include "PictureMarkerSymbol.h"
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_map::Display_a_map(QObject* parent /* = nullptr */):
        QObject(parent),
        m_map(new Map(BasemapStyle::ArcGISTopographic, this))
    {
    }
    
    Display_a_map::~Display_a_map()
    {
    }
    
    MapQuickView* Display_a_map::mapView() const
    {
        return m_mapView;
    }
    
    QUrl trailsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
    
    void Display_a_map::setupMap()
    {
        const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
        const Viewpoint viewpoint(center, 100000.0);
        m_mapView->setViewpoint(viewpoint);
    
        addOpenSpaceLayer();
    
        addTrailsLayer();
    
        addBikeOnlyTrailsLayer();
        addNoBikeTrailsLayer();
    
        addTrailheadsLayer();
    
    }
    
    // Create a new function that creates a feature layer and appends it to the operational layers and the m_map.
    FeatureLayer* Display_a_map::addFeatureLayer(const QUrl& url)
    {
        ServiceFeatureTable* serviceFeatureTable = new ServiceFeatureTable(url, this);
        FeatureLayer* featureLayer = new FeatureLayer(serviceFeatureTable, this);
        m_map->operationalLayers()->append(featureLayer);
        return featureLayer;
    }
    
    void Display_a_map::addOpenSpaceLayer()
    {
        // Create a parks and open spaces feature layer.
        QUrl parksAndOpenSpacesQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(parksAndOpenSpacesQUrl);
    
        // Create fill symbols.
        SimpleFillSymbol* purpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("purple"), this);
        SimpleFillSymbol* greenFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("green"), this);
        SimpleFillSymbol* blueFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("blue"), this);
        SimpleFillSymbol* redFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("red"), this);
    
        // Create a unique value for natural areas, regional open spaces, local parks & regional recreation parks.
        UniqueValue* naturalAreas = new UniqueValue("Natural Areas", "Natural Areas", {"Natural Areas"}, purpleFillSymbol, this);
        UniqueValue* regionalOpenSpace = new UniqueValue("Regional Open Space", "Regional Open Space", {"Regional Open Space"}, greenFillSymbol, this);
        UniqueValue* localPark = new UniqueValue("Local Park", "Local Park", {"Local Park"}, blueFillSymbol, this);
        UniqueValue* regionalRecreationPark = new UniqueValue("Regional Recreation Park", "Regional Recreation Park",
                                                              {"Regional Recreation Park"}, redFillSymbol, this);
    
        // Create and assign a unique value renderer to the feature layer.
        UniqueValueRenderer* openSpacesUniqueValueRenderer = new UniqueValueRenderer("Open Spaces", nullptr, {"TYPE"},
                                                                                     {naturalAreas, regionalOpenSpace, localPark, regionalRecreationPark }, this);
        featureLayer->setRenderer(openSpacesUniqueValueRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.25f);
    }
    
    void Display_a_map::addTrailsLayer()
    {
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
        // Create five line symbols to display class breaks.
        SimpleLineSymbol* firstClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 3, this);
        SimpleLineSymbol* secondClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 4, this);
        SimpleLineSymbol* thirdClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 5, this);
        SimpleLineSymbol* fourthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 6, this);
        SimpleLineSymbol* fifthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 7, this);
    
        // Create five class breaks.
        ClassBreak* firstClassBreak = new ClassBreak("Under 500", "0 - 500", 0.0, 500.0, firstClassSymbol, this);
        ClassBreak* secondClassBreak = new ClassBreak("501 to 1000", "501 - 1000", 501.0, 1000.0, secondClassSymbol, this);
        ClassBreak* thirdClassBreak = new ClassBreak("1001 to 1500", "1001 - 1500", 1001.0, 1500.0, thirdClassSymbol, this);
        ClassBreak* fourthClassBreak = new ClassBreak("1501 to 2000", "1501 - 2000", 1501.0, 2000.0, fourthClassSymbol, this);
        ClassBreak* fifthClassBreak = new ClassBreak("2001 to 2300", "2001 to 2300", 2001.0, 2300.0, fifthClassSymbol, this);
        QList<ClassBreak*> elevationBreaks = {firstClassBreak, secondClassBreak, thirdClassBreak, fourthClassBreak, fifthClassBreak};
    
        // Create and assign a class breaks renderer to the feature layer.
        ClassBreaksRenderer* elevationClassBreaksRenderer = new ClassBreaksRenderer("ELEV_GAIN", elevationBreaks, this);
        featureLayer->setRenderer(elevationClassBreaksRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.75);
    }
    
    void Display_a_map::addBikeOnlyTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'Yes'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* bikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("blue"), 2, this);
        SimpleRenderer* bikeTrailRenderer = new SimpleRenderer(bikeTrailSymbol, this);
        featureLayer->setRenderer(bikeTrailRenderer);
    }
    
    void Display_a_map::addNoBikeTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that don't permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'No'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* noBikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("red"), 2, this);
        SimpleRenderer* noBikeTrailRenderer = new SimpleRenderer(noBikeTrailSymbol, this);
        featureLayer->setRenderer(noBikeTrailRenderer);
    }
    
    LabelDefinition* Display_a_map::makeLabelDefinition()
    {
        // Create a new text symbol.
        TextSymbol* labelTextSymbol = new TextSymbol(this);
        labelTextSymbol->setColor(QColor("white"));
        labelTextSymbol->setSize(12.0);
        labelTextSymbol->setHaloColor (QColor("black"));
        labelTextSymbol->setHaloWidth(2.0);
        labelTextSymbol->setFontFamily("Arial");
        labelTextSymbol->setFontStyle(FontStyle::Italic);
        labelTextSymbol->setFontWeight(FontWeight::Normal);
    
        // Create a new Arcade label expression based on the field name: 'TRL_NAME'.
        ArcadeLabelExpression* labelExpression = new ArcadeLabelExpression("$feature.TRL_NAME", this);
    
        // Create and return the label definition.
        return new LabelDefinition(labelExpression, labelTextSymbol, this);
    }
    
    void Display_a_map::addTrailheadsLayer()
    {
        // Create a ServiceFeatureTable from the URL, create a FeatureLayer, and add that to the map's operational layers.
        QUrl trailheadsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(trailheadsQUrl);
    
        // Create a new picture marker symbol that uses the trailhead image.
        QUrl trailheadImageQUrl("https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png");
        PictureMarkerSymbol* pictureMarkerSymbol = new PictureMarkerSymbol(trailheadImageQUrl, this);
        pictureMarkerSymbol->setHeight(18.0);
        pictureMarkerSymbol->setWidth(18.0);
    
        // Create a new simple renderer based on the picture marker symbol.
        SimpleRenderer* simpleRenderer = new SimpleRenderer(pictureMarkerSymbol, this);
    
        // Set the feature layer's renderer and enable labels.
        featureLayer->setRenderer(simpleRenderer);
        featureLayer->setLabelsEnabled(true);
    
        // Create the label definition.
        LabelDefinition* trailHeadsDefinition = makeLabelDefinition();
    
        // Add the label definition to the layer's label definition collection.
        featureLayer->labelDefinitions()->append(trailHeadsDefinition);
    }
    
    // Set the view (created in QML)
    void Display_a_map::setMapView(MapQuickView* mapView)
    {
        if (!mapView || mapView == m_mapView)
        {
            return;
        }
    
        m_mapView = mapView;
        m_mapView->setMap(m_map);
    
        setupMap();
    
        emit mapViewChanged();
    }
    
  2. Add include statements to access the classes used in addOpenSpaceLayer().

    Display_a_map.cpp
    Use dark colors for code blocks
    16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 17 18 19 20 21 22 23 24 25 26 27 27 27 27 27 27 27 27 27 27 27 27 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 25 24 24 24 24 24 24 24 23 22 21 20 19 18 17 16 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -84 -84 -84 -84 -84 -84 -84 -84 -84 -84 -84 -84 -84 -84 -84
    Add line.Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    //   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
    //
    //   https://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.
    
    #include "Display_a_map.h"
    #include "ArcGISRuntimeEnvironment.h"
    
    #include "Basemap.h"
    #include "Map.h"
    #include "MapQuickView.h"
    
    #include "FeatureLayer.h"
    #include "ServiceFeatureTable.h"
    
    #include <QUrl>
    #include "SimpleFillSymbol.h"
    #include "UniqueValueRenderer.h"
    
    #include "SimpleLineSymbol.h"
    #include <QList>
    #include "ClassBreaksRenderer.h"
    
    #include "SimpleRenderer.h"
    
    #include "LabelDefinition.h"
    #include "TextSymbol.h"
    #include "ArcadeLabelExpression.h"
    
    #include "PictureMarkerSymbol.h"
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_map::Display_a_map(QObject* parent /* = nullptr */):
        QObject(parent),
        m_map(new Map(BasemapStyle::ArcGISTopographic, this))
    {
    }
    
    Display_a_map::~Display_a_map()
    {
    }
    
    MapQuickView* Display_a_map::mapView() const
    {
        return m_mapView;
    }
    
    QUrl trailsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
    
    void Display_a_map::setupMap()
    {
        const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
        const Viewpoint viewpoint(center, 100000.0);
        m_mapView->setViewpoint(viewpoint);
    
        addOpenSpaceLayer();
    
        addTrailsLayer();
    
        addBikeOnlyTrailsLayer();
        addNoBikeTrailsLayer();
    
        addTrailheadsLayer();
    
    }
    
    // Create a new function that creates a feature layer and appends it to the operational layers and the m_map.
    FeatureLayer* Display_a_map::addFeatureLayer(const QUrl& url)
    {
        ServiceFeatureTable* serviceFeatureTable = new ServiceFeatureTable(url, this);
        FeatureLayer* featureLayer = new FeatureLayer(serviceFeatureTable, this);
        m_map->operationalLayers()->append(featureLayer);
        return featureLayer;
    }
    
    void Display_a_map::addOpenSpaceLayer()
    {
        // Create a parks and open spaces feature layer.
        QUrl parksAndOpenSpacesQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(parksAndOpenSpacesQUrl);
    
        // Create fill symbols.
        SimpleFillSymbol* purpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("purple"), this);
        SimpleFillSymbol* greenFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("green"), this);
        SimpleFillSymbol* blueFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("blue"), this);
        SimpleFillSymbol* redFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("red"), this);
    
        // Create a unique value for natural areas, regional open spaces, local parks & regional recreation parks.
        UniqueValue* naturalAreas = new UniqueValue("Natural Areas", "Natural Areas", {"Natural Areas"}, purpleFillSymbol, this);
        UniqueValue* regionalOpenSpace = new UniqueValue("Regional Open Space", "Regional Open Space", {"Regional Open Space"}, greenFillSymbol, this);
        UniqueValue* localPark = new UniqueValue("Local Park", "Local Park", {"Local Park"}, blueFillSymbol, this);
        UniqueValue* regionalRecreationPark = new UniqueValue("Regional Recreation Park", "Regional Recreation Park",
                                                              {"Regional Recreation Park"}, redFillSymbol, this);
    
        // Create and assign a unique value renderer to the feature layer.
        UniqueValueRenderer* openSpacesUniqueValueRenderer = new UniqueValueRenderer("Open Spaces", nullptr, {"TYPE"},
                                                                                     {naturalAreas, regionalOpenSpace, localPark, regionalRecreationPark }, this);
        featureLayer->setRenderer(openSpacesUniqueValueRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.25f);
    }
    
    void Display_a_map::addTrailsLayer()
    {
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
        // Create five line symbols to display class breaks.
        SimpleLineSymbol* firstClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 3, this);
        SimpleLineSymbol* secondClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 4, this);
        SimpleLineSymbol* thirdClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 5, this);
        SimpleLineSymbol* fourthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 6, this);
        SimpleLineSymbol* fifthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 7, this);
    
        // Create five class breaks.
        ClassBreak* firstClassBreak = new ClassBreak("Under 500", "0 - 500", 0.0, 500.0, firstClassSymbol, this);
        ClassBreak* secondClassBreak = new ClassBreak("501 to 1000", "501 - 1000", 501.0, 1000.0, secondClassSymbol, this);
        ClassBreak* thirdClassBreak = new ClassBreak("1001 to 1500", "1001 - 1500", 1001.0, 1500.0, thirdClassSymbol, this);
        ClassBreak* fourthClassBreak = new ClassBreak("1501 to 2000", "1501 - 2000", 1501.0, 2000.0, fourthClassSymbol, this);
        ClassBreak* fifthClassBreak = new ClassBreak("2001 to 2300", "2001 to 2300", 2001.0, 2300.0, fifthClassSymbol, this);
        QList<ClassBreak*> elevationBreaks = {firstClassBreak, secondClassBreak, thirdClassBreak, fourthClassBreak, fifthClassBreak};
    
        // Create and assign a class breaks renderer to the feature layer.
        ClassBreaksRenderer* elevationClassBreaksRenderer = new ClassBreaksRenderer("ELEV_GAIN", elevationBreaks, this);
        featureLayer->setRenderer(elevationClassBreaksRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.75);
    }
    
    void Display_a_map::addBikeOnlyTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'Yes'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* bikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("blue"), 2, this);
        SimpleRenderer* bikeTrailRenderer = new SimpleRenderer(bikeTrailSymbol, this);
        featureLayer->setRenderer(bikeTrailRenderer);
    }
    
    void Display_a_map::addNoBikeTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that don't permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'No'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* noBikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("red"), 2, this);
        SimpleRenderer* noBikeTrailRenderer = new SimpleRenderer(noBikeTrailSymbol, this);
        featureLayer->setRenderer(noBikeTrailRenderer);
    }
    
    LabelDefinition* Display_a_map::makeLabelDefinition()
    {
        // Create a new text symbol.
        TextSymbol* labelTextSymbol = new TextSymbol(this);
        labelTextSymbol->setColor(QColor("white"));
        labelTextSymbol->setSize(12.0);
        labelTextSymbol->setHaloColor (QColor("black"));
        labelTextSymbol->setHaloWidth(2.0);
        labelTextSymbol->setFontFamily("Arial");
        labelTextSymbol->setFontStyle(FontStyle::Italic);
        labelTextSymbol->setFontWeight(FontWeight::Normal);
    
        // Create a new Arcade label expression based on the field name: 'TRL_NAME'.
        ArcadeLabelExpression* labelExpression = new ArcadeLabelExpression("$feature.TRL_NAME", this);
    
        // Create and return the label definition.
        return new LabelDefinition(labelExpression, labelTextSymbol, this);
    }
    
    void Display_a_map::addTrailheadsLayer()
    {
        // Create a ServiceFeatureTable from the URL, create a FeatureLayer, and add that to the map's operational layers.
        QUrl trailheadsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(trailheadsQUrl);
    
        // Create a new picture marker symbol that uses the trailhead image.
        QUrl trailheadImageQUrl("https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png");
        PictureMarkerSymbol* pictureMarkerSymbol = new PictureMarkerSymbol(trailheadImageQUrl, this);
        pictureMarkerSymbol->setHeight(18.0);
        pictureMarkerSymbol->setWidth(18.0);
    
        // Create a new simple renderer based on the picture marker symbol.
        SimpleRenderer* simpleRenderer = new SimpleRenderer(pictureMarkerSymbol, this);
    
        // Set the feature layer's renderer and enable labels.
        featureLayer->setRenderer(simpleRenderer);
        featureLayer->setLabelsEnabled(true);
    
        // Create the label definition.
        LabelDefinition* trailHeadsDefinition = makeLabelDefinition();
    
        // Add the label definition to the layer's label definition collection.
        featureLayer->labelDefinitions()->append(trailHeadsDefinition);
    }
    
    // Set the view (created in QML)
    void Display_a_map::setMapView(MapQuickView* mapView)
    {
        if (!mapView || mapView == m_mapView)
        {
            return;
        }
    
        m_mapView = mapView;
        m_mapView->setMap(m_map);
    
        setupMap();
    
        emit mapViewChanged();
    }
    
  3. Update setupMap() to call the new addOpenSpaceLayer() method.

    Display_a_map.cpp
    Use dark colors for code blocks
    58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 57 56 55 54 53 52 51 50 49 48 47 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 45 44 45 46 47 48 49 50 51 51 50 49 48 47 46 45 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55
    Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    //   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
    //
    //   https://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.
    
    #include "Display_a_map.h"
    #include "ArcGISRuntimeEnvironment.h"
    
    #include "Basemap.h"
    #include "Map.h"
    #include "MapQuickView.h"
    
    #include "FeatureLayer.h"
    #include "ServiceFeatureTable.h"
    
    #include <QUrl>
    #include "SimpleFillSymbol.h"
    #include "UniqueValueRenderer.h"
    
    #include "SimpleLineSymbol.h"
    #include <QList>
    #include "ClassBreaksRenderer.h"
    
    #include "SimpleRenderer.h"
    
    #include "LabelDefinition.h"
    #include "TextSymbol.h"
    #include "ArcadeLabelExpression.h"
    
    #include "PictureMarkerSymbol.h"
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_map::Display_a_map(QObject* parent /* = nullptr */):
        QObject(parent),
        m_map(new Map(BasemapStyle::ArcGISTopographic, this))
    {
    }
    
    Display_a_map::~Display_a_map()
    {
    }
    
    MapQuickView* Display_a_map::mapView() const
    {
        return m_mapView;
    }
    
    QUrl trailsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
    
    void Display_a_map::setupMap()
    {
        const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
        const Viewpoint viewpoint(center, 100000.0);
        m_mapView->setViewpoint(viewpoint);
    
        addOpenSpaceLayer();
    
        addTrailsLayer();
    
        addBikeOnlyTrailsLayer();
        addNoBikeTrailsLayer();
    
        addTrailheadsLayer();
    
    }
    
    // Create a new function that creates a feature layer and appends it to the operational layers and the m_map.
    FeatureLayer* Display_a_map::addFeatureLayer(const QUrl& url)
    {
        ServiceFeatureTable* serviceFeatureTable = new ServiceFeatureTable(url, this);
        FeatureLayer* featureLayer = new FeatureLayer(serviceFeatureTable, this);
        m_map->operationalLayers()->append(featureLayer);
        return featureLayer;
    }
    
    void Display_a_map::addOpenSpaceLayer()
    {
        // Create a parks and open spaces feature layer.
        QUrl parksAndOpenSpacesQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(parksAndOpenSpacesQUrl);
    
        // Create fill symbols.
        SimpleFillSymbol* purpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("purple"), this);
        SimpleFillSymbol* greenFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("green"), this);
        SimpleFillSymbol* blueFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("blue"), this);
        SimpleFillSymbol* redFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("red"), this);
    
        // Create a unique value for natural areas, regional open spaces, local parks & regional recreation parks.
        UniqueValue* naturalAreas = new UniqueValue("Natural Areas", "Natural Areas", {"Natural Areas"}, purpleFillSymbol, this);
        UniqueValue* regionalOpenSpace = new UniqueValue("Regional Open Space", "Regional Open Space", {"Regional Open Space"}, greenFillSymbol, this);
        UniqueValue* localPark = new UniqueValue("Local Park", "Local Park", {"Local Park"}, blueFillSymbol, this);
        UniqueValue* regionalRecreationPark = new UniqueValue("Regional Recreation Park", "Regional Recreation Park",
                                                              {"Regional Recreation Park"}, redFillSymbol, this);
    
        // Create and assign a unique value renderer to the feature layer.
        UniqueValueRenderer* openSpacesUniqueValueRenderer = new UniqueValueRenderer("Open Spaces", nullptr, {"TYPE"},
                                                                                     {naturalAreas, regionalOpenSpace, localPark, regionalRecreationPark }, this);
        featureLayer->setRenderer(openSpacesUniqueValueRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.25f);
    }
    
    void Display_a_map::addTrailsLayer()
    {
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
        // Create five line symbols to display class breaks.
        SimpleLineSymbol* firstClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 3, this);
        SimpleLineSymbol* secondClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 4, this);
        SimpleLineSymbol* thirdClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 5, this);
        SimpleLineSymbol* fourthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 6, this);
        SimpleLineSymbol* fifthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 7, this);
    
        // Create five class breaks.
        ClassBreak* firstClassBreak = new ClassBreak("Under 500", "0 - 500", 0.0, 500.0, firstClassSymbol, this);
        ClassBreak* secondClassBreak = new ClassBreak("501 to 1000", "501 - 1000", 501.0, 1000.0, secondClassSymbol, this);
        ClassBreak* thirdClassBreak = new ClassBreak("1001 to 1500", "1001 - 1500", 1001.0, 1500.0, thirdClassSymbol, this);
        ClassBreak* fourthClassBreak = new ClassBreak("1501 to 2000", "1501 - 2000", 1501.0, 2000.0, fourthClassSymbol, this);
        ClassBreak* fifthClassBreak = new ClassBreak("2001 to 2300", "2001 to 2300", 2001.0, 2300.0, fifthClassSymbol, this);
        QList<ClassBreak*> elevationBreaks = {firstClassBreak, secondClassBreak, thirdClassBreak, fourthClassBreak, fifthClassBreak};
    
        // Create and assign a class breaks renderer to the feature layer.
        ClassBreaksRenderer* elevationClassBreaksRenderer = new ClassBreaksRenderer("ELEV_GAIN", elevationBreaks, this);
        featureLayer->setRenderer(elevationClassBreaksRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.75);
    }
    
    void Display_a_map::addBikeOnlyTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'Yes'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* bikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("blue"), 2, this);
        SimpleRenderer* bikeTrailRenderer = new SimpleRenderer(bikeTrailSymbol, this);
        featureLayer->setRenderer(bikeTrailRenderer);
    }
    
    void Display_a_map::addNoBikeTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that don't permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'No'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* noBikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("red"), 2, this);
        SimpleRenderer* noBikeTrailRenderer = new SimpleRenderer(noBikeTrailSymbol, this);
        featureLayer->setRenderer(noBikeTrailRenderer);
    }
    
    LabelDefinition* Display_a_map::makeLabelDefinition()
    {
        // Create a new text symbol.
        TextSymbol* labelTextSymbol = new TextSymbol(this);
        labelTextSymbol->setColor(QColor("white"));
        labelTextSymbol->setSize(12.0);
        labelTextSymbol->setHaloColor (QColor("black"));
        labelTextSymbol->setHaloWidth(2.0);
        labelTextSymbol->setFontFamily("Arial");
        labelTextSymbol->setFontStyle(FontStyle::Italic);
        labelTextSymbol->setFontWeight(FontWeight::Normal);
    
        // Create a new Arcade label expression based on the field name: 'TRL_NAME'.
        ArcadeLabelExpression* labelExpression = new ArcadeLabelExpression("$feature.TRL_NAME", this);
    
        // Create and return the label definition.
        return new LabelDefinition(labelExpression, labelTextSymbol, this);
    }
    
    void Display_a_map::addTrailheadsLayer()
    {
        // Create a ServiceFeatureTable from the URL, create a FeatureLayer, and add that to the map's operational layers.
        QUrl trailheadsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(trailheadsQUrl);
    
        // Create a new picture marker symbol that uses the trailhead image.
        QUrl trailheadImageQUrl("https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png");
        PictureMarkerSymbol* pictureMarkerSymbol = new PictureMarkerSymbol(trailheadImageQUrl, this);
        pictureMarkerSymbol->setHeight(18.0);
        pictureMarkerSymbol->setWidth(18.0);
    
        // Create a new simple renderer based on the picture marker symbol.
        SimpleRenderer* simpleRenderer = new SimpleRenderer(pictureMarkerSymbol, this);
    
        // Set the feature layer's renderer and enable labels.
        featureLayer->setRenderer(simpleRenderer);
        featureLayer->setLabelsEnabled(true);
    
        // Create the label definition.
        LabelDefinition* trailHeadsDefinition = makeLabelDefinition();
    
        // Add the label definition to the layer's label definition collection.
        featureLayer->labelDefinitions()->append(trailHeadsDefinition);
    }
    
    // Set the view (created in QML)
    void Display_a_map::setMapView(MapQuickView* mapView)
    {
        if (!mapView || mapView == m_mapView)
        {
            return;
        }
    
        m_mapView = mapView;
        m_mapView->setMap(m_map);
    
        setupMap();
    
        emit mapViewChanged();
    }
    
  4. Press <Ctrl+R> to run the app.

When the app opens, Parks and Open Spaces feature layer is added to the map. The map displays the different types of parks and open spaces with four unique symbols.

Add a layer with a class breaks renderer

Create a method to apply a different symbol for each of the five ranges of elevation gain to the Trails feature layer.

  1. Add a new method named addTrailsLayer().

    A ClassBreak assigns a symbol to a range of values.

    For this example, the renderer uses each feature's ELEV_GAIN attribute value to classify it into a defined range (class break) and apply the corresponding symbol.

    Display_a_map.cpp
    Use dark colors for code blocks
    112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 111 110 109 108 107 106 105 104 103 102 101 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98 98 98 98 98 98 98 98 98 97 96 95 94 93 92 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    //   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
    //
    //   https://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.
    
    #include "Display_a_map.h"
    #include "ArcGISRuntimeEnvironment.h"
    
    #include "Basemap.h"
    #include "Map.h"
    #include "MapQuickView.h"
    
    #include "FeatureLayer.h"
    #include "ServiceFeatureTable.h"
    
    #include <QUrl>
    #include "SimpleFillSymbol.h"
    #include "UniqueValueRenderer.h"
    
    #include "SimpleLineSymbol.h"
    #include <QList>
    #include "ClassBreaksRenderer.h"
    
    #include "SimpleRenderer.h"
    
    #include "LabelDefinition.h"
    #include "TextSymbol.h"
    #include "ArcadeLabelExpression.h"
    
    #include "PictureMarkerSymbol.h"
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_map::Display_a_map(QObject* parent /* = nullptr */):
        QObject(parent),
        m_map(new Map(BasemapStyle::ArcGISTopographic, this))
    {
    }
    
    Display_a_map::~Display_a_map()
    {
    }
    
    MapQuickView* Display_a_map::mapView() const
    {
        return m_mapView;
    }
    
    QUrl trailsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
    
    void Display_a_map::setupMap()
    {
        const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
        const Viewpoint viewpoint(center, 100000.0);
        m_mapView->setViewpoint(viewpoint);
    
        addOpenSpaceLayer();
    
        addTrailsLayer();
    
        addBikeOnlyTrailsLayer();
        addNoBikeTrailsLayer();
    
        addTrailheadsLayer();
    
    }
    
    // Create a new function that creates a feature layer and appends it to the operational layers and the m_map.
    FeatureLayer* Display_a_map::addFeatureLayer(const QUrl& url)
    {
        ServiceFeatureTable* serviceFeatureTable = new ServiceFeatureTable(url, this);
        FeatureLayer* featureLayer = new FeatureLayer(serviceFeatureTable, this);
        m_map->operationalLayers()->append(featureLayer);
        return featureLayer;
    }
    
    void Display_a_map::addOpenSpaceLayer()
    {
        // Create a parks and open spaces feature layer.
        QUrl parksAndOpenSpacesQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(parksAndOpenSpacesQUrl);
    
        // Create fill symbols.
        SimpleFillSymbol* purpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("purple"), this);
        SimpleFillSymbol* greenFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("green"), this);
        SimpleFillSymbol* blueFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("blue"), this);
        SimpleFillSymbol* redFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("red"), this);
    
        // Create a unique value for natural areas, regional open spaces, local parks & regional recreation parks.
        UniqueValue* naturalAreas = new UniqueValue("Natural Areas", "Natural Areas", {"Natural Areas"}, purpleFillSymbol, this);
        UniqueValue* regionalOpenSpace = new UniqueValue("Regional Open Space", "Regional Open Space", {"Regional Open Space"}, greenFillSymbol, this);
        UniqueValue* localPark = new UniqueValue("Local Park", "Local Park", {"Local Park"}, blueFillSymbol, this);
        UniqueValue* regionalRecreationPark = new UniqueValue("Regional Recreation Park", "Regional Recreation Park",
                                                              {"Regional Recreation Park"}, redFillSymbol, this);
    
        // Create and assign a unique value renderer to the feature layer.
        UniqueValueRenderer* openSpacesUniqueValueRenderer = new UniqueValueRenderer("Open Spaces", nullptr, {"TYPE"},
                                                                                     {naturalAreas, regionalOpenSpace, localPark, regionalRecreationPark }, this);
        featureLayer->setRenderer(openSpacesUniqueValueRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.25f);
    }
    
    void Display_a_map::addTrailsLayer()
    {
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
        // Create five line symbols to display class breaks.
        SimpleLineSymbol* firstClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 3, this);
        SimpleLineSymbol* secondClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 4, this);
        SimpleLineSymbol* thirdClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 5, this);
        SimpleLineSymbol* fourthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 6, this);
        SimpleLineSymbol* fifthClassSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("purple"), 7, this);
    
        // Create five class breaks.
        ClassBreak* firstClassBreak = new ClassBreak("Under 500", "0 - 500", 0.0, 500.0, firstClassSymbol, this);
        ClassBreak* secondClassBreak = new ClassBreak("501 to 1000", "501 - 1000", 501.0, 1000.0, secondClassSymbol, this);
        ClassBreak* thirdClassBreak = new ClassBreak("1001 to 1500", "1001 - 1500", 1001.0, 1500.0, thirdClassSymbol, this);
        ClassBreak* fourthClassBreak = new ClassBreak("1501 to 2000", "1501 - 2000", 1501.0, 2000.0, fourthClassSymbol, this);
        ClassBreak* fifthClassBreak = new ClassBreak("2001 to 2300", "2001 to 2300", 2001.0, 2300.0, fifthClassSymbol, this);
        QList<ClassBreak*> elevationBreaks = {firstClassBreak, secondClassBreak, thirdClassBreak, fourthClassBreak, fifthClassBreak};
    
        // Create and assign a class breaks renderer to the feature layer.
        ClassBreaksRenderer* elevationClassBreaksRenderer = new ClassBreaksRenderer("ELEV_GAIN", elevationBreaks, this);
        featureLayer->setRenderer(elevationClassBreaksRenderer);
    
        // Set the layer opacity to semi-transparent.
        featureLayer->setOpacity(0.75);
    }
    
    void Display_a_map::addBikeOnlyTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'Yes'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* bikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("blue"), 2, this);
        SimpleRenderer* bikeTrailRenderer = new SimpleRenderer(bikeTrailSymbol, this);
        featureLayer->setRenderer(bikeTrailRenderer);
    }
    
    void Display_a_map::addNoBikeTrailsLayer()
    {
        // Create a trails feature layer and add it to the map view.
        FeatureLayer* featureLayer = addFeatureLayer(trailsQUrl);
    
        // Write a definition expression to filter for trails that don't permit the use of bikes.
        featureLayer->setDefinitionExpression("USE_BIKE = 'No'");
    
        // Create and assign a simple renderer to the feature layer.
        SimpleLineSymbol* noBikeTrailSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dot, QColor("red"), 2, this);
        SimpleRenderer* noBikeTrailRenderer = new SimpleRenderer(noBikeTrailSymbol, this);
        featureLayer->setRenderer(noBikeTrailRenderer);
    }
    
    LabelDefinition* Display_a_map::makeLabelDefinition()
    {
        // Create a new text symbol.
        TextSymbol* labelTextSymbol = new TextSymbol(this);
        labelTextSymbol->setColor(QColor("white"));
        labelTextSymbol->setSize(12.0);
        labelTextSymbol->setHaloColor (QColor("black"));
        labelTextSymbol->setHaloWidth(2.0);
        labelTextSymbol->setFontFamily("Arial");
        labelTextSymbol->setFontStyle(FontStyle::Italic);
        labelTextSymbol->setFontWeight(FontWeight::Normal);
    
        // Create a new Arcade label expression based on the field name: 'TRL_NAME'.
        ArcadeLabelExpression* labelExpression = new ArcadeLabelExpression("$feature.TRL_NAME", this);
    
        // Create and return the label definition.
        return new LabelDefinition(labelExpression, labelTextSymbol, this);
    }
    
    void Display_a_map::addTrailheadsLayer()
    {
        // Create a ServiceFeatureTable from the URL, create a FeatureLayer, and add that to the map's operational layers.
        QUrl trailheadsQUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0");
        FeatureLayer* featureLayer = addFeatureLayer(trailheadsQUrl);
    
        // Create a new picture marker symbol that uses the trailhead image.
        QUrl trailheadImageQUrl("https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png");
        PictureMarkerSymbol* pictureMarkerSymbol = new PictureMarkerSymbol(trailheadImageQUrl, this);
        pictureMarkerSymbol->setHeight(18.0);
        pictureMarkerSymbol->setWidth(18.0);
    
        // Create a new simple renderer based on the picture marker symbol.
        SimpleRenderer* simpleRenderer = new SimpleRenderer(pictureMarkerSymbol, this);
    
        // Set the feature layer's renderer and enable labels.
        featureLayer->setRenderer(simpleRenderer);
        featureLayer->setLabelsEnabled(true);
    
        // Create the label definition.
        LabelDefinition* trailHeadsDefinition = makeLabelDefinition();
    
        // Add the label definition to the layer's label definition collection.
        featureLayer->labelDefinitions()->append(trailHeadsDefinition);
    }
    
    // Set the view (created in QML)
    void Display_a_map::setMapView(MapQuickView* mapView)
    {
        if (!mapView || mapView == m_mapView)
        {
            return;
        }
    
        m_mapView = mapView;
        m_mapView->setMap(m_map);
    
        setupMap();
    
        emit mapViewChanged();
    }
    
  2. Add a global QUrl variable for the trails feature service.

    Display_a_map.cpp
    Use dark colors for code blocks
    51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 50 49 48 47 46 45 44 43 42 41 40 39 39 39 39 39 39 39 39 39 39 39 39 39 40 41 42 43 44 45 45 45 45 45 45 45 45 45 45 44 43 42 41 40 39 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23