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

              
                <table>
  <tr>
    <td valign="top">
      <div id="map"></div>
    </td>
  </tr>
</table>
<div id="tabs">
  <ul>
    <li><a href="#tabs-advanced">Catchment Delineation Service - Upstream Catchments</a>

    </li>
    <li><a href="#tabs-results">Results</a>

    </li>
    <li><a href="#tabs-wkt">Geometry WKT</a>

    </li>
    <li><a href="#tabs-help">Help</a>

    </li>
  </ul>
  <div id="tabs-advanced">
    <form name="frm">
      <table border="0" cellpadding="5" cellspacing="5">
        <tr>
          <td valign="top" align="left">
            <input type="checkbox" name="dz_draw_point" id="dz_draw_point" onclick="toggle_draw_point();" />Draw Input Geometry Point
            <br/>
            <br/>
            <select name="selMaxType" id="selMaxType" onchange="changeSelMaxType(this);">
              <option value="maxdistance">Maximum Distance (KM)</option>
              <option value="maxflowtime">Maximum Flow Time (Hours)</option>
            </select>:
            <input name="pMaxDistance" type="text" class="text" id="dz_maxdistance" style="display:inline; width:30px" value="15" />
            <input name="pMaxTime" type="text" class="text" id="dz_maxflowtime" style="display:none; width:30px" />
            <br/>
            <br/>
            <input name="dz_aggregate_results" type="checkbox" id="dz_aggregate_results" CHECKED/>Aggregate Results
            <br/>
            <br/>
            <br/>
            <input type="button" onclick="run_service();" value="Start Search" id="dz_run_service" />
          </td>
        </tr>
      </table>
    </form>
  </div>
  <div id="tabs-results">
    <div id="output"></div>
  </div>
  <div id="tabs-wkt">
    <textarea name="wktbox" id="wktbox" rows="8" cols="60"></textarea>
    <br/>
    <input type="button" onclick="dz_clear_results();" value="Clear Map" name="dz_clear" id="dz_clear" />
  </div>
  <div id="tabs-help">
    <div id="help">
      <h3>For help with using this Navigation Delineation service...</h3>

      <table border="0" cellspacing="10" cellpadding="0">
        <tr>
          <td></td>
          <td style="font-weight:bold">Draw Input Geometry Point</td>
          <td>This service requires a point geometry as input. Click the checkbox and draw a point on the map to index. Uncheck the box if you wish to pan around the map.</td>
        </tr>
        <tr>
          <td></td>
          <td style="font-weight:bold">Maximum Distance (KM)</td>
          <td>Distance in KM to navigate. If neither Maximum Distance or Maximum Flow Time (Hours) are provided, then distance to travel defaults to 50 km.</td>
        </tr>
        <tr>
          <td></td>
          <td style="font-weight:bold">Maximum Flow Time (Hours)</td>
          <td>Time of travel in hours to navigate.</td>
        </tr>
      </table>
    </div>
  </div>
</div>
              
            
!

CSS

              
                #map {
  width: 600px;
  height: 300px;
  border: 1px solid black;
  position: relative;
}

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

td,
th,
tr,
input {
  margin: 0px;
  padding: 0px;
}

body,
table {
  font-size: 8pt;
}

.adv-fieldgroup-1 label {
  width: 40px;
  display: inline-block;
}

.adv-fieldgroup-1 input.text {
  margin-right: 2px;
  width: 188px;
}

.adv-fieldgroup-2 label {
  width: 62px;
  display: inline-block;
}

.adv-fieldgroup-2 input {
  width: 195px;
}

.google-visualization-table-table td {
  font-size: 8pt;
}
              
            
!

JS

              
                OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
OpenLayers.Util.onImageLoadErrorColor = "transparent";

var Proj4js = window["Proj4js"] = window["Proj4js"] || {
    Proj: function(code) {
        var result = proj4(code);
        result.srsCode = code; // for ol2 compatibility
        return result;
    },
    defs: proj4.defs,
    transform: proj4
};

