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.


                <div id="busy">
  <svg width="57" height="57" viewBox="0 0 57 57" xmlns="" stroke="#000">
    <g fill="none" fill-rule="evenodd">
      <g transform="translate(1 1)" stroke-width="2">
        <circle cx="5" cy="50" r="5">
          <animate attributeName="cy" begin="0s" dur="2.2s" values="50;5;50;50" calcMode="linear" repeatCount="indefinite" />
          <animate attributeName="cx" begin="0s" dur="2.2s" values="5;27;49;5" calcMode="linear" repeatCount="indefinite" />
        <circle cx="27" cy="5" r="5">
          <animate attributeName="cy" begin="0s" dur="2.2s" from="5" to="5" values="5;50;50;5" calcMode="linear" repeatCount="indefinite" />
          <animate attributeName="cx" begin="0s" dur="2.2s" from="27" to="27" values="27;49;5;27" calcMode="linear" repeatCount="indefinite" />
        <circle cx="49" cy="50" r="5">
          <animate attributeName="cy" begin="0s" dur="2.2s" values="50;50;5;50" calcMode="linear" repeatCount="indefinite" />
          <animate attributeName="cx" from="49" to="49" begin="0s" dur="2.2s" values="49;5;27;49" calcMode="linear" repeatCount="indefinite" />
<div id="container" style="width: 1200px;">
  <div id="map" class="map" style="height: 400px; width: 600px; float: left;">
  <div id="righty" style="width: 600px; float: left;">
    <div id="top" style="text-align: center;">
      <h2>Point Indexing Service</h2> Add a point to the map or enter your NAD83 WKT text:
      <input name="dzWKT" type="text" class="textbox" style="width: 400px;" id="dzWKT" onchange="updatewkt(this.value);" />
      <br/> Use:
      <select name="dz_snap_type" id="dz_snap_type">
        <option value="DISTANCE">Distance Snap</option>
        <option value="RAINDROP">Raindrop Flow</option>
        <option value="CATCONSTRAINED">Catchment Constrained</option>
      </select>&nbsp;&nbsp; Max:
      <input name="pMaxDistance" type="text" class="text" id="dz_maxdistance" style="display:inline; width:30px" value="25" /> km
      <input type="button" onclick="run_service();" value="Start Search" id="dz_run_service" />&nbsp;
      <input type="button" onclick="dz_clear();" value="Clear" name="dz_clear" id="dz_clear" />&nbsp;
    <div id="output" style="text-align: center"></div>


                #busy {
  position: absolute;
  top: 25%;
  left: 620px;
  z-index: 100;


                var wktval, layer;
var service_url = '';

//Force Leaflet-ESRI to use JSONP for Waters Services
L.esri.get = L.esri.get.JSONP;

// Initialize the form elements
document.getElementById("dz_run_service").disabled = true;
document.getElementById("busy").style.visibility = 'hidden';

// Create map centered on DC at level 13
var map ='map').setView([38.883430, -77.035271], 13);
mapLink = '<a href="">OpenStreetMap</a>';

// Add OpenStreetMap base layer
// Please repoint to an appropriate base map for your organization
  'https://{s}{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; ' + mapLink,
    maxZoom: 18

// Add Office of Water Labelled NHDPlus Flowline Map Service from GeoCloud
  url: "",
  layers: [36,37,38,40],
  position: "back"

