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>Event Indexing Service - Polygon Example</h2> Add a polygon to the map or enter your NAD83 WKT text:
      <br/>
      <textarea name="wktbox1" id="wktbox1" type="text" class="textbox" style="width: 500px;" id="dzWKT" onchange="updatewkt(this.value);" rows="5"></textarea>
      <br/>
      <br/>
      <input type="button" onclick="run_service();" value="Start Search" id="dz_run_service" />&nbsp;
      <input type="button" onclick="dz_clear();" value="Clear" id="dz_clear_map" />&nbsp;
      <input id="polygon_area" style="width: 80px;" readonly="true" />
    </div>
  </div>
  <div id="output" style="width: 1200px; position: absolute; top: 0; left: 0; margin-top: 400px;">
  </div>
</div>
              
            
!

CSS

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

table {
  width: 1100px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 75%;
}

th, td {
  border: 1px solid black;
  border-collapse: collapse;
}

th, td {
  padding: 5px;
  text-align: left;
}

th {
  font-weight: bold;
}
              
            
!

JS

              
                var wktval, 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
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: true,
    polyline: false,
    rectangle: false,
    circle: false,
    marker: false,
    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 layer = e.layer;
  var type = e.layerType;

  if (type === 'marker') {
    document.getElementById("polygon_area").value = "";
  } else if (type === 'polygon') {
    document.getElementById("polygon_area").value = (LGeo.area(e.layer) / 1000000).toFixed(3) + ' km\u00B2';
  }

  drawnItems.clearLayers();
  wktval = toWKT(layer);
  layer.bindPopup(wktval);

  drawnItems.addLayer(layer);
  document.getElementById("wktbox1").value = wktval;
  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 events = new L.GeoJSON(
  null, {
    onEachFeature: onEachFeature
  }
).addTo(map);

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

var geojsonMarkerOptions = {
  radius: 8,
  fillColor: "#FF0000",
  color: "#000",
  weight: 1,
  opacity: 1,
  fillOpacity: 0.8
};

var eventp = L.geoJson(
  null, {
    pointToLayer: function(feature, latlng) {
      //console.log(feature.properties);
      var marker = L.circleMarker(latlng, geojsonMarkerOptions);
      return marker;
    },
    onEachFeature: onEachFeature
  }
).addTo(map);

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

  var data = {
    "pInputGeometry": wktval,
    "pInputGeometryMod": "WKT,SRSNAME=urn:ogc:def:crs:OGC::CRS84",
    "pBatchResolution": 3,
    "pIndexingType": "polygon",
    "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 + 'EventIndexing.Service', data, evtresponse
  );

}

function evtresponse(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 {
    var srv_points = response.output.point_events;
    var srv_lines = response.output.line_events;
    var srv_areas = response.output.area_events;

    var agg_table = '<P/><TABLE align="center"><TR><TH>Event Geom</TH><TH>Reach Code</TH><TH>From Measure</TH><TH>To Measure</TH><TH>Extent</TH></TR>';

    for (i in srv_points) {
      agg_table = agg_table + '<TR>' +
        '<TD>Point</TD>' +
        '<TD>' + srv_points[i].reachcode + '</TD>' +
        '<TD>' + srv_points[i].measure + '</TD>' +
        '<TD>' + srv_points[i].measure + '</TD>' +
        '<TD>&nbsp;</TD></TR>';
      var tmp_feature = geojson2feature(
        srv_points[i].shape, "<B>Point Event</B><BR/><BR/>" +
        "Reachcode: " + srv_points[i].reachcode + "<BR/>" +
        "Measure: " + srv_points[i].measure + "<BR/>"
      );
      eventp.addData(
        tmp_feature
      )
    }

    for (i in srv_lines) {
      var shape_length = Math.round(srv_lines[i].shape_length * 1000) / 1000;
      agg_table = agg_table + '<TR>' +
        '<TD>Line</TD>' +
        '<TD>' + srv_lines[i].reachcode + '</TD>' +
        '<TD>' + srv_lines[i].fmeasure + '</TD>' +
        '<TD>' + srv_lines[i].tmeasure + '</TD>' +
        '<TD>' + shape_length + '</TD></TR>';
      var tmp_feature = geojson2feature(
        srv_lines[i].shape, "<B>Line Event</B><BR/><BR/>" +
        "Reachcode: " + srv_lines[i].reachcode + "<BR/>" +
        "From Measure: " + srv_lines[i].fmeasure + "<BR/>" +
        "To Measure: " + srv_lines[i].tmeasure + "<BR/>"
      );
      events.addData(
        tmp_feature
      ).setStyle({
        color: "#FF0000",
        fillColor: "#FF0000"
      });
    }

    for (i in srv_areas) {
      var shape_area = Math.round(srv_areas[i].shape_area * 1000) / 1000;
      agg_table = agg_table + '<TR>' +
        '<TD>Area</TD>' +
        '<TD>' + srv_areas[i].reachcode + '</TD>' +
        '<TD>&nbsp;</TD>' +
        '<TD>&nbsp;</TD>' +
        '<TD>' + shape_area + '</TD></TR>';
      var tmp_feature = geojson2feature(
        srv_areas[i].shape, "<B>Area Event</B><BR/><BR/>" +
        "Reachcode: " + srv_areas[i].reachcode + "<BR/>" +
        "Area SqKM: " + shape_area + "<BR/>"
      );
      events.addData(
        tmp_feature
      ).setStyle({
        color: "#FF0000",
        fillColor: "#FF0000"
      });
    }

    document.getElementById("output").innerHTML = agg_table + '</TABLE><P/><P/>';

  }

  busy_off();

}

// Helper function to detect when wkt box is emptied
function onChangeTest(textbox) {
  if (textbox.value != null) {
    wkt = textbox.value;
    document.getElementById("dz_run_service").disabled = false;
  }

}

function updatewkt(wktString) {
  drawnItems.clearLayers();

  if (wktString == null || wktString == undefined || wktString == "") {
    document.getElementById("dz_run_service").disabled = true;

  } else {
    var layer;
    try {
      layer = omnivore.wkt.parse(wktString);
    } catch (layer) {
      alert('Unable to parse WKT geometry.');
      document.getElementById("dz_run_service").disabled = true;
      return null;
    }
    layer.bindPopup(wktString);
    drawnItems.addLayer(layer);
    document.getElementById("dz_run_service").disabled = false;
    wktval = wktString
    map.fitBounds(drawnItems.getBounds(), {
      maxZoom: 11
    });
  }
}

function toWKT(layer) {
  var lng, lat, coords = [];
  if (layer instanceof L.Polygon || layer instanceof L.Polyline) {

    var latlngs = layer.getLatLngs();

    for (var i = 0; i < latlngs[0].length; i++) {
      latlngs[i]
      coords.push(latlngs[0][i].lng + " " + latlngs[0][i].lat);
      if (i === 0) {
        lng = latlngs[0][i].lng;
        lat = latlngs[0][i].lat;
      }
    };

    if (layer instanceof L.Polygon) {
      return "POLYGON((" + coords.join(",") + "," + lng + " " + lat + "))";
    } else if (layer instanceof L.Polyline) {
      return "LINESTRING(" + coords.join(",") + ")";
    }
  } else if (layer instanceof L.Marker) {
    return "POINT(" + layer.getLatLng().lng + " " + layer.getLatLng().lat + ")";
  }
}

// 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 = '';
  events.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