I am trying to create a web map that uses a layer hosted on CartoDB and a basemap created in Mapbox studio. Never mind adding the basemap to the L.map, I cannot get the cartoDB layer to draw at all. My code is below (without the Mapbox portion):
<html>
<head>
<title>RCC Global 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://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
</head>
<body>
<div id="map"></div>
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script>
<script>
var map;
function main() {
map = new L.map("map", {
center: [0,0]
zoom: 2
});
cartodb.createLayer("map", 'https://mccook3.cartodb.com/api/v2/viz/3136e62c-98bf-11e5-8d04-0ef24382571b/viz.json')
.addTo(map)
.done(function(layers) {
var sublayer = layers.getSubLayer(0);
subLayer.setInteraction(true);
});
}
window.onload = main;
</script>
</body>
</html>
2 Answers 2
The createLayer
function accepts a map
object, not the id of the div element.
-
You are correct. Simple mistake on my part. Thank you!mccook– mccook2016年03月28日 21:12:54 +00:00Commented Mar 28, 2016 at 21:12
You're using cartodb.createLayer()
when you really want to use cartodb.createViz()
. Double check the documentation.
-
He wants to use the
createLayer
to be able to create first a map by hand and add the mapbox layer before the CartoDB one. Docs hereJorge Sanz– Jorge Sanz2016年03月23日 10:57:09 +00:00Commented Mar 23, 2016 at 10:57