Skip to content

Instantly share code, notes, and snippets.

@wjdennen
Last active August 29, 2015 14:04
Show Gist options
  • Save wjdennen/b55c93d14d0d5aed30ee to your computer and use it in GitHub Desktop.
Save wjdennen/b55c93d14d0d5aed30ee to your computer and use it in GitHub Desktop.
Simple Leaflet map

Code to create a simple map with Leaflet

$( document ).ready(function() {
var map = L.map('map', {
center: [30, 0],
zoom: 2,
minZoom: 2,
maxZoom: 5,
zoomControl: false,
attributionControl: false,
doubleClickZoom: true,
scrollWheelZoom: false
});
L.tileLayer('http://brown.edu/web/bill/tileserver/files/{z}/{x}/{y}.png', {
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>',
maxZoom: 5,
noWrap: true,
}).addTo(map);
new L.Control.Zoom({ position: 'bottomright' }).addTo(map);
// Internally this function uses the TopoJSON library to decode the given file
// into GeoJSON.
var continentLayer = omnivore.topojson('continents.topo.json')
.addTo(map);
console.log( "ready now!" );
});
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>A Simple Leaflet Map</title>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src='//api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css' rel='stylesheet' />
<!-- added 20140806 -->
<script src='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.1.2/leaflet-omnivore.min.js'></script>
<script src="base.js"></script>
<style>#map { height: 700px; }</style>
</head>
<body>
<div id="map"></div>
</body>
</html>
#map { height: 500px; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment