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://cartodb.com/assets/favicon.ico" />
    <style>
        html, body, #map {
        height: 100%;
        padding: 0;
        margin: 0;
        }
    </style>
    <link rel="stylesheet" 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

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

| improve this answer | |
  • You are correct. Simple mistake on my part. Thank you! – mccook Mar 28 '16 at 21:12
1

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

| improve this answer | |
  • 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 – Jorge Sanz Mar 23 '16 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.