var proj4269, proj4326, projSM;
var map, velayer, vectors, results;
var wktformatter, geojsonformatter, sldformatter;
var drawControls;
var $tabs, waiting_srv, waiting_pt;
var sldstyle = WATERS.SLD.general_styles('https://watersgeo.epa.gov/', ['DROPLET', 'GENERIC_STREAM', 'BASINS']);
var bingapi = "AmV2-FOWOEUjICR1lRxws9e2hUr7Vig5wACrvubpFGbqO61pxUxHzvIwhonYvVd0";

$(document).ready(function() {
  $tabs = $("#tabs").tabs({
    disabled: [1, 2]
  });
  $("#dz_draw_point").attr('checked', false);
  $("#dz_run_service").attr('disabled', true);

  // Projections in usage - NAD83, WSG84 and Spherical Mercator
  proj4269 = new OpenLayers.Projection("EPSG:4269");
  proj4326 = new OpenLayers.Projection("EPSG:4326");
  projSM = new OpenLayers.Projection("EPSG:900913");

  // Build some common formatters
  wktformatter = new OpenLayers.Format.WKT();
  geojsonformatter = new OpenLayers.Format.GeoJSON();
  sldformatter = new OpenLayers.Format.SLD();

  /* Create the map object */
  var options = {
    projection: projSM,
    displayProjection: proj4269,
    units: "m",
    numZoomLevels: 18,
    maxResolution: 156543.0339,
    maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
      20037508, 20037508.34)
  };

  map = new OpenLayers.Map('map', options);

  var veroad = new OpenLayers.Layer.Bing({
    'name': "Bing Roads",
    'type': 'Road',
    'key': bingapi
  });
  veroad.projection = projSM;
  map.addLayers([veroad]);

  var veaerial = new OpenLayers.Layer.Bing({
    'name': "Bing Aerial",
    'type': 'Aerial',
    'key': bingapi
  });
  veaerial.projection = projSM;
  map.addLayers([veaerial]);

  var nhddetailed = new OpenLayers.Layer.ArcGIS93Rest(
    "Office of Water NHD Detailed",
    "https://watersgeo.epa.gov/arcgis/rest/services/NHDPlus_NP21/NHDSnapshot_NP21_Labeled/MapServer/export", {
      layers: '0,1,3,4',
      srs: 102113,
      format: 'image/png'
    }, {
      isBaseLayer: true
    });
  nhddetailed.projection = projSM;
  map.addLayers([nhddetailed]);

  vectors = fast_layer("Sketch Layer", "WKT");
  snap_point = fast_layer("Snap Points");
  basins = fast_layer("Delineated Areas");
  flowlines = fast_layer("NHD Streams");

  map.addLayers([vectors, snap_point, basins, flowlines]);

  vectors.preFeatureInsert = function(feature) {
    if (vectors.features.length == 1) {
      vectors.removeFeatures(vectors.features[0]);
      vectors.redraw();
    }
  };

  vectors.onFeatureInsert = function(feature) {
    if (feature !== null) {
      var tempFeature = feature.clone();
      tempFeature.geometry.transform(projSM, proj4269);
      $("#wktbox").val(wktformatter.write(tempFeature));
      $tabs.tabs("enable", 2);
      $("#dz_run_service").attr('disabled', false);
    }
  };

  var sld = sldformatter.read(sldstyle);
  var stylelibrary = sld.namedLayers["common_styles"].userStyles;
  for (i in stylelibrary) {
    if (stylelibrary[i].name == "DROPLET") {
      snap_point.styleMap.styles["default"] = stylelibrary[i];
    } else if (stylelibrary[i].name == "GENERIC_STREAM") {
      flowlines.styleMap.styles["default"] = stylelibrary[i];
    } else if (stylelibrary[i].name == "BASINS") {
      basins.styleMap.styles["default"] = stylelibrary[i];
    }
  }

  // Add controls to the map
  map.addControl(new OpenLayers.Control.LayerSwitcher());
  map.addControl(new OpenLayers.Control.MousePosition());
  map.addControl(new OpenLayers.Control.Navigation());

  // Center on DC
  var mapcenter = new OpenLayers.LonLat(-77.035271, 38.883430);
  map.setCenter(
    OpenLayers.Layer.SphericalMercator.forwardMercator(
      mapcenter.lon,
      mapcenter.lat),
    11);

  //Add some drawing tools
  drawControls = {
    point: new OpenLayers.Control.DrawFeature(
      vectors,
      OpenLayers.Handler.Point)
  };

  map.addControl(drawControls['point']);

  // Create the three waiting overlay objects
  waiting_pt = new WATERS.Helpers.SearchingDialog("globe_spinning_small.gif", "<h4>&nbsp;&nbsp;Snapping Point...</h4>", null, 80, "dz_p1");
  waiting_srv = new WATERS.Helpers.SearchingDialog("globe_spinning_small.gif", "<h4>&nbsp;&nbsp;Searching...</h4>", null, 80, "dz_in");

});

