Skip to content

Instantly share code, notes, and snippets.

@ebrelsford
Created April 25, 2014 16:22
Show Gist options
  • Save ebrelsford/11295124 to your computer and use it in GitHub Desktop.
Save ebrelsford/11295124 to your computer and use it in GitHub Desktop.
Leaflet with styled GeoJSON points
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- Load jQuery -->
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<!-- Load Leaflet -->
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<!-- Load Stamen's library -->
<script type="text/javascript" src="http://maps.stamen.com/js/tile.stamen.js?v1.2.4"></script>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
#map {
height: 100%;
width: 100%;
}
</style>
<script>
/*
* Keep the map variable out here so we can access it from
* the console.
*/
var map;
$(document).ready(function () {
map = L.map('map').setView([40.70, -73.96], 11);
var layer = new L.StamenTileLayer("toner");
map.addLayer(layer);
$.getJSON('http://eric.cartodb.com/api/v2/sql?q=SELECT * FROM sign_application_filings&format=GeoJSON', function (data) {
L.geoJson(data, {
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.text_on_sign);
},
/*
* When each feature is loaded from the GeoJSON this
* function is called. Here we create a cicle marker
* for the feature and style the circle marker.
*/
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, {
// Stroke properties
color: '#5EA4D4',
opacity: 0.75,
weight: 2,
// Fill properties
fillColor: '#5EA4D4',
fillOpacity: 0.25,
radius: 2
});
}
}).addTo(map);
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment