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">Beach Event Indexing Service</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 Start and End Points
            <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="wktbox1" id="wktbox1" rows="1" cols="60"></textarea>
    <br/>
    <textarea name="wktbox2" id="wktbox2" rows="1" cols="60"></textarea>
    <br/>
    <textarea name="wktbox3" id="wktbox3" rows="2" 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 Beach Point Traversal Indexing service...</h3>
      <table border="0" cellspacing="10" cellpadding="0">
        <tr>
          <td style="font-weight:bold">Draw Start and End Points</td>
          <td>
            This service requires two point geometries as input. Click the checkbox and draw the points on the map to index. Uncheck the box if you wish to pan around the map.
          </td>
        </tr>
        <tr>
          <td style="font-weight:bold">Notes</td>
          <td>
            This service utilizes the point traversal indexing method. This method calculates NHD network connections on-the-fly and essentially "wanders" these connections until the two points find a connection to each other. This is not viable over large networks.
            However as beach networks are by nature simple and at the same time cannot be navigated by utilizing NHDPlus flow tables, the point traversal indexing method has great utility in beach indexing. Note this service example limits network "wandering"
            to 25 KM. If a connection cannot be found after 25 KM, the process is aborted. If you desire to index beaches with lengths greater than 25KM, adjust this value accordingly.
          </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, feature1, feature2;
var $tabs, waiting_p1, waiting_p2, waiting_index;
var sldstyle = WATERS.SLD.general_styles('https://watersgeo.epa.gov/', ['SNAP_POINT', 'GENERIC_EVENTS']);
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");
  index_events = fast_layer("Indexed Events");

  map.addLayers([vectors, snap_point, index_events]);

  var sld = sldformatter.read(sldstyle);
  var stylelibrary = sld.namedLayers["common_styles"].userStyles;
  for (i in stylelibrary) {
    if (stylelibrary[i].name == "SNAP_POINT") {
      snap_point.styleMap.styles["default"] = stylelibrary[i];
    } else if (stylelibrary[i].name == "GENERIC_EVENTS") {
      index_events.styleMap.styles["default"] = stylelibrary[i];
    }
  }

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

  vectors.onFeatureInsert = function(feature) {
    if (feature !== null) {
      if (vectors.features.length > 1) {
        var tempFeature = vectors.features[0].clone();
        tempFeature.geometry.transform(projSM, proj4269);
        $("#wktbox1").val(wktformatter.write(tempFeature));
        tempFeature = vectors.features[1].clone();
        tempFeature.geometry.transform(projSM, proj4269);
        $("#wktbox2").val(wktformatter.write(tempFeature));
        $tabs.tabs("enable", 2);
        $("#dz_run_service").attr('disabled', false);
      }
    }
  }

  // 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 Traverse City
  var mapcenter = new OpenLayers.LonLat(-85.575, 44.755);
  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_p1 = new WATERS.Helpers.SearchingDialog("generic_spinner_small.gif", "<h4>&nbsp;&nbsp;Snapping First Point...</h4>", null, 80, "dz_p1");
  waiting_p2 = new WATERS.Helpers.SearchingDialog("generic_spinner_small.gif", "<h4>&nbsp;&nbsp;Snapping Second Point...</h4>", null, 80, "dz_p2");
  waiting_index = new WATERS.Helpers.SearchingDialog("generic_spinner_small.gif", "<h4>&nbsp;&nbsp;Indexing...</h4>", null, 80, "dz_in");

});

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

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

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

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

