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

              
                <div class="marker-position">click on the map, move the marker, click on the marker</div>
<div id="map"></div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0
}

html {
  height: 100%
}

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

body {
  position: relative;
  display: flex;
  justify-content: center;
  flex-direction: column;
  height: 100%;
  font-family: Lato, sans-serif;
  min-height: 100%;
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  background-color: #f1f1f1;
}


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

JS

              
                /**
 * add move and delete marker
 */

// config map
let config = {
  minZoom: 7,
  maxZomm: 18
};
// magnification with which the map will start
const zoom = 18;
// co-ordinates
const lat = 52.22977;
const lon = 21.01178;

// 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);

// add marker on click
map.on("click", addMarker);

function addMarker(e) {
  // Add marker to map at click location
  const markerPlace = document.querySelector(".marker-position");
  markerPlace.textContent = `new marker: ${e.latlng.lat}, ${e.latlng.lng}`;

  const marker = new L.marker(e.latlng, {
    draggable: true
  })
    .addTo(map)
    .bindPopup(buttonRemove);

  // event remove marker
  marker.on("popupopen", removeMarker);

  // event draged marker
  marker.on("dragend", dragedMaker);
}

const buttonRemove =
  '<button type="button" class="remove">delte marker 💔</button>';

// remove marker
function removeMarker() {
  const marker = this;
  const btn = document.querySelector(".remove");
  btn.addEventListener("click", function () {
    const markerPlace = document.querySelector(".marker-position");
    markerPlace.textContent = "goodbye marker 💩";
    map.removeLayer(marker);
  });
}

// draged
function dragedMaker() {
  const markerPlace = document.querySelector(".marker-position");
  markerPlace.textContent = `change position: ${this.getLatLng().lat}, ${
    this.getLatLng().lng
  }`;
}

              
            
!
999px

Console