Last active
April 5, 2016 13:09
A simple visualization with CartoDB.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>A simple visualization with CartoDB.js</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | |
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" /> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
<style> | |
html, body, #map { | |
width:100%; | |
height:100%; | |
padding: 0; | |
margin: 0; | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script> | |
function main() { | |
// declare a map object | |
var map = new L.Map('map', { | |
center: [37, -84.5], | |
zoom: 7 | |
}); | |
// add basemap | |
L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', { | |
attribution: 'CartoDB' | |
}).addTo(map); | |
// add layer | |
cartodb.createLayer(map, { | |
user_name: 'edwinorange', | |
type: 'cartodb', | |
sublayers: [{ | |
type: "mapnik", | |
sql: "SELECT * FROM carto_db", | |
cartocss: "#carto_db{polygon-fill: red;polygon-opacity: 0.7;line-color: #FFF;line-width: 0.5;line-opacity: 1;}" | |
}] | |
}) | |
.addTo(map) | |
// add sublayer | |
.done(function(layer) { | |
layer.getSubLayer(0).setSQL("SELECT * FROM carto_db LIMIT 10"); | |
}); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment