How to create a SceneView in my project

1317
8
06-01-2017 06:50 AM
ManelKEDDAR
New Contributor III

Hello,

I'm a beginner on using ArcGis runtime V100 framework , and while i was looking at the tutorials i 've created a map using the framework but i didn't find ho to create a scenview  can any one tell me how to do that or explain it more for me thanks a lot

0 Kudos
8 Replies
AnttiKajanus1
Regular Contributor II

Hi and welcome!

Have you looked to Display a scene—ArcGIS Runtime SDK for .NET | ArcGIS for Developers? Hopefully that will give you enough information to get started.

0 Kudos
ManelKEDDAR
New Contributor III

Hello,

I've already seen it , it didn't help me a lot , and doesn't explain it good for beginners like me  , is there a possibility to alter it and make it more clear (step by step)? thanks a lot 

0 Kudos
dotMorten_esri
Esri Frequent Contributor

If you created a MapView and a Map already, it's pretty much identical, except replace the word "Map" with "Scene", so you'll be creating a SceneView instead of a MapView, and you'll be assigning a Scene instead of a Map to the SceneView.Scene property instead of the MapView.Map property.

0 Kudos
ManelKEDDAR
New Contributor III

Hello i've already done what you asked me but does show me just a globe , i share with you my code  in my MainWindow.xaml

<Window x:Class="ArcGISApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
xmlns:local="clr-namespace:ArcGISApp1"
mc:Ignorable="d"
Title="MainWindow" Height="525" Width="790">
<Window.Resources>
<local:MapViewModel x:Key="MapViewModel" />
</Window.Resources>
<Grid>

<!-- <esri:MapView Map="{Binding Map, Source={StaticResource MapViewModel}}" Grid.Column="1"/> -->
<esri:SceneView x:Name="MySceneView">
<esri:SceneView.GraphicsOverlays>
<esri:GraphicsOverlay x:Name="SceneGraphics"/>
</esri:SceneView.GraphicsOverlays>
<esri:Scene>
<esri:Scene.Basemap>
<esri:Basemap>
<esri:ArcGISTiledLayer Name="Topographic"
Source="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
</esri:Basemap>
</esri:Scene.Basemap>
<esri:ArcGISSceneLayer Name="BuildingsLayer"
Source="http://scene.arcgis.com/arcgis/rest/services/Hosted/Buildings_Brest/SceneServer/layers/0"/>

</esri:Scene>

</esri:SceneView>


</Grid>
</Window>

in my MapViewModel.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Location;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Security;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.Portal;
using static System.Net.WebRequestMethods;

namespace ArcGISApp1
{
/// <summary>
/// Provides map data to an application
/// </summary>
public class MapViewModel : INotifyPropertyChanged
{
public MapViewModel()
{

}

// private Map _map = new Map(Basemap.CreateStreetsVector());
private Scene scene = new Scene(Basemap.CreateTopographic());

/// <summary>
/// Gets or sets the map
/// </summary>
/* public Map Map
{
get { return _map; }
set { _map = value; OnPropertyChanged(); }
}*/

public Scene Scene
{
get { return scene; }
set { scene = value;OnPropertyChanged(); }

}
//String array pour stoquer les basemap constructor types

private string[] _basemapTypes = new string[]
{
"Topographic",
"Topographic Vector",
"Streets",
"Streets Vector",
"Imagery",
"Oceans",
"USGS National Map",
"World Globe 1812"


};

//Read-Only property to return the available basemap names
public string[] BasemapChoices
{
get { return _basemapTypes; }
}

/// <summary>
/// Raises the <see cref="MapViewModel.PropertyChanged" /> event
/// </summary>
/// <param name="propertyName">The name of the property that has changed</param>
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var propertyChangedHandler = PropertyChanged;
if (propertyChangedHandler != null)
propertyChangedHandler(this, new PropertyChangedEventArgs(propertyName));
}

public async void ChangeBasemap(string basemap)
{
//apply the selected basemap to the map

switch (basemap)
{
/* case "Topographic":
_map.Basemap = Basemap.CreateTopographic();
break;
case "Topographic Vector":
_map.Basemap = Basemap.CreateTopographicVector();
break;
case "Streets":
//set the basemap to streets
_map.Basemap = Basemap.CreateStreets();
break;
case "Streets Vector":
_map.Basemap = Basemap.CreateStreetsVector();
break;
case "Imagery":
_map.Basemap = Basemap.CreateImagery();
break;
case "Oceans":
_map.Basemap = Basemap.CreateOceans();
break;
case "USGS National Map":
//Set the basemap to USGS National Map by opening it from ArcGis Online
var itemID = "809d37b42ca340a48def914df43e2c31";
//Connect to ArcGIS Online
ArcGISPortal agsOnline = await ArcGISPortal.CreateAsync();
//Get the USGS webmap item
PortalItem usgsMapItem = await PortalItem.CreateAsync(agsOnline, itemID);
//Create a new basemap using the item

_map.Basemap = new Basemap(usgsMapItem);
break;
case "World Globe 1812":
//create a URI that points to a map service to use in the basemap
var uri = new Uri("https://tiles.arcgis.com/tiles/IEuSomXfi6iB7a25/arcgis/rest/services/World_Globe_1812/MapServer");
//create an ArcGISTiledLayer from the URI
ArcGISTiledLayer baseLayer = new ArcGISTiledLayer(uri);
//create a basemap from the layer and assign it to the map
_map.Basemap = new Basemap(baseLayer);
break;*/

}

}


public event PropertyChangedEventHandler PropertyChanged;
}
}

