1

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>
IvanSanchez
10.4k2 gold badges21 silver badges35 bronze badges
asked Mar 22, 2016 at 20:10

2 Answers 2

2

The createLayer function accepts a map object, not the id of the div element.

answered Mar 23, 2016 at 10:55
1
  • You are correct. Simple mistake on my part. Thank you! Commented Mar 28, 2016 at 21:12
1

You're using cartodb.createLayer() when you really want to use cartodb.createViz(). Double check the documentation.

answered Mar 23, 2016 at 9:23
1
  • 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 here Commented Mar 23, 2016 at 10:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.