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"
    />
    <!--
     ArcGIS API for JavaScript, https://js.arcgis.com
     For more information about the sceneview-hittest sample,
     read the original sample description at developers.arcgis.com.
     https://developers.arcgis.com/javascript/latest/sample-code/sceneview-hittest/index.html
     -->
    <title>SceneView - hitTest - 4.13</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #hitInfo {
        position: absolute;
        top: 12px;
        right: 12px;
        padding: 12px;
        background-color: rgba(0, 0, 0, 0.8);
        color: white;
      }
    </style>

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

    <script>
      require([
        "esri/WebScene",
        "esri/views/SceneView",
        "esri/Graphic"
      ], function(WebScene, SceneView, Graphic) {
        // Load webscene and display it in a SceneView
        const webscene = new WebScene({
          portalItem: {
            id: "9a542f6755274436985617a462ffdf44"
          }
        });

        // create the SceneView
        const view = new SceneView({
          container: "viewDiv",
          map: webscene,
          highlightOptions: {
            haloOpacity: 0
          }
        });

        // symbol for points on objects
        let objectPointSymbol = {
          type: "point-3d",
          symbolLayers: [
            {
              type: "icon", // autocasts as new IconSymbol3DLayer()
              size: 12, // points
              resource: { primitive: "circle" },
              material: { color: "#CA676F" },
              outline: {
                color: "#CA676F"
              }
            }
          ]
        };

        // symbol for first object hit point
        let firstObjectPointSymbol = {
          type: "point-3d",
          symbolLayers: [
            {
              type: "icon", // autocasts as new IconSymbol3DLayer()
              size: 12, // points
              resource: { primitive: "circle" },
              material: { color: "#51A5B2" },
              outline: {
                color: "#51A5B2"
              }
            }
          ]
        };

        // symbol for the ground point
        const groundPointSymbol = {
          type: "point-3d",
          symbolLayers: [
            {
              type: "icon", // autocasts as new IconSymbol3DLayer()
              size: 12, // points
              resource: { primitive: "circle" },
              material: { color: "#CA676F" },
              outline: {
                color: "#CA676F"
              }
            }
          ]
        };
        // line symbol which connects the points
        const visibleLineSymbol = {
          type: "line-3d", // autocasts as new LineSymbol3D()
          symbolLayers: [
            {
              type: "line", // autocasts as new LineSymbol3DLayer()
              material: {
                color: "#51A5B2"
              },
              size: 4
            }
          ]
        };

        const invisibleLineSymbol = {
          type: "line-3d", // autocasts as new LineSymbol3D()
          symbolLayers: [
            {
              type: "line", // autocasts as new LineSymbol3DLayer()
              material: {
                color: "#CA676F"
              },
              size: 4
            }
          ]
        };

        let highlightedList = [];
        const hitresultground = document.getElementById("hitresultground");
        const hitresultcount = document.getElementById("hitresultcount");

        view.on("immediate-click", function(event) {
          // get the returned hitTestResult
          // and draw points on all return mappoints and connect to a line
          // (using promise chaining for cleaner code and error handling)
          view
            .hitTest(event, { exclude: [view.graphics] })
            .then(function(hitTestResult) {
              // print the information to the panel
              hitresultground.textContent =
                Math.round(hitTestResult.ground.distance) + " m";
              hitresultcount.textContent = hitTestResult.results.length;

              let lastHit = null;
              if (hitTestResult.results.length > 0) {
                lastHit =
                  hitTestResult.results[hitTestResult.results.length - 1];
                // create point graphic for each hit on objects
                hitTestResult.results.forEach(function(result, index) {
                  const hitObject = new Graphic({
                    geometry: result.mapPoint,
                    symbol:
                      index === 0 ? firstObjectPointSymbol : objectPointSymbol
                  });
                  view.graphics.add(hitObject);

                  let graphic = result.graphic;
                  // change the layer to be transparent
                  graphic.layer.opacity = 0.8;
                  // highlight the hit object
                  view.whenLayerView(graphic.layer).then(function(layerView) {
                    highlightedList.push(layerView.highlight(graphic));
                  });
                });
              }

              if (hitTestResult.ground.mapPoint) {
                if (lastHit) {
                  if (hitTestResult.ground.distance > lastHit.distance) {
                    // an object under the ground could be more far away,
                    // check first the distance before set the ground as last point
                    lastHit = hitTestResult.ground;
                  }
                } else {
                  lastHit = hitTestResult.ground;
                }
                // create point graphic for the ground
                const hitGround = new Graphic({
                  geometry: hitTestResult.ground.mapPoint,
                  symbol: groundPointSymbol
                });
                view.graphics.add(hitGround);
              }

              if (hitTestResult.results.length > 0 && lastHit) {
                // Draw a line to connect all hit objects and ground
                let visibleLinePoints = [
                  [
                    view.camera.position.x,
                    view.camera.position.y,
                    view.camera.position.z
                  ],
                  [
                    hitTestResult.results[0].mapPoint.x,
                    hitTestResult.results[0].mapPoint.y,
                    hitTestResult.results[0].mapPoint.z
                  ]
                ];

                let invisibleLinePoints = [
                  [
                    hitTestResult.results[0].mapPoint.x,
                    hitTestResult.results[0].mapPoint.y,
                    hitTestResult.results[0].mapPoint.z
                  ],
                  [lastHit.mapPoint.x, lastHit.mapPoint.y, lastHit.mapPoint.z]
                ];

                view.graphics.addMany([
                  {
                    geometry: {
                      type: "polyline",
                      paths: visibleLinePoints,
                      spatialReference: view.spatialReference
                    },

                    symbol: visibleLineSymbol
                  },
                  {
                    geometry: {
                      type: "polyline",
                      paths: invisibleLinePoints,
                      spatialReference: view.spatialReference
                    },

                    symbol: invisibleLineSymbol
                  }
                ]);
              }
            })
            .catch(function(error) {
              console.error(error);
            });
        });
        document.getElementById("reset").addEventListener("click", function() {
          // remove all graphics
          view.graphics.removeAll();
          // remove the highlights
          highlightedList.forEach(function(highlightObject) {
            highlightObject.remove();
          });
          highlightedList = [];
          // disable the transparency
          view.map.layers.getItemAt(0).opacity = 1;
          // remove the result
          hitresultground.textContent = "0 m";
          hitresultcount.textContent = "-";
        });
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="hitInfo" class="esri-widget">
      <p>Click in the view and see the hit objects:</p>
      <table
        class="esri-widget"
        style="color: white; background-color: rgba(0, 0, 0, 0);"
      >
        <tr>
          <td>Ground hit distance:</td>
          <td id="hitresultground">0 m</td>
        </tr>
        <tr>
          <td>Objects hit:</td>
          <td id="hitresultcount">-</td>
        </tr>
      </table>

      <br />
      <button id="reset" class="esri-button">
        Reset
      </button>
    </div>
  </body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console