3

I am trying to remove the legend associated with the current CartoDB generated map and replace it with a legend from a map generated when the user selects a radio button. My code is as follows:

function showMap(radioButton, currentLayer, currentMap, mapUrl) {

        if (radioButton.checked == true) {
            if (currentMap.viz != null) {
                var vis = currentMap.viz;
                vis.legends.getLegendByIndex(0).remove();
            }

            cartodb.createLayer(currentMap, mapUrl)
            .addTo(currentMap)

            .on('done', function(layer) {       
                //do stuff
                currentLayer=layer

                .on('featureOver', function(e, latlng, pos, data) {
                    console.log(e, latlng, pos, data);
                })  
            })

            .on('error', function(err) {
                alert("some error occurred: " + err);
            }); 
        } <!--end function-->
        else {
            currentLayer.hide();
        }
    }

Your Answer

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

Browse other questions tagged or ask your own question.