Example 3: Creating a Tool that Loads a Mesh Layer, Flies to It, and Creates a Viewshed in that Location

 

This example uses the TE4W API to create a mesh layer (using mesh.create), then fly to it (using Cesium API) and then create a viewshed in that location (using viewshed.create).  

var MyViewshedTool = function() {

 

    //SET TOOL ID   

    this.getId = function() {

        return "MyViewshedTool";

    },

 

        //SET MENU ENTRY FOR THE TOOL (See example 1 for more details)

        this.getMenuEntry = function() {

            return TerraExplorer.tools.MenuEntry.addToSidebar(this, "My Viewshed Tool", "./userTools/myToolIcon.png", 3, TerraExplorer.tools.MenuEntry.MenuEntryAnalysis(), "My Tools");

        },

 

        //SET CODE TO EXECUTE WHEN TOOL IS CLICKED IN SIDEBAR

        this.open = function() {

                                         //CREATE A MESH LAYER USING THE layers.mesh.create METHOD

                                         Cesium.when(TerraExplorer.layers.mesh.create("Frederick", "https://www.SkylineGlobe.com/SG/streamer.ashx", "Frederick_4TEDF", true),

                                         function(teObject){

                                                        //PRINT DESCRIPTION OF ADDED LAYER

                                                        console.log("Created Mesh layer: " + teObject.description);

                                                        //FLY TO Frederick USING THE TerraExplorerObject.flyTo METHOD

                                                        teObject.flyTo();

                                                        //CREATE a TEPosition USING THE position.create METHOD AND VIEWSHED OBJECT USING THE viewshed.create METHOD

                                                        var pos = TerraExplorer.navigate.position.create({cartesian: Cesium.Cartesian3.fromDegrees(-77.41069, 39.41455, 300), headingPitchRange: new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-45), 2000), altitudeType: TerraExplorer.AltitudeMethod.RELATIVE_TO_MODEL});

                                                        TerraExplorer.analysis.viewshed.create("Viewshed on Current View",pos.cartesian, 53, 53, pos.headingPitchRange, {});

                                                       

                          });

           }

};