Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Geoprocessing - viewshed analysis | Sample | ArcGIS API for JavaScript 4.18</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #paneDiv {
        position: absolute;
        top: 18px;
        right: 18px;
        padding: 12px;
        background-color: rgba(0, 0, 0, 0.5);
        color: white;
        width: 200px;
      }
    </style>

    <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.19/"></script>

    <script>
      require([
        "esri/Map",
        "esri/views/SceneView",
        "esri/layers/GraphicsLayer",
        "esri/Graphic",
        "esri/geometry/Point",
        "esri/tasks/Geoprocessor",
        "esri/tasks/support/LinearUnit",
        "esri/tasks/support/FeatureSet"
      ], function(Map, SceneView, GraphicsLayer, Graphic, Point, Geoprocessor, LinearUnit, FeatureSet) {
        var gpUrl = "https://elevation.arcgis.com/arcgis/rest/services/Tools/Elevation/GPServer/Viewshed";

        var map = new Map({
          basemap: "hybrid",
          ground: "world-elevation"
        });

        var view = new SceneView({
          container: "viewDiv",
          map: map,
          camera: {
            // autocasts as new Camera()
            position: [7.59564, 46.06595, 5184],
            tilt: 70
          }
        });

        var graphicsLayer = new GraphicsLayer();
        map.add(graphicsLayer);

        var markerSymbol = {
          type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
          color: [255, 0, 0],
          outline: {
            // autocasts as new SimpleLineSymbol()
            color: [255, 255, 255],
            width: 2
          }
        };

        var fillSymbol = {
          type: "simple-fill", // autocasts as new SimpleFillSymbol()
          color: [226, 119, 40, 0.75],
          outline: {
            // autocasts as new SimpleLineSymbol()
            color: [255, 255, 255],
            width: 1
          }
        };

        var gp = new Geoprocessor(gpUrl);
        gp.outSpatialReference = {
          // autocasts as new SpatialReference()
          wkid: 102100
        };
        view.on("click", computeViewshed);

        function computeViewshed(event) {
          graphicsLayer.removeAll();

          var point = new Point({            
            longitude: event.mapPoint.longitude,
            latitude: event.mapPoint.latitude
          });

          var inputGraphic = new Graphic({
            geometry: point,            
            symbol: markerSymbol
          });

          graphicsLayer.add(inputGraphic);
          
          var featureSet = new FeatureSet({
            features: [inputGraphic]
          });          
          
          var params = {
            InputPoints: featureSet,
            MaximumDistance: 5.0,
            MaximumDistanceUnits: 'Kilometers',
            ObserverHeight: 15.0,
            ObserverHeightUnits:'Meters'
          };
          
          // SUBMIT JOB //
          //console.info('Job Params: ', params);          
          gp.submitJob(params).then((jobSubmitInfo)=>{   
            // JOB ID //
            const jobId = jobSubmitInfo.jobId;
            console.info('Submit Job: ', jobId);            
            gp.waitForJobCompletion(jobId).then((jobCompletedInfo)=>{
              console.info('Job Completed: ', jobCompletedInfo.jobStatus);            
              gp.getResultData(jobId,'OutputViewshed').then(({value})=>{                                              drawResultData(value);
              });
            });            
          });
        }

        function drawResultData(value) {
          var resultFeatures = value.features;

          // Assign each resulting graphic a symbol
          var viewshedGraphics = resultFeatures.map(function(feature) {
            feature.symbol = fillSymbol;
            return feature;
          });

          // Add the resulting graphics to the graphics layer
          graphicsLayer.addMany(viewshedGraphics);
         
          view.goTo({
            target: viewshedGraphics,
            tilt: 0
          })
          .catch(function(error) {
            if (error.name != "AbortError") {
              console.error(error);
            }
          });
        }
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="paneDiv" class="esri-widget">Click on map to execute ViewShed GP Task</div>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console