Pen Settings



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


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


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.


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.


  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>ArcGIS API for JavaScript Tutorials: Buffer and intersect geometry</title>
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
  <link rel="stylesheet" href="">
  <script src=""></script>
    ], 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: ""


      var activeGraphic;
      var bufferGraphic;
      var textGraphic;
      var lineGraphic;
      function findNearestGraphic(event) {
        return view.hitTest(event).then(function (response) {
          var graphic, filteredResult;
          // Get the featureLayer graphic
          if (response.results.length) {
            filteredResult = response.results.filter(function (result) {
              return (result.graphic.layer === featureLayer);
          // Only return new graphics found
          if (filteredResult) {
            graphic = filteredResult.graphic;
            if (!activeGraphic ||  (activeGraphic.attributes.OBJECTID !== graphic.attributes.OBJECTID)) {
              return graphic;
            } else {
              return null;
          } else {
            return null;
      function drawBuffer(bufferGeometry) {;
        bufferGraphic = new Graphic({
          geometry: bufferGeometry,
          symbol: {
            type: "simple-fill",
            color: "rgba(0,0,0,.15)",
            outline: {
              color: "rgba(0,0,0,.5)",
              width: 1
      function drawLine(point, point2) {;
        lineGraphic = new Graphic({
          geometry: {
            type: "polyline",
            paths: [
              [point.longitude, point.latitude],
              [point2.longitude, point2.latitude]
          symbol: {
            type: "simple-line",
            color: "#333",
            width: 1
      function drawText(point, distance) {;
        textGraphic = new Graphic({
          geometry: point,
          symbol: {
            type: "text",
            text: distance.toFixed(2) + " miles",
            color: "black",
            font: {
              size: 12
            haloColor: "white",
            haloSize: 1
      // Mouse events
      view.on("pointer-move", function(event){
        // Get the graphic closest to the mouse pointer and buffer it     
          if (graphic) {
            activeGraphic = graphic;
            // Buffer geometry and draw polygon
            var buffer = geometryEngine.geodesicBuffer(activeGraphic.geometry, .25, "miles");
        // 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);            
<div id="viewDiv"></div>