0

I've created a multilayer-geoportal based on that cartodb blog post.

I have it up and running and hosted on my GitHub site, but I'm trying to enable infowindows, and can't get it to work. Cartodb support suggested I add in the following line:

cdb.vis.Vis.addInfowindow(map, layer.getSubLayer(0), ['cartodb_id']);

after I create the layer. However, when I do that, the map doesn't load at all.

Any suggestions on code that I may be missing in my github repository to fix this problem (line 77 in the multilayer.js file is currently commented out).

To view this live, go to andrewmartini.github.io/labs-multilayer/multilayer.html?u=andrewmartini&t=multilayer_test&v=0d192f34-2a79-11e5-8e7c-0e4fddd5de28&tt=Title&d=descr

Note:

I'm new to this forum, forgive me if I've broken any posting rules. Also I would add more links but since I'm new, the system won't let me yet. I'm relatively new to using GitHub and Javascript but very familiar with GIS.

Thanks, Andrew

Manju
  • 668
  • 7
  • 22

1 Answers1

0

So, this answer from folks at Cartodb was a helpful start, and I wanted to share this for others who are experimenting - the line of code from above needed to go inside the addLayer function:

function addLayer(id, show, map) {
    return function (layer) {
        if (!show) {
            layer.hide();
        }
        cdb.vis.Vis.addInfowindow(map, layer.getSubLayer(0), ['cartodb_id'])
        cartodbLayers[id] = layer;
    };
}

And also change this:

                cartodb.createLayer(map, layerOptions)
                    .addTo(map)
                    .done(addLayer(id, layer.show, map))
                    .error(function (error) {
                        console.log("error: " + error);
                    });

But, this still has issues - for instance if you add other columns to the cbd.vis.Vis.addInfowindow function - only the data layers with that column value will load, and all of the others will fail to load. Can anyone tell me how to fix this so that I can add infowindow for selected columns for multiple datasets from my cartodb account/database?