Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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>Add Graphics to a SceneView | Sample | ArcGIS API for JavaScript 4.21</title>

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

  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <script>
    require([
      "esri/core/watchUtils",
      "esri/core/promiseUtils",
      "esri/Map",
      "esri/views/SceneView",      
      "esri/layers/FeatureLayer",
      "esri/Graphic",
      "esri/geometry/Point",
      "esri/geometry/Polyline",
      "esri/geometry/Mesh",
      "esri/geometry/support/meshUtils",
      "esri/geometry/geometryEngine"
    ], (watchUtils, promiseUtils, EsriMap, SceneView, FeatureLayer, Graphic, Point, Polyline, Mesh, meshUtils, geometryEngine) => {
      
      const view = new SceneView({
        container: "viewDiv",
        map: new EsriMap({
          basemap: "hybrid",
          ground: "world-elevation"
        }),
        viewpoint: {
          rotation: 287.9444860480998,
          scale: 26507.626205500943,
          targetGeometry: {
            type: 'point',
            spatialReference: {
              wkid: 102100
            },
            x: -12656148.28708868,
            y: 4271010.800576917,
            z: 823.0197749277577
          },
          camera: {
            position: {
              type: 'point',
              spatialReference: {
                wkid: 102100
              },
              x: -12661105.905233372,
              y: 4269406.526120242,
              z: 3761.1432871511206
            },
            heading: 72.05551395190018,
            tilt: 55.19041234149143
          }
        }
      });
      view.when(() => {                
        view.popup.defaultPopupTemplateEnabled = true;                        
        initializeGraphics();        
      });
      
      const initializeGraphics = (elevationLayer) => {
        
        const viewSR = view.spatialReference;
        
        // WALL GRAPHIC //
        const wallMeshGraphic = new Graphic({          
          attributes: { 'ObjectID': 1, 'wallHeight': 1.0 }
        });
        // WALL LAYER //
        const wallMeshLayer = new FeatureLayer({
          title: 'Mesh Wall',
          popupEnabled: true,
          geometryType: "mesh",
          spatialReference: viewSR,
          objectIdField: "ObjectID",
          fields: [
            { name: "ObjectID", alias: "ObjectID", type: "oid" },
            { name: "wallHeight", alias: "Wall Height", type: "double" }
          ],                 
          source: [wallMeshGraphic],
          renderer: {
            type: 'simple',
            symbol:{
              type: "mesh-3d",
              symbolLayers: [
                {
                  type: "fill",
                  material: {color: "red"},
                  edges: {type: "solid", color: 'yellow', size: 2.5 }
                }
              ]
            }            
          }          
        });
        view.map.add(wallMeshLayer);
        
        const startPoint = new Point({
          spatialReference: viewSR,
          x: -12657698.041564343,
          y: 4271708.99767823,
          z: 1364.260375522043
        });
        const endPoint = new Point({
          spatialReference: viewSR,
          x: -12657308.077876419,          
          y: 4229294.715132089,
          z: 1438.0513646899717
        });                
        
        // LINE BETWEEN START AND END LOCATIONS //
        const polyline2D = new Polyline({
          spatialReference: viewSR,
          paths: [
            [startPoint.x, startPoint.y],
            [endPoint.x, endPoint.y]
          ]
        });                        
        
        // BUFFER AROUND LINE //
        let buffer2D = geometryEngine.geodesicBuffer(polyline2D, 5.0, "meters");
        
        // DENSIFY //
        const pointCount = 500;        
        const distanceMeters = geometryEngine.geodesicLength(polyline2D);        
        const distanceAlongMeters = Math.max(25.0, distanceMeters / pointCount);                
        const denseBuffer2D = geometryEngine.geodesicDensify(buffer2D, distanceAlongMeters);
        
        // BUFFER BOUNDARY //
        const boundary2D = new Polyline({spatialReference: viewSR, paths: denseBuffer2D.rings });                              
        // WALL MAX Z //        
        const staticMazZ = 2100.0;
                                
        const updateGraphic = promiseUtils.debounce(() => {        

          // BUFFER BOUNDARY ALONG GROUND //
          const boundary3D = view.groundView.elevationSampler.queryElevation(boundary2D);            

          // Z INFOS //
          const allZ = boundary3D.paths[0].map(c=>c[2]);        
          const minZ = Math.min(...allZ);          
          const wallHeight = (staticMazZ - minZ);          
          
          // BUFFER AT MAX Z //
          const buffer3D = denseBuffer2D.clone();
          buffer3D.hasZ = true;
          buffer3D.rings[0].forEach(coords=>{
            coords.push(staticMazZ);
          });        

          // TOP AND BOTTOM COORDINATES //
          const coordsTop = buffer3D.rings[0];
          const coordsBoottom = boundary3D.paths[0];
          // INTERLEAVED SIDE WALL COORDINATES //
          const positions = [];
          for(let topIdx = 0; topIdx < (coordsTop.length -1); topIdx++){          
            positions.push(coordsTop[topIdx], coordsTop[topIdx+1], coordsBoottom[topIdx+1]);
            positions.push(coordsTop[topIdx], coordsBoottom[topIdx+1], coordsBoottom[topIdx]);
          }

          // WALL TOP //
          const wallMeshTop = Mesh.createFromPolygon(buffer3D);
          // WALL SIDES //
          const wallMeshSides = new Mesh({            
            spatialReference: viewSR,
            vertexAttributes: {
              position: positions.flat()
            }        
          });            

          wallMeshGraphic.setAttribute('wallHeight', wallHeight);
          wallMeshGraphic.geometry = meshUtils.merge([wallMeshTop, wallMeshSides]);

          return wallMeshLayer.applyEdits({ updateFeatures: [wallMeshGraphic] }).then((updateResults)=>{
            const updateFeatureResult = updateResults.updateFeatureResults[0];
            updateFeatureResult.error && console.warn(updateFeatureResult);              
            //console.info(`Mesh Graphic has been updated... ${Date.now()}`);
          })            
        });         
        
        // ABORT ERROR //
        const handleAbortError = error => { if(error.name !== 'AbortError'){ console.error(error); } };

        // UPDATE THE WALL WHENEVER THE DYNAMIC GROUND VIEW CHANGES //
        view.groundView.elevationSampler.on("changed", (evt) => {
          //console.info(`GroundView ElevationSampler has changed: ${Date.now()}`);
          updateGraphic().catch(handleAbortError);
        });                    
       
      };
    });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console