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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>ArcGIS JavaScript Tutorials: Buffer and intersect geometry</title>
  <style>
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>
  
  <link rel="stylesheet" href="https://js.arcgis.com/4.14/esri/themes/light/main.css">
  <script src="https://js.arcgis.com/4.14"></script>
  
  <script>  
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer",
      "esri/Graphic",
      "esri/geometry/geometryEngine"
    ], function(Map, MapView, FeatureLayer, Graphic, geometryEngine) {

      var map = new Map({
        basemap: "topo-vector"
      });
      
      var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-118.80543,34.02700],
        zoom: 13
      });

      // Trails (lines)
      var featureLayer = new FeatureLayer({
        url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails_Styled/FeatureServer/0"
      });

      map.add(featureLayer);

      var activeGraphic;
      var bufferGraphic;
      var textGraphic;
      var lineGraphic;
      
      function findNearestGraphic(event) {
        return view.hitTest(event).then(function (response) {
          var graphic;
          // Get the featureLayer graphic
          if (response.results.length) {
            graphic = response.results.filter(function (result) {
              return (result.graphic.layer === featureLayer);
            })[0].graphic; 
          }
          // Only return new graphics found
          if (graphic) {
            if (!activeGraphic ||  (activeGraphic.attributes.OBJECTID !== graphic.attributes.OBJECTID)) {
              return graphic;
            } else {
              return null;
            } 
          } else {
            return null;
          }
        });
      }
      
      function drawBuffer(bufferGeometry) {
        view.graphics.remove(bufferGraphic);
        bufferGraphic = new Graphic({
          geometry: bufferGeometry,
          symbol: {
            type: "simple-fill",
            color: "rgba(0,0,0,.15)",
            outline: {
              color: "rgba(0,0,0,.5)",
              width: 1
            }
          }
        });
        view.graphics.add(bufferGraphic);
      }
      
      function drawLine(point, point2) {
        view.graphics.remove(lineGraphic);
        lineGraphic = new Graphic({
          geometry: {
            type: "polyline",
            paths: [
              [point.longitude, point.latitude],
              [point2.longitude, point2.latitude]
            ]
          },
          symbol: {
            type: "simple-line",
            color: "#333",
            width: 1
          }
        });
        view.graphics.add(lineGraphic);
      }
      
      function drawText(point, distance) {
        view.graphics.remove(textGraphic);
        textGraphic = new Graphic({
          geometry: point,
          symbol: {
            type: "text",
            text: distance.toFixed(2) + " miles",
            color: "black",
            font: {
              size: 12
            },
            haloColor: "white",
            haloSize: 1
          }
        })
        view.graphics.add(textGraphic)
      }
      
      // Mouse events
      
      view.on("pointer-move", function(event){
        // Get the graphic closest to the mouse pointer and buffer it     
        findNearestGraphic(event).then(function(graphic){
          if (graphic) {
            activeGraphic = graphic;
            // Buffer geometry and draw polygon
            var buffer = geometryEngine.geodesicBuffer(activeGraphic.geometry, .25, "miles");
            drawBuffer(buffer);
          }
        });
        // Perform intersect and distance calculations
        if (bufferGraphic) {
          // Change the color if the pointer intersects the buffer
          var cursorPoint = view.toMap(event);
          var intersects = geometryEngine.intersects(bufferGraphic.geometry, cursorPoint);
          var symbol = bufferGraphic.symbol.clone();
          if (intersects) {
            symbol.color = "rgba(0,0,0,.15)";
          } else {
            symbol.color = "rgba(0,0,0,0)";
          }
          bufferGraphic.symbol = symbol;
          // Get the closest vertex (point) in the buffer to the mouse location and draw a line
          var vertexResult = geometryEngine.nearestVertex(bufferGraphic.geometry, cursorPoint);
          var closestPoint = vertexResult.coordinate;
          drawLine(cursorPoint, closestPoint)
          // Get the distance and draw a text label
          var distance = geometryEngine.geodesicLength(lineGraphic.geometry, "miles");
          drawText(cursorPoint, distance);            
        }      
      });
            
            
    });
  </script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
            
          
!

CSS

            
              
            
          
!

JS

            
              
            
          
!
999px

Console