// Initialize marker point drawing tools
var drawnItems = new L.FeatureGroup().addTo(map);
var drawControl = new L.Control.Draw({
  draw: {
    polygon: false,
    polyline: false,
    rectangle: false,
    circle: false,
    marker: true,
    circlemarker: false
  edit: {
    featureGroup: drawnItems,
    edit: false,
    remove: true

// Add event to update the box and popup with WKT
map.on('draw:created', function(e) {
  var type = e.layerType,
    layer = e.layer;
  if (type === 'marker') {
    wktval = 'POINT(' + layer.getLatLng().lng + ' ' + layer.getLatLng().lat + ')';
  document.getElementById("dzWKT").value = wktval;
  document.getElementById("dz_run_service").disabled = false;

// Add event to remove the WKT from the box and disable controls
map.on('draw:deleted', function(e) {
  document.getElementById("dzWKT").value = "";
  document.getElementById("dz_run_service").disabled = true;

// Add layer to hold the service results
var snapline = L.geoJson().addTo(map);

// Function to execute the service when button is pressed
function run_service() {

  var pmethod = document.getElementById("dz_snap_type");
  var pdist, rpath

  if (pmethod.options[pmethod.selectedIndex].value == "DISTANCE") {
    pdist = document.getElementById("dz_maxdistance").value;
    rpath = 0;
  } else {
    pdist = 0.25;
    rpath = document.getElementById("dz_maxdistance").value;

  // Load the parameters to pass to the service
  var data = {
    "pGeometry": wktval,
    "pGeometryMod": "WKT,SRSNAME=urn:ogc:def:crs:OGC::CRS84",
    "pPointIndexingMethod": pmethod.options[pmethod.selectedIndex].value,
    "pPointIndexingRaindropDist": rpath,
    "pPointIndexingMaxDist": pdist,
    "pOutputPathFlag": "TRUE",
    "pReturnFlowlineGeomFlag": "FALSE",
    "optOutCS": "SRSNAME=urn:ogc:def:crs:OGC::CRS84",
    "optOutPrettyPrint": 0,
    "optClientRef": "CodePen"

  // Use ESRI request module to call service via JSONP
    service_url + 'PointIndexing.Service', data, ptresponse


// Callback function on service completion
function ptresponse(error, response) {
  if (error) {
    document.getElementById("output").innerHTML = "<P>" + error + "</P>";
    return false;


  var srv_rez = response.output;

  if (srv_rez == null) {
    if (response.status.status_message !== null) {
      document.getElementById("output").innerHTML = "<P>" + response.status.status_message + "</P>";

    } else {
      document.getElementById("output").innerHTML = "<P>No results found.</P>";


    return false;


  var comid = srv_rez.ary_flowlines[0].comid;
  var measure = srv_rez.ary_flowlines[0].fmeasure;

  document.getElementById("output").innerHTML = "<P>NHDPlus Flowline Permanent Identifier: " + comid + "</P>NHDPlus Flowline Measure: " + measure + "</P>"

  tmp_feature = geojson2feature(srv_rez.indexing_path);
    color: "#FF0000",
    fillColor: "#FF0000"

  map.fitBounds(snapline.getBounds(), {
    maxZoom: 13


// Function to wrap GeoJSON geometry into a vanilla feature
function geojson2feature(
  p_geojson, p_popup_value, p_id
) {
  if (p_geojson == undefined) {
    return null;

  if (p_id == undefined || p_id == null) {
    p_id = 0;

  p_feature = {
    "type": "Feature",
    "properties": {
      "id": p_id,
      "popupValue": p_popup_value
    "geometry": p_geojson

  return p_feature;


//Function to clear map on new request or Clear button
function dz_clear() {
  document.getElementById("output").innerHTML = '';


//Function to turn on the dorky animation
function busy_on() {
  document.getElementById("busy").style.visibility = 'visible'; = 'wait';
  document.getElementById("dz_run_service").disabled = true;


//Function to turn off the dorky animation
function busy_off() {
  document.getElementById("busy").style.visibility = 'hidden'; = 'auto';
  document.getElementById("dz_run_service").disabled = false;


// Function to produce WKT for the box and marker popup
// Uses Leaflet-Omnivore for WKT parsing 
function updatewkt(wktString) {

  if (wktString == null || wktString == undefined || wktString == "") {
    document.getElementById("dz_run_service").disabled = true;

  } else {
    var layer;

    try {
      layer = omnivore.wkt.parse(wktString);

    } catch (layer) {
      alert('Unable to parse WKT geometry.');
      document.getElementById("dz_run_service").disabled = true;
      return null;


    document.getElementById("dz_run_service").disabled = false;
    wktval = wktString
    map.fitBounds(drawnItems.getBounds(), {
      maxZoom: 11