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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


                <!DOCTYPE html>
<html lang="en">

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Search bar -->
  <div class="input-group">
    <input type="text" class="form-control" id="searchTerm" placeholder="Search Bar">
    <div class="input-group-append">
      <button class="btn btn-info" type="button" id="searchBtn" onclick="search();">Search</button>
<!-- /Search bar -->

<!-- Panel button -->
  <button type="button" id="panelBtn" class="btn btn-primary mt-5" onclick="togglePanel();">Open Panel ></button>
<!-- /Panel button -->
<!-- Panel --> 
  <div id="panel">
    <!-- Dissmiss button to close Sidepanel -->
    <button class="btn btn-secondary" type="button" id="closeBtn" onclick="closePanel();">
    <p id="panelContent">
    <h2 id="panelTitle">Title</h2>
    <span id="panelText">Text</span>    
<!-- /Panel -->  

<!-- Map -->
  <div id="mapDemo">
    <!-- Map markers -->
<!-- /Map -->




                /* Basic settings for map */
#mapDemo {
  width: 100vw;
  height: 100vh;

/* Search bar */
  z-index: 401; /* minimum z-index for content to sit on top of map */
  width: 100vw;

@media only screen and (min-width: 501px) {
    .input-group {
        width: 500px;
} /* expand search bar to 100vw on small screens */

/* Open/close panel button */
  z-index: 401;
} /* allows panel button to sit on top of content */

  position: fixed;
  z-index: 401;
  width: 100vw;
  left: -500px;
  bottom: 0;
  overflow-y: scroll;
  background: #FFFFFF;
  transition: all 0.3s; /* gives a "sliding" effect */

@media only screen and (min-width: 500px) {
    #panel {
        width: 500px;
        left: -500px;
} /* expand sidebar to 100vw on small screens (when active) */ {
    left: 0;
} /* show sidebar when active, see JS */

/* Autocomplete */


                // Create map
map ='mapDemo', {
  minZoom: 4,
  maxZoom: 6

// Place Zoom Control at screen bottom right of the screen

// Define map bounds so that it fits data coordinates
var bounds = [[-10,-10], [10,10]];

// Create a dictionary of markers, with IDs (key), coordinates and content (value)
var markers = {'id1':{'title':'Marker 1','coords':[1,0],'description':'Text for marker 1'}, 'id2':{'title':'Marker 2','coords':[4,2],'description':'Text for marker 2'}, 'id3':{'title':'Marker 3','coords':[8,8],'description':'Text for marker 3'}}

// Define all variables
var layers = L.layerGroup().addTo(map);
var titlesList = [];  
var idToLayer = {};
var titleToId = {};
var idToTitle = {};
var idToText = {};

// Declare updatePanel: open panel, update panel button inner HTML and update content with updateContent(), depending on mId
var updatePanel = function(mId){
  // Open panel
  // Update Open/Close Panel button on map
  $("#panelBtn").text('< Close Panel');
  // Store marker title and text in variables
  var markerTitle = idToTitle[mId];
  var markerText = idToText[mId];
  // Update panel content with marker title and text

// Declare markerOnClick: 
var markerOnClick = function(){
  // Store markerId
  var mId = this.options.markerId;
  // Store marker title & update seach placeholder
  var markerTitle = idToTitle[mId];
  // Update Panel

// Loop through the dictionary, define coordinates & marker options and add markers to the map
$.each(markers, function(key, val) {
  var markerOptions = {markerId: key,
                       markerTitle: val['title'],
                       markerText: val['description']};

  // Plot markers on the map 
  var marker = L.marker(val['coords'], markerOptions).addTo(map);

  // Set popup options
  var popupContent = val['title'];
  // Bind popup to marker click

  // Create a list of marker titles 

  // Call markerOnClick when event click on marker 
  marker.on('click', markerOnClick);

  // Create a layer for each marker that is part of the feature group of layers  

  // -- Append dictionaries --
  titleToId[val['title']] = key;
  idToTitle[key] = val['title'];  
  // {key:id,value:'text'}  
  idToText[key] = val['description'];


// loup through and append dictionnary of {key:id,value:layerId} 
$.each(layers._layers, function(key,val){
  idToLayer[val.options.markerId] = key;

$(function() {
     source: titlesList,
     minLength: 1, // minimum number of characters required to trigger autocomplete
     select: function(event, ui) { // update the input field and run the search function on select

// Search function
var search = function(){
   $("#searchTerm").blur(); //close autocomplete after click event
   // get value from search field
   var markerTitle = $("#searchTerm").val();
   var markerId = titleToId[markerTitle];

   // find the corresponding layer and open the marker popup on the map
   var layerId = idToLayer[markerId];
   var layer = layers._layers[layerId];

   // open panel and display marker info

// Open/Close button (map): toggle panel & update #panelBtn
var togglePanel = function() {
  $("#panelBtn").text(($("#panelBtn").text() == 'Open Panel >') ? '< Close Panel' : 'Open Panel >'); 

// Close button (panel): close panel & update #panelBtn
var closePanel = function() {
  $('#panelBtn').text('Open Panel >');