Skip to content

Instantly share code, notes, and snippets.

@enactdev
Last active October 18, 2016 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enactdev/7d52c904a20c4f70acaf89e0cb505fee to your computer and use it in GitHub Desktop.
Save enactdev/7d52c904a20c4f70acaf89e0cb505fee to your computer and use it in GitHub Desktop.
Display Delaware in a Leaflet map!
This is a basic Leaflet map showing the state of Delaware. It's a mashup of
[Leaflet's Quick Start Guide](http://leafletjs.com/examples/quick-start/) and
[SitePoint's Basic HTML5 Template](https://www.sitepoint.com/a-basic-html5-template/).
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Leaflet Examples</title>
<meta name="description" content="Leaflet Examples">
<meta name="author" content="Open Data Delaware">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
<style>
#mapid {
height: 720px;
width: 350px;
}
</style>
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid').setView([39.12, -75.41], 9);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', {
maxZoom: 18,
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(mymap);
var popup = L.popup();
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(mymap);
}
mymap.on('click', onMapClick);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment