Adding the 3D content

Now that we have a virtual globe, it would be great to add some content so that we can make the globe useful. Let's add data from one of the more popular formats, called KML:

  1. In the same app, add the following code to the MainViewModel class after the USA layer:
    Uri kml = new Uri("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week_age_link.kml");
    KmlLayer kmlLayer = new KmlLayer(kml);
    kmlLayer.ID = "Earthquakes";
    kmlLayer.InitializeAsync();
    this.sceneView.Scene.Layers.Add(kmlLayer);
  2. Run the app, and you should see recent earthquakes around the world along with a legend.

Now that we've added a KML layer, let's add a simple graphic to the map too:

  1. Add using statements to Esri.ArcGISRuntime.Symbology.SceneSymbology and Windows.Media.Colors in the MainViewModel.cs file. Add the following code to a method in your ViewModel class, and then call the method from the anonymous messenger code:
    private void DrawSphere()
    {
        // create a new point (MapPoint); pass x, y, and z coordinates in    
        // the constructor
        var point = new MapPoint(-122.4167, 37.7833,  6000);
    
        // create a graphics layer
        GraphicsLayer graphicsLayer = new GraphicsLayer();
        graphicsLayer.ID = "Graphics Layer";
        graphicsLayer.SceneProperties.SurfacePlacement =
            SurfacePlacement.Absolute;
        graphicsLayer.InitializeAsync();
    
        // creates a red sphere with a radius of 20,000 meters
        var sphereSym = new SphereMarkerSymbol();
        sphereSym.Color = Colors.Red;
        sphereSym.Radius = 20000;
    
        // create the graphic
        var graphic = new Graphic(point, sphereSym);
        graphicsLayer.Graphics.Add(graphic);
    
        // add the graphics layers to the scene
        this.sceneView.Scene.Layers.Add(graphicsLayer);
    }
  2. Next, let's add a 3D model and place it above the sphere we just added. Add this method:
    private void DrawModel()
    {
        ModelMarkerSymbol mms = new ModelMarkerSymbol();
        mms.SourceUri = "Data/M-14/M-14.obj";
        mms.Scale = 1000;
    
        SimpleRenderer sr = new SimpleRenderer();
        sr.Symbol = mms;
    
        GraphicsOverlay graphicsOverlay = new GraphicsOverlay()
        {
            RenderingMode = GraphicsRenderingMode.Dynamic,
            Renderer = sr,
            SceneProperties = new LayerSceneProperties()
            {
                SurfacePlacement = SurfacePlacement.Relative
             }
        };
    
        MapPoint mp = new MapPoint(-122.4167, 37.7833, 55000);
    
        Graphic gm = new Graphic(mp);
        graphicsOverlay.Graphics.Add(gm);
        this.sceneView.GraphicsOverlays.Add(graphicsOverlay);
    }
  3. Run the app and zoom over San Francisco. You will see the sphere and a futuristic jet, which will look like this:
    Adding the 3D content

In this last example, there was a lot of new code you haven't seen yet. This is a taste of the topics to come in the next chapter, but this shows you how to add basic content to the scene. In the first method, a point was created via MapPoint, a new GraphicsLayer was created, and SphereMarkerSymbol was created with the color of red and a radius of 20,000 meters.

Lastly, the graphic was created using the point geometry (MapPoint) and a symbol, and then the graphic was added to GraphicsLayer. Then, GraphicsLayer was added to the Scene. In the second method (DrawModel), ModelMarkerSymbol was created, its SourceUri property was set, SimpleRenderer was instantiated, and its symbol was set to ModelMarkerSymbol. Then, GraphicsOverlay was created with several properties, the geometry was set to be over San Francisco, the graphic was created with the geometry, the graphic was added to GraphicsOverlay, and finally, GraphicsOverlay was added to the GraphicsOverlay property of SceneView.

Although we created this with a simple method in ViewModel, it really should go into a class that allows you to reuse it in all of your projects. You could then have a service that your ViewModel class uses to call the DLL.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.123.189