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">Event Indexing Service - Polygon</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_polygon" id="dz_draw_polygon" onclick="toggle_draw_polygon();" /> Draw Indexing Polygon
            <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="5" 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 Event Indexing service...</h3>
      <table border="0" cellspacing="10" cellpadding="0">
        <tr>
          <td style="font-weight:bold">Draw Input Geometry Polygon</td>
          <td>
            This service requires a polygon geometry as input. Click the checkbox and draw a polygon on the map to index. Uncheck the box if you wish to pan around the map.
          </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_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_polygon").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/OW/NHD_Med_Detailed_WMERC/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 == 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);
    }
  }

  // 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 Mall
  var mapcenter = new OpenLayers.LonLat(-77.035271, 38.883430);
  map.setCenter(
    OpenLayers.Layer.SphericalMercator.forwardMercator(
      mapcenter.lon,
      mapcenter.lat
    ),
    12
  );

  //Add some drawing tools
  drawControls = {
    polygon: new OpenLayers.Control.DrawFeature(
      vectors,
      OpenLayers.Handler.Polygon, {
        handlerOptions: {
          freehand: false
        }
      }
    )
  };

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

  // Create the three waiting overlay objects
  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": "success",
    "error": "error",
    "timeout": 60 * 1000
  };

  var data = {
    "pInputGeometry": WATERS.Helpers.GetFieldValue("wktbox"),
    "pInputGeometryMod": "WKT,SRID=8265",
    "pBatchResolution": 3,
    "pIndexingType": "polygon",
    "optNHDPlusDataset": "2.1"
  };

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

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

function 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");

      for (index in srv_areas) {
        tableData.addRows(1);
        var colIndex = 0;
        var shape_area = 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++, shape_area.toString() + " SQKM");
        rowIndex++;
      }

      for (index in srv_lines) {
        tableData.addRows(1);
        var colIndex = 0;
        var f_measure = Math.round(srv_lines[index].fmeasure * 100000) / 100000;
        var t_measure = Math.round(srv_lines[index].tmeasure * 100000) / 100000;
        var shape_length = 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++, f_measure.toString());
        tableData.setCell(rowIndex, colIndex++, t_measure.toString());
        tableData.setCell(rowIndex, colIndex++, shape_length.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 error(XMLHttpRequest, textStatus, errorThrown) {
  alert(textStatus);
  waiting_index.hide();
}

function toggle_draw_polygon() {
  if (drawControls['polygon'].active == true) {
    drawControls['polygon'].deactivate();
  } else {
    drawControls['polygon'].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