in my MainWindow.xaml.cs

using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ArcGISApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///

public partial class MainWindow : Window
{

private MapViewModel _mapViewModel;


public MainWindow()
{
InitializeComponent();
_mapViewModel = this.FindResource("MapViewModel") as MapViewModel;
var dddBuildingLayer = new ArcGISSceneLayer(new System.Uri("Http://scene.arcgis.com/arcgis/rest/services/Hosted/Buildings_Brest/SceneServer/layers/0"));
_mapViewModel.Scene.OperationalLayers.Add(dddBuildingLayer);

MySceneView.Scene = _mapViewModel.Scene;
var elevationSource = new ArcGISTiledElevationSource(new System.Uri("http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"));
var sceneSurface = new Surface();
sceneSurface.ElevationSources.Add(elevationSource);
MySceneView.Scene.BaseSurface = sceneSurface;
var sceneGraphicsOverLays = new GraphicsOverlay();
MySceneView.GraphicsOverlays.Add(sceneGraphicsOverLays);
var drapedOverlay = new GraphicsOverlay();
//create and add a new graphics overlay with drapped surface placement
drapedOverlay.SceneProperties.SurfacePlacement = SurfacePlacement.Draped;
drapedOverlay.SceneProperties.SurfacePlacement = SurfacePlacement.Draped;
MySceneView.GraphicsOverlays.Add(drapedOverlay);
//create and add a new graphics overlay with absolute surface placement
var absoluteOverlay = new GraphicsOverlay();
absoluteOverlay.SceneProperties.SurfacePlacement = SurfacePlacement.Absolute;
MySceneView.GraphicsOverlays.Add(absoluteOverlay);
//create and add a new graphics overlay with relative surface placement
var relativeOverlay = new GraphicsOverlay();
relativeOverlay.SceneProperties.SurfacePlacement = SurfacePlacement.Relative;
MySceneView.GraphicsOverlays.Add(relativeOverlay);
//create a map point to display
var location = new MapPoint(-4.04, 53.06, 1000, SpatialReference.Wgs84);
//create three graphics to display the location with different symbols
var redGraphic = new Graphic(location, redCircleSym);
var greenGraphic = new Graphic(location, greenCircleSym);
var blueGraphic = new Graphic(location, blueCircleSym);
// add each graphic to a different graphics overlay (different surface placement)
drapedOverlay.Graphics.Add(redGraphic);
absoluteOverlay.Graphics.Add(blueGraphic);
relativeOverlay.Graphics.Add(greenGraphic);


// BasemapListBox.SelectionChanged += OnBasemapsClicked
}

private void OnBasemapsClicked(object sender , SelectionChangedEventArgs e)
{
//get the text (basemap name) selected in the list box
var basemapName = e.AddedItems[0].ToString();
//pass the basemap name to the view model method to change the basemap
_mapViewModel.ChangeBasemap(basemapName);
}
// Map initialization logic is contained in MapViewModel.cs
}
}

but it doesn't show me the scene as in the tutorial and i have an error saying SpatialReference doesn't have a definition for "Wgs84"

Any one can make it clear to me please

thanks a lot 

0 Kudos
NagmaYasmin
Occasional Contributor III

Hi Manel,

I am able to see the 3D scene layer. Below is my code:

XAML:

<Grid>
   <esri:SceneView x:Name="MySceneView" />
</Grid>
</Window>

XAML.cs

=========

public MainWindow()
{
InitializeComponent();
Initialize();
}

private void Initialize()
{

Scene myScene = new Scene(Basemap.CreateTopographic());

ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(new Uri("http://scene.arcgis.com/arcgis/rest/services/Hosted/Buildings_Brest/SceneServer/layers/0"));
myScene.OperationalLayers.Add(sceneLayer);

// create a new elevation source and add to scene
ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(new Uri("http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"));

myScene.BaseSurface.ElevationSources.Add(elevationSource);

// create a camera and set the initial viewpoint

MapPoint mapPoint = new MapPoint(-4.49779155626782, 48.38282454039932, 62.013264927081764, SpatialReferences.Wgs84);

Camera camera = new Camera(mapPoint, 41.64729875588979, 71.2017391571523, 2.194677223e-314);

Viewpoint initViewpoint = new Viewpoint(mapPoint, camera);

myScene.InitialViewpoint = initViewpoint;

MySceneView.Scene = myScene;

}
}SceneLayer

I noticed sometime it takes time to load the the 3D Scene. Hope that helps. Thanks

Nagma

ManelKEDDAR
New Contributor III

Thanks that helped me 

0 Kudos
dotMorten_esri
Esri Frequent Contributor

'SpatialReference.Wgs84' should probably be 'SpatialReferences.Wgs84' (the extra 's' is missing)

ManelKEDDAR
New Contributor III

Thanks didn't notice that 

0 Kudos