function fast_layer(dz_title, dz_type) {
  var dz_format;
  if (dz_type == undefined || dz_type == 'GEOJSON') {
    dz_format = OpenLayers.Format.GEOJSON;
  } else if (dz_type == 'WKT') {
    dz_format = OpenLayers.Format.WKT;
  } else {
    alert('ERROR, unknown format!');
    return false;
  }
  var dz_layer = new OpenLayers.Layer.Vector(
    dz_title, {
      format: dz_format
    }, {
      isFixed: false
    });
  return dz_layer;
}

function geojson2feature(dz_geojson) {

  // Force jquery coordinates into real js Array
  if (dz_geojson.coordinates instanceof Array == false) {
    dz_geojson.coordinates = WATERS.Utilities.RepairArray(dz_geojson.coordinates, 0);
  }

  var dz_geometry = geojsonformatter.parseGeometry(dz_geojson);
  dz_geometry.transform(proj4269, projSM);
  var dz_feature = new OpenLayers.Feature;
  dz_feature.geometry = dz_geometry;

  return dz_feature;
}

function toggle_draw_point() {
  if (drawControls['point'].active == true) {
    drawControls['point'].deactivate();
  } else {
    drawControls['point'].activate();
  }
}

function run_service() {
  var options = {
    "success": "ptsuccess",
    "error": "pterror",
    "timeout": 60 * 1000
  };

  var data = {
    "pGeometry": WATERS.Helpers.GetFieldValue("wktbox"),
    "pGeometryMod": "WKT,SRID=8265",
    "pResolution": 3,
    "pPointIndexingMethod": "DISTANCE",
    "pPointIndexingMaxDist": 25,
    "pOutputPathFlag": "FALSE",
    "pReturnFlowlineGeomFlag": "FALSE",
    "optNHDPlusDataset": "2.1"
  };

  waiting_pt.show();
  rtnStr = WATERS.Services.PointIndexingService(data, options);

  if (rtnStr != "") {
    alert(rtnStr);
  };
}

function ptsuccess(result, textStatus) {
  document.getElementById("output").innerHTML = '';

  var srv_rez = result.output;

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

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

    }

  } else {
    // Need to get the results to then call navigation service

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

    snap_point.addFeatures(geojson2feature(srv_rez.end_point));
    snap_point.refresh();

    // Only use the topology as the source when aggregating      
    var use_topo;
    if (WATERS.Helpers.GetFieldValue('dz_aggregate_results') == false) {
      use_topo = "CATCHMENT";
    } else {
      //use_topo = "CATCHMENT_TOPO";
      use_topo = "CATCHMENT";
    }

    var options = {
      "success": "success",
      "error": "error",
      "timeout": 60 * 1000,
      "geomFormat": "GEOJSON"
    };

    var data = {
      "pNavigationType": "UT",
      "pStartComid": comid,
      "pStartMeasure": measure,
      "pMaxDistance": WATERS.Helpers.GetFieldValue("dz_maxdistance"),
      "pMaxTime": WATERS.Helpers.GetFieldValue("dz_maxflowtime"),
      "pAggregationFlag": WATERS.Helpers.GetFieldValue('dz_aggregate_results'),
      "pFeatureType": use_topo,
      "pOutputFlag": "BOTH",
      "optNHDPlusDataset": "2.1"
    };

    waiting_srv.show();
    rtnStr = WATERS.Services.NavigationDelineationService(data, options);

    if (rtnStr != "") {
      alert(rtnStr);
    };

  }

}

