Skip to content

Instantly share code, notes, and snippets.

@alasarr
Last active August 28, 2017 12:22
Show Gist options
  • Save alasarr/88d82d6799a9d75adef7385671921019 to your computer and use it in GitHub Desktop.
Save alasarr/88d82d6799a9d75adef7385671921019 to your computer and use it in GitHub Desktop.
Postal codes
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Postal Codes</title>
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<link rel="stylesheet" href="main.css" />
</head>
<body>
<div id="map"></div>
<script src="main.js"></script>
</body>
</html>
#map {
height: 100%;
width: 100%;
position: relative;
}
var map = L.map('map', {
center: [40.445379415215285, -3.416748046875],
zoom: 10,
layers: [
L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/{style}/{z}/{x}/{y}.png',{style: 'light_nolabels', zIndex: 0})
]
});
// add cartodb layer with one sublayer
cartodb.createLayer(map, {
user_name: 'alasarr',
type: 'cartodb',
sublayers: [{
sql: `SELECT cartodb_id,cod_postal,the_geom_webmercator,the_geom,(area/60)::integer as clicks FROM alasarr.postal_code_merged`,
cartocss: `#layer {
polygon-fill: ramp([clicks], (#c4e6c3, #80c799, #4da284, #2d7974, #1d4f60), quantiles);
}
#layer::outline {
line-width: 1;
line-color: #FFF;
line-opacity: 0.5;
}`
}]
}, {https: true})
.addTo(map)
.done(function(layer) {
console.log('Yeah!')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment