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 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


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.


  <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>
    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;
          // Get the featureLayer graphic
          if (response.results.length) {
            graphic = response.results.filter(function (result) {
              return (result.graphic.layer === featureLayer);
          // 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) {;
        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>