Skip to content

Instantly share code, notes, and snippets.

@zross
Created April 1, 2015 15:05
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 zross/1ac4290ee89498288cbd to your computer and use it in GitHub Desktop.
Save zross/1ac4290ee89498288cbd to your computer and use it in GitHub Desktop.
Simple Leaflet with CartoDB tiles
<!DOCTYPE html>
<html>
<head>
<title>Leaflet GeoJSON Example</title>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
<style>
html, body, #map {
height:100%;
width:100%;
padding:0px;
margin:0px;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([38, -96], 5);
L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
maxZoom: 5,
minZoom: 5
}).addTo(map);
var points = new L.geoJson();
points.addTo(map);
$.ajax({
dataType: "json",
url: "temp.geojson",
success: function(data) {
$(data.features).each(function(key, data) {
points.addData(data);
});
}
}).error(function() {});
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "id": 1, "properties": { "finalLoc": "Los Angeles County, California", "popPct": 0.250000 }, "geometry": { "type": "Point", "coordinates": [ -118.2436596, 34.0522265 ] } },
{ "type": "Feature", "id": 2, "properties": { "finalLoc": "Santa Cruz County, California", "popPct": 0.990000 }, "geometry": { "type": "Point", "coordinates": [ -121.9579578, 37.0453988 ] } },
{ "type": "Feature", "id": 3, "properties": { "finalLoc": "Pinellas County, Florida", "popPct": 0.214000 }, "geometry": { "type": "Point", "coordinates": [ -82.7778579, 27.876394 ] } },
{ "type": "Feature", "id": 4, "properties": { "finalLoc": "University of Chicago Cook County, Illinois", "popPct": 0.658000 }, "geometry": { "type": "Point", "coordinates": [ -87.6749647, 41.8730122 ] } },
{ "type": "Feature", "id": 5, "properties": { "finalLoc": "Baltimore, Maryland", "popPct": 0.333000 }, "geometry": { "type": "Point", "coordinates": [ -76.6121893, 39.2903848 ] } },
{ "type": "Feature", "id": 6, "properties": { "finalLoc": "Camden, New Jersey", "popPct": 0.782400 }, "geometry": { "type": "Point", "coordinates": [ -75.1196199, 39.9259463 ] } },
{ "type": "Feature", "id": 7, "properties": { "finalLoc": "Milwaukee, Wisconsin", "popPct": 0.654000 }, "geometry": { "type": "Point", "coordinates": [ -87.9064736, 43.0389025 ] } }
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment