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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

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


                <!DOCTYPE html>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Points to CSV</title>

    <link rel="stylesheet" href="" />
    <script src=""></script>
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    #sampleInstructions {
        padding: 10px;
        background-color: white;
        width: 300px;

    ], function (Map, MapView, Graphic, GraphicsLayer, FeatureLayer, Draw, Expand) {
      const map = new Map({
        basemap: "gray"
      const view = new MapView({
        container: "viewDiv",
        map: map,
        zoom: 5,
        center: [-99, 37]
      // county layer
      const countiesLayer = new FeatureLayer({
        url: "",
        outFields: "*",
        visible: false
      // add layer
      // create a new instance of draw
      const draw = new Draw({
        view: view

      // draw point button
      view.ui.add("draw-point", "top-right");
      document.getElementById("draw-point").addEventListener("click", () => { 
        var action = draw.create("point");
        action.on("draw-complete", function (evt) {
      // crete point graphic and add to map
      function createPointGraphic(coordinates) {
        var point = {
          type: "point", // autocasts as Point
          x: coordinates[0],
          y: coordinates[1],
          spatialReference: view.spatialReference
        var graphic = new Graphic({
          geometry: point,
          symbol: {
            type: "simple-marker", // autocasts as SimpleMarkerSymbol
            style: "x",
            //color: "red",
            size: "10px",
            outline: { // autocasts as SimpleLineSymbol
              color: 'red',
              width: 4
       // erase button
      view.ui.add("erase", "top-right");
      document.getElementById("erase").addEventListener("click", () => {                 ; // reset graphics
      // init csv header
      let csv = 'lat,lon,county,state,pop\n';
      /* When clicking the save button,
       * for each graphic (drawn point)
       * perform a spatial query on the county layer
       * on the last graphic download the csv
      view.ui.add("download", "top-right");
      document.getElementById("download").addEventListener("click", () => {
        const gras =; // sketch points
        gras.forEach((gra, i) => {
          if (gras.length == (i+1)) {  // if last point
            queryCounties(gra.geometry, true);  // download the csv once done
          else {
            queryCounties(gra.geometry);  // add point to csv with fields from county
       * @param {Geometry} g: a graphic geometry
       * @param {bool} d: true if last graphic
       * @return: A spatial query promise that adds to the csv string
      function queryCounties(g, d = false) {
        // set up query options
        const query = countiesLayer.createQuery();
        query.geometry = g; // graphic geometry from drawn points
        query.spatialRelationship = "intersects"; // find which county the point geometry is in
        query.outFields = ["NAME", "STATE_NAME", "POP2000"]; // the fields to add to the csv
        return countiesLayer.queryFeatures(query)
          .then((response) => { // after query is done, add the point to the csv
            csv += g.latitude + "," + g.longitude + "," + // will be undefined for lines/polygons
              response.features[0] + ',' +
              response.features[0].attributes.state_name + ',' +
              response.features[0].attributes.pop2000 + '\n'
            if (d) {
    ; // reset graphics
              csv = 'lat,lon,county,state,pop\n'; // reset the csv

       * @param {String} text: the text to be downloaded
       * Downloads a csv file
      function download(text) {
        const element = document.createElement('a');
        element.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', "data.csv"); = 'none';
       const sampleInstructions = document.createElement("div");
 = "sampleInstructions";
          sampleInstructions.innerHTML = `
         Click the marker symbol in the top right to draw points. <br>
        - trash symbol to clear previous points. <br>
        - download symbol for a csv with coordinates and county information. `;

          const instructionsExpand = new Expand({
            expandIconClass: "esri-icon-question",
            expandTooltip: "How to use this sample",
            view: view,
            content: sampleInstructions,
            expanded: true
          view.ui.add(instructionsExpand, "top-left");
    <div id="viewDiv">
      <div id="draw-point" class="esri-widget--button esri-widget esri-interactive" title="Draw points">
        <span class="action-button esri-icon-map-pin"></span>
      <div id="erase" class="esri-widget--button esri-widget esri-interactive" title="Remove points">
        <span class="action-button esri-icon-trash"></span>
      <div id="download" class="esri-widget--button esri-widget esri-interactive" title="Download CSV">
        <span class="action-button esri-icon-download"></span>