2

I am able to add and remove cartoDB layers over my google maps but after removing layer the legend stays . how to remove that legends ? here is code that i used

document.getElementById('school').onclick = function()
        {
            var layerUrl = 'http://astrosnehakul123.cartodb.com/api/v2/viz/4c13821a-e192-11e3-8f8f-0e73339ffa50/viz.json';
            if (school.checked)
            {
                        // add cartodb layer 
                      cartodb.createLayer(map, layerUrl)
                      .addTo(map,0)
                      .on('done', function(layer) 
                      {
                        layer1 = layer;
                        var sublayer = layer.getSubLayer(0);
                        sublayer.on( function(e, pos, latlng, data) {
                          cartodb.log.log(e, pos, latlng, data);


                    });

                    sublayer.on('error', function(err) {
                      cartodb.log.log('error: ' + err);
                    });

                  })
                  .on('error', function() {
                    cartodb.log.log("some error occurred");
                  });   
        }
        else{

            layer1.remove();
            layer1.clear();
        }
    }

1 Answer 1

1

just pass legends: false in createLayer options, like:

cartodb.createLayer(map, layerUrl, { legends: false })

0

Your Answer

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

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