Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <!-- loading screen -->
<div id="back-cover">
   <h1>Map Loading ...</h1>
   <i class="fa fa-circle-o-notch fa-spin fa-3x"></i>   
<!-- container for map -->
<div id="map"></div>
<!-- error message modal -->
<div class="modal fade" id="layerErrorModal" tabindex="-1" role="dialog" aria-labelledby="layerErrorModal" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Error Adding Layers</h4>
      <div id="erMsg" class="modal-body">
         <h4 class="text-danger">Warning: Some layers may not appear on map!</h4>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>        
#map {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;

/* loading screen */
#back-cover {
    background: rgba(191, 191, 191, 1);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    display: -webkit-box;   
    display: -moz-box;      
    display: -ms-flexbox;   
    display: -webkit-flex;  
    display: flex;    
    -webkit-box-orient: vertical;
    -moz-box-orient: vertical;
    -ms-flex-direction: column;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-box-align: center; 
    -moz-box-align: center; 
    -ms-flex-align: center; 
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-pack: center; 
    -moz-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;    
    color: #222;
    z-index: 1500;

#back-cover h1 {
    font-weight: bold;
    font-size: 1.75em;

/* error message modal */
#layerErrorModal {
   display: none;
   z-index: 2000;

.modal-content {
   width: 900px;
   max-width: 100%;
   word-wrap: break-word;
   padding: 15px;
              'use strict';

// Create Map object
var map ='map', {
   center: [40.15, -77.25],
   zoom: 10,               

// Set base map to Open Street Map and add to map 
var osm = L.tileLayer('//{s}{z}/{x}/{y}.png', {
    attribution: '&#169; <a href="">OpenStreetMap</a> contributors, CC BY-SA license'

// Create objects for map services, but don't add to map
// Documentation states that you must add the event listener before adding layer to map
// See
// Hiking Trails - Dynamic Map Layer
var trails = L.esri.dynamicMapLayer({
   // url for service
   url: '//',
   // bad URL to invoke error message
   //url: '//',
   // optional attribution for source of data
   attribution: 'Cumberland County',
   // a property I added to store boolean for whether layer has loaded or not
   // used to remove loading screen
   isLoaded: false

// Municipal Compost Sites - Feature Layer
var compostSites = L.esri.featureLayer({
   // url for service; don't forget number at the end
   url: '//',
   // bad URL to invoke error message
   //url: '//',
   // a property I added to store boolean for whether layer has loaded or not
   // used to remove loading screen
   isLoaded: false

// function to handle load event for map services
// pass in map service object and access properties
// service parameter is map/feature service object
function processLoadEvent(service) {
   // service load event
   service.on('requestsuccess', function(e) {
      console.log('The map service ' + service.options.url + ' has been added to the map');
      // set isLoaded property to true
      service.options.isLoaded = true;      
   // request error event
   service.on('requesterror', function(e) {      
      // if the error url matches the url for the map service, display error messages
      // without this logic, various urls related to the service appear
      if (e.url == service.options.url) {
         // add messages to console
         console.log('There was an error adding ' + e.url + 'to the map');
         console.log('Error code:' + e.code + '; Message: ' + e.message); 
         // set isLoaded property to false
         service.options.isLoaded = false;  
         // add messages to modal window
         var erMsgContent = '<p>There was an error adding ' + e.url + ' to the map</p>';
         erMsgContent += '<p>Error code:' + e.code + '; Message: ' + e.message + '</p>';
         // add error message to modal window
         // show modal window

// Call function to process load/error events
// Trails
// Compost Sites
// Add layers to map

// Function will remove loading screen once layers are added to map 
// loading screen element
var $backCover = $('#back-cover');
// display style property
var $backCoverDisplay = $backCover.css('display');

// test if isLoaded property for both layers is true every 2 seconds
// if it is true for both layers, remove loading screen and remove interval
var loadScreenTimer = window.setInterval(function() {
   // isLoaded property
   var trailsLoaded = trails.options.isLoaded;
   var compostSitesLoaded = compostSites.options.isLoaded;
   if (trailsLoaded && compostSitesLoaded) {
      // remove loading screen after 3 seconds
      window.setTimeout(function() {
      }, 3000); 
      // clear timer
}, 2000);
// Remove loading screen when warning modal is closed
$('#layerErrorModal').on('', function(e) {
   // remove loading screen
   // clear timer
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.