Add features and graphics to a scene view

Add features to a scene view when you want to:

  • Display data with a common attribute schema (for example, census data)
  • Display geographical data of a common geometry type (point, line, or polygon)
  • Persist or store the data beyond the current app session

Add graphics to a scene view when:

  • You want to display temporary data, such as fast-changing, fast-moving data (for example, a fleet of airliners, or voluminous data.
  • You want to display data that doesn't share a common geometry type (such as point, line, or polygon) and doesn't share a common set of attribute fields
  • The data is required only for the current app session

Both features and graphics can be:

The way you add features and graphics to scenes follows the same steps required to add them to maps, with these additional considerations:

Add features to a scene view

Feature layers can contain any number of features of a single geometry type (point, polyline or polygon). Adding features to a scenes is the same as adding features to a map:

  1. Add features to a feature layer
  2. If you want to include features' attributes (to run queries, for example), make sure to use QueryFeatureFields.LoadAll if building your feature layer from a service feature table
  3. Add the feature layer to the scene's operational layers

Add graphics to a scene view

Adding graphics to scenes is the same as adding graphics to maps:

  1. Add graphics to a graphics overlay
  2. Set the graphic overlays surface placement, if you prefer a surface placement other than the default SurfacePlacement.Draped
  3. Add the graphics overlay to the scene view's graphic overlays
Note:

Any graphic you add to a scene view must be constructed from a geometry with a spatial reference.

In 3D, you can add graphics such as points, polylines, polygons, and 3D marker symbols, all into the same graphics overlay or into multiple graphics overlays.

For additional details on adding graphic overlays to a map or scene, see Add graphic overlays to your app. For details on adding graphics to a graphics overlay, see Add graphics and text to graphics overlays.

var sceneGraphicsOverlay = new GraphicsOverlay();
// ... set graphics overlay properties ...
MySceneView.GraphicsOverlays.Add(sceneGraphicsOverlay);

Surface placement modes

For both feature layers and graphics overlays, you can specify a surface placement mode or use the default mode of DRAPED. These modes control how the z-value of your geometry is used when features and graphics are drawn.

  • SurfacePlacement.Draped—(default) Features and graphics are drawn on the surface. The z-value has no effect.
  • SurfacePlacement.Absolute—Features and graphics are drawn at a height using the z-value referenced from above the globe skin (sea level).
  • SurfacePlacement.Relative—Features and graphics are drawn at a height using the z-value referenced from above the surface layer.

The following code shows three points drawn in graphics overlays in the three different surface placement modes. The red graphic is draped on the surface, the blue graphic is drawn in absolute mode, and the green in relative mode

// create and add a new graphics overlay with Draped surface placement
var drapedOverlay = new GraphicsOverlay();
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 three marker symbols (red, green, and blue circles)
var redCircleSym = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 10);
var greenCircleSym = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Green, 10);
var blueCircleSym = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Blue, 10);


// create a map point to display
var location = new MapPoint(-4.04, 53.06, 1000, SpatialReferences.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);

Graphics rendered at different heights, despite all having the same z-value.

Graphics drawn with different surface placement options

Renderers: Controlling symbology with attributes

Just as in 2D, both feature layers and graphic overlays can use various renderers, such as simple renderers and unique value renderers, to control symbology with attributes. For details, see Symbols and renderers.

When using renderers in 3D, you can set properties to define extrusion expressions for both features and graphics. However, only graphics can have rotation expressions.

To apply extrusion to a feature layer:

  1. Set the feature layer to rendering in DYNAMIC mode
  2. Define a renderer which will be used to render the feature layer
  3. Set the renderer's scene property extrusion mode
  4. Set the renderer's scene property extrusion expression
  5. Set the renderer to the feature layer
  6. Add the feature layer to the scene

Extrusion can also be applied to graphics overlays:

  1. Define a renderer which will be used to render the graphics overlay
  2. Set the renderer's scene property extrusion mode
  3. Set the renderer's scene property extrusion expression
  4. Set the renderer to the graphics overlay

// create a simple renderer that uses a (polygon) fill symbol
var lineSym = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Black, 1);
var fillSym = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Green, lineSym);
var rendrr = new SimpleRenderer(fillSym);


// set the rendering mode (absolute) and the expression (population attribute name)
rendrr.SceneProperties.ExtrusionMode = ExtrusionMode.AbsoluteHeight;
rendrr.SceneProperties.ExtrusionExpression = "pop2000";


// apply the renderer to the first graphics overlay in the scene view
MySceneView.GraphicsOverlays[0].Renderer = rendrr;

In the image below, a graphic overlay is being extruded based on a population attribute: pop2000.

County polygons extruded on population

Only graphics overlays can have rotation expressions--used to change the heading, pitch and roll of the graphics in the graphics overlay. To set rotation expressions:

  1. Define a renderer which will be used to render the graphics overlay
  2. Set the rotation type
  3. Set the renderer's scene property heading expression
  4. Set the renderer's scene property pitch expression
  5. Set the renderer's scene property roll expression
  6. Set the renderer to the graphics overlay