function pterror(XMLHttpRequest, textStatus, errorThrown) {
  alert('Point Indexing Service Error: ' + textStatus);
  waiting_pt.hide();
}

function success(result, textStatus) {
  document.getElementById("output").innerHTML = '';

  var srv_rez = result.output;

  waiting_srv.hide();
  if (srv_rez == null) {
    if (result.status.status_message !== null) {
      document.getElementById("output").innerHTML = result.status.status_message;
    } else {
      document.getElementById("output").innerHTML = "No results found";
    }
  } else {

    function drawTable() {
      var tableData = new google.visualization.DataTable();
      tableData.addColumn('string', 'Total Area SQKM');

      var rowIndex = 0;
      var output = document.getElementById("output");
      var areasqkm = Math.round(result.output.total_areasqkm * 1000) / 1000;

      tableData.addRows(1);
      tableData.setCell(rowIndex, 0, areasqkm.toString());

      var table = new google.visualization.Table(output);
      table.draw(
        tableData, {
          showRowNumber: true,
          allowHtml: true,
          sortColumn: 0,
          page: "enable",
          pageSize: Math.floor((document.body.clientHeight - 135) / 19)
        });
    }

    google.load('visualization', '1', {
      packages: ['table'],
      callback: drawTable
    });

    if (result.output.shape == null) {
      for (i in result.output.catchments) {
        basins.addFeatures(geojson2feature(result.output.catchments[i].shape));
      }
    } else {
      basins.addFeatures(geojson2feature(result.output.shape));
    }

    if (result.output.flowlines.length > 0) {
      for (i in result.output.flowlines) {
        flowlines.addFeatures(geojson2feature(result.output.flowlines[i].shape));
      }
    }
    flowlines.refresh();
    basins.refresh();
  }

  $tabs.tabs("option", "disabled", []);
  $tabs.tabs("option", "active", 1);

}

function error(XMLHttpRequest, textStatus, errorThrown) {
  alert(textStatus);
  waiting_srv.hide();
}

function dz_clear_results() {
  snap_point.destroyFeatures();
  flowlines.destroyFeatures();
  basins.destroyFeatures();
  snap_point.refresh();
  flowlines.refresh();
  basins.refresh();
}

function changeSelMaxType(el) {
  if (el.selectedIndex == 0) {
    document.getElementById('dz_maxflowtime').value = '';
    document.getElementById('dz_maxflowtime').focus();
    document.getElementById('dz_maxflowtime').blur();
    document.getElementById('dz_maxdistance').style.display = "inline";
    document.getElementById('dz_maxflowtime').style.display = "none";
    document.getElementById('dz_maxdistance').focus();
  } else {
    document.getElementById('dz_maxdistance').value = '';
    document.getElementById('dz_maxdistance').focus();
    document.getElementById('dz_maxdistance').blur();
    document.getElementById('dz_maxdistance').style.display = "none";
    document.getElementById('dz_maxflowtime').style.display = "inline";
    document.getElementById('dz_maxflowtime').focus();
  }
}
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
  var pageTracker = _gat._getTracker("UA-10077177-1");
  pageTracker._trackPageview();
} catch (err) {}
              
            
!
999px

Console