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;">
      <h3>Navigation Delineation Service - Results Queue - Catchments</h3> 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, dz_results_queue_id;
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
L.esri.dynamicMapLayer({
  url: "https://inlandwaters.geoplatform.gov/arcgis/rest/services/OWOTHER/WATERS_GeoViewer/MapServer/",
  layers: [36,37,38,40],
  position: "back"
}).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 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 disable controls
map.on('draw:deleted', function(e) {
  document.getElementById("dz_run_service").disabled = true;
});

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

// 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
  );

}

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",
    "optQueueResults": "THREADED",
    "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, results_queue_response
  );

}

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

  }

  if (
    response == null || response == undefined || response.output == null || response.output == undefined
  ) {
    busy_off();
    alert('Error calling results queue submittal');
    return false;

  }

  dz_results_queue_id = response.output.queue_service_id;

  var data = {
    "pQueueUniqueID": dz_results_queue_id,
    "pAction": "GET STATUS"
  };

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

}

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

  }

  if (
    response == null || response == undefined || response.output == null || response.output == undefined
  ) {
    busy_off();
    alert('Error calling check results');
    return false;
  }

  if (response.output.queue_status == "processing") {
    if (sleeping == undefined || sleeping == null) {
      setTimeout(
        function() {
          results_check_response(error, response, "slept");
        }, 20000
      );

      return true;

    } else {
      // Try again 
      var data = {
        "pQueueUniqueID": dz_results_queue_id,
        "pAction": "GET STATUS"
      };

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

    }

  } else if (response.output.queue_status == "complete") {

    var data = {
      "pQueueUniqueID": dz_results_queue_id,
      "pAction": "FETCH HTTP"
    };

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

  } else {
    busy_off();
    alert('Error calling queue service!');
    return false;
  }

}

function final_results_response(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";
    }

  } else {
    document.getElementById("output").innerHTML = "<P>  Area SQKM: " + Math.round(response.output.total_areasqkm * 1000) / 1000 + "</P>";
    var tmp_feature = geojson2feature(response.output.shape);
    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 dz_clear() {
  document.getElementById("output").innerHTML = '';
  basins.clearLayers();
}

function busy_on() {
  document.getElementById("busy").style.visibility = 'visible';
  document.body.style.cursor = 'wait';
  document.getElementById("dz_run_service").disabled = true;
}

function busy_off() {
  document.getElementById("busy").style.visibility = 'hidden';
  document.body.style.cursor = 'auto';
  document.getElementById("dz_run_service").disabled = false;
}
              
            
!
999px

Console