Skip to content

Instantly share code, notes, and snippets.

@jargnar
Created June 4, 2016 08:25
Show Gist options
  • Save jargnar/8125c180707c66d05bf963d5f7e96715 to your computer and use it in GitHub Desktop.
Save jargnar/8125c180707c66d05bf963d5f7e96715 to your computer and use it in GitHub Desktop.
Custom TopoJSON and Leaflet.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Custom map</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
</head>
<body>
<div id="map" style="width: 100%; height: 400px; margin-bottom: 1.5em;"></div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.20/topojson.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script>
var map = L.map('map').setView([25, 80], 4);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
$.getJSON('voro.json', function(topo) {
var geojson = topojson.feature(topo, topo.objects[Object.keys(topo.objects)[0]]);
L.geoJson(geojson, {
style: function(feature) {
return {color: 'green'}
}
}).addTo(map);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment