1

I have created a few visualizations in cartodb, and I'm trying to create a html with some buttons to select each one.

I have seen some examples using createlayer and sublayers, but not using different viz.jon.

I am a rookie, and I would like that someone to give me a simple example to start developing.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 4, 2016 at 19:36

1 Answer 1

1

I may be missing something, but you could simply have different buttons that trigger createVis() for different vis.json files

One hangup may be removing existing visualizations when a new button is clicked. The code here does this in a brute force way with a jQuery $.empty() on #map. There may be a built in CartoDB method for this (?) not sure. Have not tested any of this...

html

<button data-url="http://account.cartodb.com/yourvis1.json">vis #1</button>
<button data-url="http://account.cartodb.com/yourvis2.json">vis #2</button>
<button data-url="http://account.cartodb.com/yourvis3.json">vis #3</button>

javascript/jQuery

$(document).ready(function(){
 $('button').on('click', function(){
 $('#map').empty();
 var url = $(this).data().url;
 cartodb.createVis('map', url);
 });
});
answered Jan 5, 2016 at 23:59
0

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.