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 lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Access features with pointer events | Sample | ArcGIS Maps SDK for JavaScript 4.27</title>

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

      #info {
        background-color: black;
        opacity: 0.75;
        color: orange;
        font-size: 18pt;
        padding: 8px;
        visibility: hidden;
      }
    </style>

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

    <script>
      require(["esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/geometry/SpatialReference"
              ,"esri/Graphic", "esri/geometry/Polyline", "esri/core/promiseUtils"],
      (Map, MapView, FeatureLayer, SpatialReference, Graphic, Polyline, promiseUtils) => {
        
        const feature = new Graphic({
            geometry: new Polyline({
              paths: [
                [
                  [-9195403.730899999, 4140909.2590000033],
                  [-9195405.8717, 4140858.9967000037],
                  [-9195331.1022, 4140815.3533999994],
                  [-9195408.0125, 4140808.7343000025],
                ],
              ],
              spatialReference: new SpatialReference({
                wkid: 3857,
              }),
            }),
            attributes: {
              OBJECTID: 1,
              CAT: "One",
              WIND_KTS: 5,
              NAME: "Name",
              YEAR: 1990
            },
          });        
        
        const hurricanesLayer = new FeatureLayer({
          source: [feature],
          objectIdField: "OBJECTID",
          fields: [{
              name: "OBJECTID",
              type: "oid"
            },{
              name: "CAT",
              type: "string"
            },{
              name: "WIND_KTS",
              type: "integer"
            },{
              name: "NAME",
              type: "string"
            },{
              name: "YEAR",
              type: "integer"
          }],
          outFields: ["*"]
        });

        const map = new Map({
          basemap: "dark-gray-vector",
          layers: [hurricanesLayer]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-82.6, 34.83],
          zoom: 15,
          highlightOptions: {
            color: "orange"
          }
        });
        

        view.ui.add("info", "top-right");

        view
          .when()
          .then(() => {
            return hurricanesLayer.when();
          })
          .then((layer) => {
            const renderer = layer.renderer.clone();
            renderer.symbol.width = 2;
            renderer.symbol.color = [0, 102, 255];
            layer.renderer = renderer;

            // Set up an event handler for pointer-down (mobile)
            // and pointer-move events (mouse)
            // and retrieve the screen x, y coordinates

            return view.whenLayerView(layer);
          })
          .then((layerView) => {
            view.on("pointer-move", eventHandler);
            view.on("pointer-down", eventHandler);

            function eventHandler(event) {
             debouncedUpdate(event).catch((err) => {
                if (!promiseUtils.isAbortError(err)) {
                  throw err;
                }
              });
            }
          
            const debouncedUpdate = promiseUtils.debounce(async (event) => {
              // Perform a hitTest on the View
              const opts = {
                include: hurricanesLayer
              }
              const response = await view.hitTest(event, opts);
              if (response.results.length) {
                const graphic = response.results[0].graphic;

                const attributes = graphic.attributes;
                const category = attributes.CAT;
                const wind = attributes.WIND_KTS;
                const name = attributes.NAME;
                const year = attributes.YEAR;
                const id = attributes.OBJECTID;
                console.log(graphic.attributes)

                if (
                  highlight &&
                  (currentName !== name || currentYear !== year)
                ) {
                  highlight.remove();
                  highlight = null;
                  return;
                }

                if (highlight) {
                  return;
                }

                document.getElementById("info").style.visibility = "visible";
                document.getElementById("name").innerHTML = name;
                document.getElementById("category").innerHTML =
                  "Category " + category;
                document.getElementById("wind").innerHTML = wind + " kts";

                // highlight all features belonging to the same hurricane as the feature
                // returned from the hitTest
                const query = layerView.createQuery();
                query.where = "YEAR = " + year + " AND NAME = '" + name + "'";
                layerView.queryObjectIds(query).then((ids) => {
                  if (highlight) {
                    highlight.remove()
                  }
                  highlight = layerView.highlight(ids);
                  currentYear = year;
                  currentName = name;
                });
              } else {
                // remove the highlight if no features are
                // returned from the hitTest
                if (highlight){
                  highlight.remove();
                  highlight = null;
                }
                document.getElementById("info").style.visibility = "hidden";
              }

            });
            // Listen for the pointer-move event on the View
            view.on("pointer-move", (event) => {
              debouncedUpdate(event).catch((err) => {
                if (!promiseUtils.isAbortError(err)) {
                  throw err;
                }
              });
            });
          
          
          
          
          

            let highlight, currentYear, currentName;
          });
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="info">
      <span id="name"></span> <br />
      <span id="category"></span> <br />
      <span id="wind"></span>
    </div>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console