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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.js"></script>

<div class="marker-position">Click/hover on polygon</div>
<div id="map"></div>
              
            
!

CSS

              
                body {
  padding: 0;
  margin: 0;
  position: relative;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

html,
body,
#map {
  height: 100%;
}

.marker-position {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 999;
  padding: 10px;
  font-weight: 700;
  background-color: #fff;
}

              
            
!

JS

              
                /**
 * geoJSON extended action
 */

// config map
let config = {
  minZoom: 4,
  maxZomm: 18
};
// magnification with which the map will start
const zoom = 6;
// co-ordinates
const lat = 51.918904;
const lon = 19.1343786;

// calling map
const map = L.map("map", config).setView([lat, lon], zoom);

// Used to load and display tile layers on the map
// Most tile servers require attribution, which you can set under `Layer`
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
  attribution:
    '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

// adding the province name to the visible div
function addTextToDiv(text) {
  const markerPlace = document.querySelector(".marker-position");
  markerPlace.textContent = text;
}

// showing the name of the province
function getVoivodeshipName(feature, layer) {
  if (feature.properties && feature.properties.name) {
    layer.bindPopup(feature.properties.name);
  }
}

// adding geojson by fetch
// of course you can use jquery, axios etc.
// fetch('./wojewodztwa-medium.geojson')
fetch(
  "https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/poland.geojson"
)
  .then(function (response) {
    return response.json();
  })
  .then(function (data) {
    var layer = new L.GeoJSON(data, {
      // A Function that will be called once for each
      // created Feature, after it has been created and styled
      onEachFeature: function (feature, layer) {
        layer.on("mouseover", function (e) {
          // bindPopup
          getVoivodeshipName(feature, layer);
          // show voivodeship
          addTextToDiv(feature.properties.name);
          this.openPopup();
          // style
          this.setStyle({
            fillColor: "#eb4034",
            weight: 2,
            color: "#eb4034",
            fillOpacity: 0.7
          });
        });
        layer.on("mouseout", function () {
          this.closePopup();
          // style
          this.setStyle({
            fillColor: "#3388ff",
            weight: 2,
            color: "#3388ff",
            fillOpacity: 0.2
          });
        });
        layer.on("click", function () {
          // adding the province name to the visible div
          addTextToDiv(feature.properties.name);
        });
      }
    }).addTo(map);
  });

              
            
!
999px

Console