Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Last active September 30, 2016 11:29
Show Gist options
  • Save ramiroaznar/83aab20206e8b870b92f5b7fd9ad1b3f to your computer and use it in GitHub Desktop.
Save ramiroaznar/83aab20206e8b870b92f5b7fd9ad1b3f to your computer and use it in GitHub Desktop.
How to add markers to a CARTO map
<!DOCTYPE html>
<html>
<head>
<title>How to add markers to a CARTO map</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" />
<style>
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
}
</style>
<!-- include cartodb.js CSS library -->
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<!-- include cartodb.js library -->
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script>
</head>
<body>
<div id="map"></div>
<script>
function main() {
var map = new L.Map('map', {
center: [40.7328,-74.0059],
zoom: 14
});
// var layer = L.mapbox.styleLayer('mapbox://styles/fluffywolf24/cimhxr71f0021qxno7nts1d4w', { detectRetina: true });
// layer.addTo(map);
// console.log('map:', map);
L.tileLayer('http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {attribution: 'OpenStreetMaps'
}).addTo(map);
cartodb.createLayer(map, {
user_name: 'whayler1',
type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM ny_listings",
cartocss: '#layer{marker-fill-opacity: 0.7; marker-line-color: #B40903; marker-line-width: 1; marker-line-opacity: 0; marker-placement: point; marker-type: ellipse; marker-width: 1; marker-fill: #F11810; marker-allow-overlap: true; } #layer::point{marker-fill-opacity: 0.4; marker-line-color: #B40903; marker-line-width: 1; marker-line-opacity: 1; marker-placement: point; marker-type: ellipse; marker-width: 7; marker-fill: #F11810; marker-allow-overlap: true; }'}]
})
.addTo(map)
.done(function(layer) {
console.log('done', layer);
layer.createSubLayer({
sql: "SELECT * FROM ny_listings",
cartocss: '#map {marker-fill: #000000;}'
});
});
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment