A Pen by Nolin D Naidoo on CodePen.
Created
March 24, 2022 19:08
-
-
Save ddrscott/e7f9ae2e63bd5e770dd6cc3cfc583fb8 to your computer and use it in GitHub Desktop.
Simple Leaflet.js Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="map"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize the map and assign it to a variable for later use | |
// there's a few ways to declare a VARIABLE in javascript. | |
// you might also see people declaring variables using `const` and `let` | |
var map = L.map('map', { | |
// Set latitude and longitude of the map center (required) | |
center: [38.89, -77.03], | |
// Set the initial zoom level, values 0-18, where 0 is most zoomed-out (required) | |
zoom: 11 | |
}); | |
// Create a Tile Layer and add it to the map | |
var tiles = new L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', | |
minZoom: '15'}).addTo(map); | |
var marker = L.marker( | |
[38.89, -77.03], | |
{ | |
draggable: true, | |
title: "", | |
opacity: 0.75 | |
}); | |
marker.addTo(map).bindPopup("<p1><b>The White House</b><br>Landmark, historic home & office of the United States president, with tours for visitors.</p1>") .openPopup(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map { | |
height: 100vh; | |
} | |
.leaflet-popup-content-wrapper { | |
width: 100%; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://unpkg.com/[email protected]/dist/leaflet.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment