Last active
April 5, 2016 15:37
-
-
Save ramiroaznar/dacb85d6854403376fc3a53872258804 to your computer and use it in GitHub Desktop.
Set sublayer options with CartoDB.js
This file contains 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>Set sublayer options 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 type="text/javascript"> | |
function main() { | |
urlLayer = "https://team.cartodb.com/u/ramirocartodb/api/v2/viz/81e4d0b6-f418-11e5-9f9c-0e5db1731f59/viz.json"; | |
var sublayerOptions = { | |
sql: "SELECT * FROM kachemakbaysp_track_points WHERE cartodb_id < 1000", // select points with id less than 100 | |
cartocss: "#kachemakbaysp_track_points{marker-fill: red; marker-width: 5; marker-line-color: white; marker-line-width: 0;}" // with color red | |
} | |
// center and zoom level | |
var options = { | |
center: [59.5,-151.25], | |
zoom: 10, | |
}; | |
// declare a map object | |
var map = new L.Map('map', options); | |
// add basemap | |
L.tileLayer('http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', { | |
attribution: 'OpenStreetMaps' | |
}).addTo(map); | |
// add layer | |
cartodb.createLayer(map,urlLayer) | |
.addTo(map) | |
.done(function(layer){ | |
layer.getSubLayer(0).set(sublayerOptions); // set layer options | |
}); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment