Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div id="busy">
  <svg width="57" height="57" viewBox="0 0 57 57" xmlns="http://www.w3.org/2000/svg" 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>
        <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>
        <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" />
        </circle>
      </g>
    </g>
  </svg>
</div>
<div id="container" style="width: 1200px;">
  <div id="map" class="map" style="height: 400px; width: 600px; float: left;">
  </div>
  <div id="righty" style="width: 600px; float: left;">
    <div id="top" style="text-align: center;">
      <h2>Navigation Delineation Service - Catchments</h2> Start by drawing a point on the map
      <p/> Maximum Distance (KM):&nbsp;
      <input name="pMaxDistance" type="text" class="text" id="dz_maxdistance" style="display:inline; width:30px" value="2" />&nbsp;&nbsp;
      <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>
    <div id="output" style="text-align: center"></div>
  </div>
</div>
              
            
!

CSS

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

JS

              
                var wkt, layer;
var service_url = 'https://ofmpub.epa.gov/waters10/';

//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 = L.map('map').setView([38.883430, -77.035271], 13);
mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';

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

// Add Office of Water Labelled NHDPlus Flowline Map Service from GeoCloud
var snapshot = L.esri.dynamicMapLayer({
  url: "https://inlandwaters.geoplatform.gov/arcgis/rest/services/OWOTHER/WATERS_GeoViewer/MapServer/",
  layers: [36,37,38,40],
  position: "back",
  useCors: true
}).addTo(map);

// 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
  }
});
map.addControl(drawControl);

// Add event to update the box and popup with WKT
map.on('draw:created', function(e) {
  var type = e.layerType,
    layer = e.layer;
  drawnItems.clearLayers();
  if (type === 'marker') {
    wkt = 'POINT(' + layer.getLatLng().lng + ' ' + layer.getLatLng().lat + ')';
    layer.bindPopup(wkt);
  }
  drawnItems.addLayer(layer);
  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("dz_run_service").disabled = true;
});

// Add layer to hold the service results
var basins = new L.GeoJSON(
  null, {
    onEachFeature: onEachFeature
  }
).addTo(map);

// Function to bind popup values
function onEachFeature(feature, layer) {
  layer.bindPopup(feature.properties.popupValue);
}

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

  var data = {
    "pGeometry": wkt,
    "pGeometryMod": "WKT,SRSNAME=urn:ogc:def:crs:OGC::CRS84",
    "pPointIndexingMethod": "DISTANCE",
    "pPointIndexingMaxDist": 25,
    "pOutputPathFlag": "FALSE",
    "pReturnFlowlineGeomFlag": "FALSE",
    "optOutCS": "SRSNAME=urn:ogc:def:crs:OGC::CRS84",
    "optOutPrettyPrint": 0,
    "optClientRef": "CodePen"
  };

  // Use ESRI request module to call service via JSONP
  L.esri.get(
    service_url + 'PointIndexing.Service', data, ptresponse
  );
}

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

  }

  var srv_rez = response.output;
  if (srv_rez == null) {
    if (response.status.status_message !== null) {
      document.getElementById("output").innerHTML = response.status.status_message;
    } else {
      document.getElementById("output").innerHTML = "No results found";
    }
    busy_off();
    return false;

  }

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

  var data = {
    "pNavigationType": "UT",
    "pStartComid": comid,
    "pStartMeasure": measure,
    "pMaxDistance": document.getElementById("dz_maxdistance").value,
    "pAggregationFlag": "TRUE",
    "pFeatureType": "CATCHMENT_TOPO",
    "pOutputFlag": "FEATURE",
    "pFlowlineLists": "FALSE",
    "optOutPruneNumber": 8,
    "optOutCS": "SRSNAME=urn:ogc:def:crs:OGC::CRS84",
    "optOutPrettyPrint": 0,
    "optClientRef": "CodePen"
  };

  // Use ESRI request module to call service via JSONP
  L.esri.get(
    service_url + 'NavigationDelineation.Service', data, delinresponse
  );

}

function delinresponse(error, response) {
  if (error) {
    document.getElementById("output").innerHTML = "<P>" + error + "</P>";
    busy_off();
    return false;

  }

  var srv_rez = response.output;

  if (srv_rez == null) {
    if (response.status.status_message !== null) {
      document.getElementById("output").innerHTML = response.status.status_message;

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

    }
    busy_off();
    return false;

  }
  var total_areasqkm = Math.round(srv_rez.total_areasqkm * 1000) / 1000;
  document.getElementById("output").innerHTML = "<P>  Area SQKM: " + total_areasqkm + "</P>";
  var tmp_feature = geojson2feature(
    srv_rez.shape, "<B>Aggregated Basin of NHDPlus Catchments</B><BR/><BR/>Total Area SqKM: " + total_areasqkm
  );
  basins.addData(tmp_feature);

  map.fitBounds(basins.getBounds());
  busy_off();

}

// 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 = '';
  basins.clearLayers();

}

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

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

Console