· 4 years ago · Jun 15, 2021, 09:38 AM
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5//SDK Components
6using ArcGISMapsSDK.Components;
7using Esri.GameEngine.Camera;
8using Esri.GameEngine.Extent;
9using Esri.GameEngine.Location;
10using Esri.GameEngine.View;
11using Esri.GameEngine.View.Event;
12using Esri.Unity;
13
14public class ApiScene_Wageningen : MonoBehaviour
15{
16 float lattitude = <Lattitude>;
17 float longitude = <Longitude>;
18
19 // Start is called before the first frame update
20 void Start()
21 {
22 // API Key
23 string apiKey = "";//"6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b";
24
25 // View mode
26 var viewMode = Esri.GameEngine.Map.ArcGISMapType.Global;
27
28 // The map component
29 var arcGISMap = new Esri.GameEngine.Map.ArcGISMap(viewMode);
30
31 // Set the Basemap
32 arcGISMap.Basemap = new Esri.GameEngine.Map.ArcGISBasemap("https://www.arcgis.com/sharing/rest/content/items/8d569fbc4dc34f68abae8d72178cee05/data", apiKey);
33
34 // Create the Elevation
35 arcGISMap.Elevation = new Esri.GameEngine.Map.ArcGISMapElevation(new Esri.GameEngine.Elevation.ArcGISImageElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer", "Elevation", apiKey));
36
37 // Adding your custom layer
38 var layer_1 = new Esri.GameEngine.Layers.ArcGIS3DModelLayer("<LINK>", "<NAME>", 1.0f, true, apiKey);
39 arcGISMap.Layers.Add(layer_1);
40
41 // Adding the camera and controller
42 ArcGISCameraComponent cameraGE = Camera.main.gameObject.AddComponent<ArcGISCameraComponent>();
43 ArcGISCameraControllerComponent controller = Camera.main.gameObject.AddComponent<ArcGISCameraControllerComponent>();
44
45 // Setup of the position of the camera
46 var position = new ArcGISGlobalCoordinatesPosition(lattitude, longitude, 3000);
47 var rotation = new ArcGISRotation(68, 0, 65);
48
49 // Adding the values to the camera
50 cameraGE.Latitude = position.Latitude;
51 cameraGE.Longitude = position.Longitude;
52 cameraGE.Height = position.Altitude;
53 cameraGE.Heading = rotation.Heading;
54 cameraGE.Pitch = rotation.Pitch;
55 cameraGE.Roll = rotation.Roll;
56
57 // The creation of the render component
58 GameObject renderContainer = new GameObject("RenderContainer");
59 ArcGISRendererComponent renderer = renderContainer.AddComponent<ArcGISRendererComponent>();
60
61 // This position will be overwritten by the camera component
62 ArcGISCamera camera = new ArcGISCamera("Camera", position, rotation);
63
64 ArcGISRendererViewOptions options = new ArcGISRendererViewOptions();
65 ArcGISRendererView rendererView = new ArcGISRendererView(arcGISMap, camera, options);
66
67 renderer.RendererView = rendererView;
68 cameraGE.RendererView = rendererView;
69
70 // Adding the sky component
71 var currentSky = GameObject.FindObjectOfType<UnityEngine.Rendering.Volume>();
72 if (currentSky)
73 {
74 ArcGISSkyRepositionComponent skyComponent = currentSky.gameObject.AddComponent<ArcGISSkyRepositionComponent>();
75 skyComponent.CameraComponent = cameraGE;
76 skyComponent.RendererComponent = renderer;
77 }
78
79 }
80
81 void Update()
82 {
83
84 }
85}