// create a simple renderer that uses a (3D) cone symbol
var rendrr = new SimpleRenderer(coneSymbol);
// set expressions (attribute names) to define heading, pitch, and roll for each graphic
rendrr.SceneProperties.HeadingExpression = "heading";
rendrr.SceneProperties.PitchExpression = "pitch";
rendrr.SceneProperties.RollExpression = "roll";

3D-specific symbols for graphics

Graphics in a 3D graphics overlay can use any of the symbols discussed in Add graphics and text to graphics overlays. You can also add:

3D symbols

Add shape-based symbols

3D shapes, such as a cone, floating on the earth's surface.

The following code snippet shows how to create a sphere symbol and render it using a point geometry in a graphic.

// create a red sphere symbol
var sphereSymbol = new SimpleMarkerSceneSymbol
{
    Style = SimpleMarkerSceneSymbolStyle.Sphere,
    Color = Color.Red,
    Height = 3000,
    Width = 3000,
    Depth = 3000,
    AnchorPosition = SceneSymbolAnchorPosition.Center
};


// create a graphic using a map location (point) and the sphere symbol
var location = new MapPoint(-4.04, 53.16, 1000, SpatialReferences.Wgs84);
var sphereGraphic = new Graphic(location, sphereSymbol);


// add the graphic to the first graphics overlay in the scene view
MySceneView.GraphicsOverlays[0].Graphics.Add(sphereGraphic);

Add model symbols

A model symbol provides a realistic three-dimensional visualization to symbolize scene features. These models define the geometry and surface textures of real-world items such as aircraft. Create a ModelSceneSymbol using a 3D model file, passing the path to the file and a scale factor to the model symbol constructor. The supported model file types include Collada (.dae), 3D Max (.3ds), Blender 3d (.blend), and the formats listed in the Open Asset Import Library (Assimp). Depending on the model file's default orientation, you may have to rotate the symbol to get your model in the desired orientation.

Note:

Model scene symbols cannot be used with a static graphics rendering mode.

Model symbol representing a helicopter

Create these model symbols using the ModelSceneSymbol class.

// call the static CreateAsync method to create a new ModelMarkerSymbol, pass a uri for the model and a scale
var modelSymbol = await ModelSceneSymbol.CreateAsync(modelSourceUri, 300.0);


// create a graphic using a map location (point) and the model symbol
var location = new MapPoint(-4.04, 53.16, 2000, SpatialReferences.Wgs84);
var modelGraphic = new Graphic(location, modelSymbol);


// add the graphic to the first graphics overlay in the scene view
MySceneView.GraphicsOverlays[0].Graphics.Add(modelGraphic);

Distance composite symbols

While model symbols closely resemble the real-world object they represent when viewed close up, when you zoom away from them, the symbols gets smaller until they're no longer visible. If you want to see the location of your graphics at any distance from the camera, use distance composite symbols. These symbols allow you to use different symbols depending on the distance the graphic is from the camera.

The code snippet below the following images shows how to set up a distance composite symbol similar to the one shown in the images.

When the camera is far away from the point, a red simple marker symbol displays.

A simple point is displayed when the camera is far away

As you zoom closer to the point, the symbol renders as a cone pointing in the aircraft's direction of travel.

A cone symbol shows heading at intermediate camera distance

When viewed even closer, the point displays as a model symbol, which is appropriate at this distance from the camera.

A model symbol displays at the nearest camera distance

// create a new DistanceCompositeSceneSymbol to hold a collection of range-specific symbols
var compositeSymbol = new DistanceCompositeSceneSymbol();


// ... code here to create new ModelMarkerSymbol, ConeMarkerSymbol, and SimpleMarkerSymbol ...


// use a model symbol when the camera is within 5,000 meters
var nearSymbolInfo = new DistanceSymbolRange(modelSymbol, 0, 5000);
compositeSymbol.Ranges.Add(nearSymbolInfo);


// use a cone marker symbol for intermediate distances (5,000 to 50,000 meters)
var midSymbolInfo = new DistanceSymbolRange(coneSymbol, 5000, 50000);
compositeSymbol.Ranges.Add(midSymbolInfo);


// use a simple marker symbol for large distances (> 50,000 meters)
var farSymbolInfo = new DistanceSymbolRange(markerSymbol, 50000, 0);
compositeSymbol.Ranges.Add(farSymbolInfo);


// create a new graphic using the DistanceCompositeSceneSymbol
var location = new MapPoint(-4.04, 53.16, 2000, SpatialReferences.Wgs84);
var distanceCompositeGraphic = new Graphic(location, compositeSymbol);


// add the graphic to the first graphics overlay in the scene view
MySceneView.GraphicsOverlays[0].Graphics.Add(distanceCompositeGraphic);

Related topics