Learn how to set a basemap, elevation source, data layers by using the C++ API.
In this tutorial, you will create a C++ class to set up an ArcGIS Map with a circular extent in the Local scene. Using the C++ class, you can easily switch between the Global and Local scene by modifying one line of code.
Click on File on the Menu Bar and select New Level.
Select Empty Level in the popup window.
Click Window in the menu bar and select World Settings.
Open Advanced under World and check Enable Large Worlds.
Initialize the C++ API
To create these scripts in your project, you need to go to the content folder. Click Tools > New C++ Class.
This will show the Choose Parent Class wizard. You want your script to attach to an Actor. Select All Classes and click on ArcGIS Actor under Actor, then click Next. ArcGIS Actor includes ArcGIS Maps SDK Subsystem Listener that allows you to use the editor mode.
Give a name to the Actor and set where you like to place the Actor script. It can be set in the host project or in a different module. The Public/Private button will define whether this class will be public or private. Also, you can define the path where the file will be. After you fill out the parameters click Create Class.
After Unreal Engine compiles the project, Visual Studio will automatically open the .h and the .cpp files.
Add Actors and set Origin Position
ArcGIS Map Actor will place your GIS content in Unreal Engine space, and you can enable/disable the editor mode and Mesh Colliders. In this tutorial, you will configure where your GIS content is to be placed at 0, 0, 0 of the game engine space.
You can find the ArcGIS Map Actor here:
Plugins\ArcGIS Maps SDK for Unreal Engine C++ Classes\ArcGISMapsSDK\Public\ArcGISMapsSDK\Actors
Drag the ArcGIS Map Actor into the level.
Configure the Origin Position with a WKID for the values. In this tutorial, you are setting up the following Origin Position values for New York City.
Longitude: -74
Latitude: 40
Spatial Reference WKID: 4326
Altitude: 0
This is the result of the ArcGIS Map Actor.
Locate the Map Creator Actor in the Content Drawer. Drag and drop the Actor you created into the level.
Set up the project
Before working on the .h and the .cpp files, we will first set up the project.
Navigate to your MapCreator.cpp file folder. Create a PCH file with the .h suffix as follows:
When you create an ArcGIS Actor, you already have the necessary includes in the header file. Make sure you have ArcGISMapsSDK/Actors/ArcGISActor.h
Set the default values for the Actor's properties and set it to public. Make sure to replace YOUR_API_KEY text with your API key by going to your developer dashboard to get your API key.
For the editor mode, it's necessary to react to changes during the editor time. Add subsystem listener for the ArcGIS Map Component Actor which is connected to the subsystem.
To configure an extent, it is required to provide the center point position together with the shape and dimensions. ArcGISPoint class allows you to define a position of a map with GIS coordinates and its spatial reference. You can use ArcGISPoint to specify the extent center. Use ArcGISExtentCircle to configure an extent with the following parameter values and set it for the map.
Latitude: 40.691242
Longitude: -74.054921
Altitude: 3000 Meters
Radius: 10000 Meters
Spatial Reference: WGS 84 (WKID 4326)
The if statement will check the maptype and the extent can be set only for local. Refer step 2 in the Create ArcGIS Map and set layers section.
For other extent options, refer to the map extent page.
Set initial camera position
The ArcGIS Camera Component controls the data that is loaded into your scene. The ArcGIS Location Component is responsible for the position and the angle of the camera. Unreal Engine's Default Pawn is a kind of Actors that can be controlled by players or AI with some additional Components and functionality. To explore ArcGIS Map with a camera, you can set your camera controller together with the ArcGIS Camera Component and the ArcGIS Location Component to a Default Pawn.
In this tutorial, you will set the initial camera position with C++ script by using ArcGIS Pawn which is a sample Pawn that has a sample camera controller code together with the ArcGIS Camera Component and the ArcGIS Location Component.
The position of the ArcGIS Pawn is defined by the ArcGIS Location Component. To populate the position values of the ArcGIS Location Component, access the Component that is attached to the Actor.
ArcGIS Map Component communicates with ArcGISView to handle what and how the ArcGIS Map to be rendered. Set the viewOptions and arcGISMap to the MapComponent.
You have created the C++ source code for an API scene. Build and compile the project and Unreal Engine will be automatically opened.
Set up the sky and the light
From the quick add menu on the toolbar, select Lights > Directional Light and drag it into the level to create a Directional Light. For more information about Directional Lights, see Lights.
Select the Directional Light in the Outliner, and open the Transform section in the Details panel.
Reset the Location and Set the Rotation to:
X: 0
Y: -28
Z: -28
Set the Mobility to Movable.
In the Light section, change the Intensity Value to 3.1416.
In the Cascaded Shadow Maps section, change the Dynamic Shadow Distance MovableLight to 2000000.
In the Atmosphere and Cloud section, enable Atmosphere Sun Light.
In the Actor > Spawn Collision Handling Method section, select Always Spawn, Ignore Collisions.
From the quick add menu on the toolbar, select Lights > Sky Light and drag it into the level to create a Sky Light. For more information about Sky Light, see Lights.
In the Transform section, reset the Location and set the Mobility to Movable.
In the Light section, enable Real Time Capture.
From the quick add menu on the toolbar, select Visual Effects > Sky Atmosphere and drag it into the level to create a Sky. For more information about Sky Atmosphere, see Fog Effects.
In the Planet section, change the Ground Radius to 6378.137207.
When the light starts loading in the Viewport, you can see the render result in the editor Viewport. Double click on the ArcGIS Pawn in the Outliner panel to snap the editor camera to the camera position.
Use the WASD keys while holding the right mouse button mouse to move around, or hold the left mouse button to pan during the editor mode.
Click the Play icon on the Tool bar, and Use the WASD keys to move around, hold the right mouse button mouse to look around or hold the left mouse button to pan.