function pt1success(result, textStatus) {

  var point1 = result.output.end_point;
  feature1 = geojson2feature(point1);
  snap_point.addFeatures(feature1);

  waiting_p1.hide();

  var options = {
    "success": "pt2success",
    "error": "pterror",
    "timeout": 60 * 1000
  };

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

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

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

function pt2success(result, textStatus) {

  var point2 = result.output.end_point;
  feature2 = geojson2feature(point2);
  snap_point.addFeatures(feature2);

  waiting_p2.hide();

  var temp_mp = new OpenLayers.Feature();
  temp_mp.geometry = new OpenLayers.Geometry.MultiPoint();
  temp_mp.geometry.addPoint(feature1.geometry.clone());
  temp_mp.geometry.addPoint(feature2.geometry.clone());
  temp_mp.geometry.transform(projSM, proj4269);
  $("#wktbox3").val(wktformatter.write(temp_mp));

  var options = {
    "success": "final_success",
    "error": "final_error",
    "timeout": 60 * 1000
  };

  var data = {
    "pInputGeometry": WATERS.Helpers.GetFieldValue("wktbox3"),
    "pInputGeometryMod": "WKT,SRID=8265",
    "pBatchResolution": 3,
    "pIndexingType": "traversal",
    "pFcodeAllow": "56600,56700",
    "pFcodeAllowMod": ",",
    "pTraverseFcodeAllow": "56600,56700",
    "pTraverseFcodeAllowMod": ",",
    "optNHDPlusDataset": "2.1"
  };

  waiting_index.show();
  rtnStr = WATERS.Services.EventIndexingService(data, options);

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

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

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

  var srv_rez = result.output;

  waiting_index.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 {

    var srv_points = result.output.point_events;
    var srv_lines = result.output.line_events;
    var srv_areas = result.output.area_events;

    function drawTable() {
      var tableData = new google.visualization.DataTable();
      tableData.addColumn('string', 'Event Type');
      tableData.addColumn('string', 'Event Reach Code');
      tableData.addColumn('string', 'Event From Measure');
      tableData.addColumn('string', 'Event To Measure');
      tableData.addColumn('string', 'Event Extent')

      var rowIndex = 0;
      var output = document.getElementById("output");
      var distance = Math.round(srv_rez.total_distance * 1000) / 1000;

      for (index in srv_areas) {
        tableData.addRows(1);
        var colIndex = 0;
        var extent = Math.round(srv_areas[index].shape_area * 1000) / 1000;
        tableData.setCell(rowIndex, colIndex++, "Area");
        tableData.setCell(rowIndex, colIndex++, srv_areas[index].reachcode);
        tableData.setCell(rowIndex, colIndex++, " ");
        tableData.setCell(rowIndex, colIndex++, " ");
        tableData.setCell(rowIndex, colIndex++, extent.toString() + " SQKM");
        rowIndex++;
      }

      for (index in srv_lines) {
        tableData.addRows(1);
        var colIndex = 0;
        var extent = Math.round(srv_lines[index].shape_length * 1000) / 1000;
        tableData.setCell(rowIndex, colIndex++, "Line");
        tableData.setCell(rowIndex, colIndex++, srv_lines[index].reachcode);
        tableData.setCell(rowIndex, colIndex++, srv_lines[index].fmeasure.toString());
        tableData.setCell(rowIndex, colIndex++, srv_lines[index].tmeasure.toString());
        tableData.setCell(rowIndex, colIndex++, extent.toString() + " M");
        rowIndex++;
      }

      for (index in srv_points) {
        tableData.addRows(1);
        var colIndex = 0;
        tableData.setCell(rowIndex, colIndex++, "Point");
        tableData.setCell(rowIndex, colIndex++, srv_points[index].reachcode);
        tableData.setCell(rowIndex, colIndex++, srv_points[index].measure.toString());
        tableData.setCell(rowIndex, colIndex++, " ");
        tableData.setCell(rowIndex, colIndex++, "1");
        rowIndex++;
      }

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

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

    for (i in srv_points) {
      index_events.addFeatures(geojson2feature(srv_points[i].shape));
    }
    for (i in srv_lines) {
      index_events.addFeatures(geojson2feature(srv_lines[i].shape));
    }
    for (i in srv_areas) {
      index_events.addFeatures(geojson2feature(srv_areas[i].shape));
    }
    index_events.refresh();
  }

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

}

function final_error(XMLHttpRequest, textStatus, errorThrown) {
  alert(textStatus);
  waiting_index.hide();
}

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

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 dz_clear_results() {
  snap_point.destroyFeatures();
  index_events.destroyFeatures();
  snap_point.refresh();
  index_events.refresh();
}
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