Skip to content

Instantly share code, notes, and snippets.

@RikdeBoer
Created December 21, 2019 03:42
Show Gist options
  • Save RikdeBoer/368cef8516e9707af84b7af71b0a36f1 to your computer and use it in GitHub Desktop.
Save RikdeBoer/368cef8516e9707af84b7af71b0a36f1 to your computer and use it in GitHub Desktop.
Leaflet: basic map
<!DOCTYPE html>
<html lang="en">
<head>
<title>Leaflet - Basic map</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Find latest version at: https://leafletjs.com/download.html -->
<link href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" rel="stylesheet" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
</head>
<body>
<div id="map-placeholder" style="height:400px"></div>
<script>
const center = [-37.8178, 144.968]
const markerOptions = { draggable: true }
const myMap = L.map('map-placeholder').setView(center, 9)
const myMarker = L.marker(center, markerOptions).addTo(myMap)
myMarker
.bindPopup('I am the default marker, an<br/>image with transparency (.png).<br/><br/>You can drag me.')
.openPopup()
myMap.addLayer(L.tileLayer(
'https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}@2x.png',
{ attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contr.' }
))
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment