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>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>
      Slider widget example
    </title>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.28/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.28/"></script>
  <body>
    <div id="viewDiv"></div>
    <div id="infoDiv" class="esri-widget">
      <div id="drop-downs">
        Select well type:
        <select id="well-type" class="esri-widget"></select>
      </div>
      Well buffer distance (meters):
      <div id="distance" class="slider"></div>
      Earthquake magnitude:
      <div id="mag" class="slider"></div>
      <button id="query-quakes" class="esri-widget">Query Earthquakes</button>
      <div id="results" class="esri-widget"></div>
    </div>
  </body>
</html>
              
            
!

CSS

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

#infoDiv {
  background-color: white;
  color: black;
  padding: 6px;
  width: 400px;
}

#results {
  font-weight: bolder;
  padding-top: 10px;
}
.slider {
  width: 100%;
  height: 60px;
}
#drop-downs {
  padding-bottom: 15px;
}

              
            
!

JS

              
                require([
  "esri/Map",
  "esri/views/MapView",
  "esri/layers/FeatureLayer",
  "esri/layers/GraphicsLayer",
  "esri/geometry/geometryEngine",
  "esri/Graphic",
  "esri/widgets/Slider"
], (
  Map,
  MapView,
  FeatureLayer,
  GraphicsLayer,
  geometryEngine,
  Graphic,
  Slider
) => {
  const quakesUrl =
    "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/ks_earthquakes_since_2000/FeatureServer/0";

  var wellBuffer, wellsGeometries, magnitude;

  const wellTypeSelect = document.getElementById("well-type");

  const magSlider = new Slider({
    container: "mag",
    min: 0,
    max: 5,
    steps: 0.1,
    values: [2],
    visibleElements: {
      labels: true,
      rangeLabels: true
    }
  });

  const distanceSlider = new Slider({
    container: "distance",
    min: 100,
    max: 10000,
    steps: 100,
    labelFormatFunction: function (value, type) {
      if (type === "value") {
        return parseInt(value);
      }
      return value;
    },
    values: [5000],
    visibleElements: {
      labels: true,
      rangeLabels: true
    }
  });

  const queryQuakes = document.getElementById("query-quakes");

  // oil and gas wells
  const wellsLayer = new FeatureLayer({
    portalItem: {
      // autocasts as new PortalItem()
      id: "8af8dc98e75049bda6811b0cdf9450ee"
    },
    outFields: ["*"],
    visible: false
  });

  // historic earthquakes
  const quakesLayer = new FeatureLayer({
    url: quakesUrl,
    outFields: ["*"],
    visible: false
  });

  // GraphicsLayer for displaying results
  const resultsLayer = new GraphicsLayer();

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

  const view = new MapView({
    container: "viewDiv",
    map: map,
    center: [-97.75188, 37.23308],
    zoom: 9
  });
  view.ui.add("infoDiv", "top-right");

  // query all features from the wells layer
  view
    .when(function () {
      return wellsLayer.when(function () {
        const query = wellsLayer.createQuery();
        return wellsLayer.queryFeatures(query);
      });
    })
    .then(getValues)
    .then(getUniqueValues)
    .then(addToSelect)
    .then(createBuffer);

  // return an array of all the values in the
  // STATUS2 field of the wells layer
  function getValues(response) {
    const features = response.features;
    const values = features.map(function (feature) {
      return feature.attributes.STATUS2;
    });
    return values;
  }

  // return an array of unique values in
  // the STATUS2 field of the wells layer
  function getUniqueValues(values) {
    const uniqueValues = [];

    values.forEach(function (item, i) {
      if (
        (uniqueValues.length < 1 || uniqueValues.indexOf(item) === -1) &&
        item !== ""
      ) {
        uniqueValues.push(item);
      }
    });
    return uniqueValues;
  }

  // Add the unique values to the wells type
  // select element. This will allow the user
  // to filter wells by type.
  function addToSelect(values) {
    values.sort();
    values.forEach(function (value) {
      const option = document.createElement("option");
      option.text = value;
      wellTypeSelect.add(option);
    });

    return setWellsDefinitionExpression(wellTypeSelect.value);
  }

  // set the definition expression on the wells
  // layer to reflect the selection of the user
  function setWellsDefinitionExpression(newValue) {
    wellsLayer.definitionExpression = "STATUS2 = '" + newValue + "'";

    if (!wellsLayer.visible) {
      wellsLayer.visible = true;
    }

    return queryForWellGeometries();
  }

  // Get all the geometries of the wells layer
  // the createQuery() method creates a query
  // object that respects the definitionExpression
  // of the layer
  function queryForWellGeometries() {
    const wellsQuery = wellsLayer.createQuery();

    return wellsLayer.queryFeatures(wellsQuery).then(function (response) {
      wellsGeometries = response.features.map(function (feature) {
        return feature.geometry;
      });

      return wellsGeometries;
    });
  }

  // creates a single buffer polygon around
  // the well geometries

  var bufferGraphic = null;
  function createBuffer(wellPoints) {
    const bufferDistance = distanceSlider.values[0];
    const wellBuffers = geometryEngine.geodesicBuffer(
      wellPoints,
      [bufferDistance],
      "meters",
      true
    );
    wellBuffer = wellBuffers[0];

    if (bufferGraphic) {
      bufferGraphic.geometry = wellBuffer;
    } else {
      // add the buffer to the view as a graphic
      bufferGraphic = new Graphic({
        geometry: wellBuffer,
        symbol: {
          type: "simple-fill", // autocasts as new SimpleFillSymbol()
          outline: {
            width: 1.5,
            color: [255, 128, 0, 0.5]
          },
          style: "none"
        }
      });
      view.graphics.add(bufferGraphic);
    }
  }

  // Get the magnitude value set by the user
  magSlider.on("thumb-drag", function (event) {
    magnitude = event.value;
  });
  // create a buffer around the queried geometries
  distanceSlider.on("thumb-drag", function (event) {
    if (event.state === "stop") {
      createBuffer(wellsGeometries);
    }
  });
  // set a new definitionExpression on the wells layer
  // and create a new buffer around the new wells
  wellTypeSelect.addEventListener("change", function () {
    const type = event.target.value;
    setWellsDefinitionExpression(type).then(createBuffer);
  });

  // query for earthquakes with the specified magnitude
  // within the buffer geometry when the query button
  // is clicked
  queryQuakes.addEventListener("click", function () {
    queryEarthquakes().then(displayResults);
  });

  function queryEarthquakes() {
    const query = quakesLayer.createQuery();
    query.where = "mag >= " + magSlider.values[0];
    query.geometry = wellBuffer;
    query.spatialRelationship = "intersects";

    return quakesLayer.queryFeatures(query);
  }

  // display the earthquake query results in the
  // view and print the number of results to the DOM
  function displayResults(results) {
    resultsLayer.removeAll();
    const features = results.features.map(function (graphic) {
      graphic.symbol = {
        type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
        style: "diamond",
        size: 6.5,
        color: "darkorange"
      };
      return graphic;
    });
    const numQuakes = features.length;
    document.getElementById("results").innerHTML =
      numQuakes + " earthquakes found";
    resultsLayer.addMany(features);
  }
});

              
            
!
999px

Console