Add layers (C++ API)

Learn how to add and manage layers by using the C++ API with an example of New York.

In this tutorial, you'll add raster tile layers, 3D object scene layers from ArcGIS Online in a global scene or local scene. Also, you'll learn how to add local files, how to manage layers such as set visibility, reorder and remove layers.

Prerequisites

Before starting this tutorial, you should:

Follow the C++ tutorials in display the globe (C++ API) or display a specific area (C++ API).

Steps

  1. Open your .cpp file and add necessary headers in the include list.

    Use dark colors for code blocksCopy
      
    1
    2
    #include "ArcGISMapsSDK/BlueprintNodes/GameEngine/Layers/ArcGISImageLayer.h"
    #include "ArcGISMapsSDK/BlueprintNodes/GameEngine/Layers/ArcGIS3DModelLayer.h"
  2. In the function CreateArcGISMap(), add a raster tile layer (image tile layer) by using the class name UArcGISImageLayer. Get the arcGISMap layer array from arcGISMap by using GetLayers() and add the layer to it. Set the opacity value to 1.0f and the visibility to true.

    Use UrbanObservatory_NYC_TransitFrequency for layer_1.

    Use dark colors for code blocksCopy
        
    1
    2
    3
    4
    auto layer_1 = UArcGISImageLayer::CreateArcGISImageLayerWithProperties(
        "https://tiles.arcgis.com/tiles/nGt4QxSblgDfeJn9/arcgis/rest/services/UrbanObservatory_NYC_TransitFrequency/MapServer",
        "NYTransitFrequencyTiles", 1.0f, true, apiKey);
    arcGISMap->GetLayers()->Add(layer_1);
  3. Add another raster tile layer.

    Use New_York_Industrial for layer_2.

    Use dark colors for code blocksCopy
        
    1
    2
    3
    4
    auto layer_2 = UArcGISImageLayer::CreateArcGISImageLayerWithProperties(
        "https://tiles.arcgis.com/tiles/nGt4QxSblgDfeJn9/arcgis/rest/services/New_York_Industrial/MapServer",
        "NYIndustrialTiles", 1.0f, true, apiKey);
    arcGISMap->GetLayers()->Add(layer_2);
  4. Add one more raster tile layer and set the visibility to true.

    Use NewYorkCity_PopDensity for layer_3.

    Use dark colors for code blocksCopy
        
    1
    2
    3
    4
    auto layer_3 = UArcGISImageLayer::CreateArcGISImageLayerWithProperties(
        "https://tiles.arcgis.com/tiles/4yjifSiIG17X0gW4/arcgis/rest/services/NewYorkCity_PopDensity/MapServer", "NYPopDensityTiles", 1.0f, true,
        apiKey);
    arcGISMap->GetLayers()->Add(layer_3);
  5. To add a 3D object scene layer, use the class name UArcGIS3DModelLayer.

    Use New York, USA Buildings for buildingLayer.

    Use dark colors for code blocksCopy
       
    1
    2
    3
    auto buildingLayer = UArcGIS3DModelLayer::CreateArcGIS3DModelLayerWithProperties(
        "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_NewYork_17/SceneServer", "NYScene", 1.0f, true, apiKey);
    arcGISMap->GetLayers()->Add(buildingLayer);

Save and you have successfully configured a scene using the API.

C++ sample

You can change the opacity and visibility of added layers (either during runtime or with presets), delete and reorder layers.

To remove a layer:

Use dark colors for code blocksCopy
  
1
2
auto index = arcGISMap->GetLayers()->IndexOf(buildingLayer);
arcGISMap->GetLayers()->Remove(index);

To change the opacity of a layer:

Use dark colors for code blocksCopy
 
1
layer_1.SetOpacity(0.9f);

What's next

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.