Wednesday, 29 January 2020

leaflet - Cartodb Layer source object not loading


I have tried to figure out why the layer is not showing up on the map. My code is as follows.


var markersLayerSource = {
user_name: 'someaccount',
type: 'cartodb',
sublayers: [{
sql: baseSql,

https: 'force https',
cartocss: cartoCss,
interactivity: 'cartodb_id'
}]
}

cartodb.createLayer(map, markersLayerSource, {https: true})
.addTo(map)
.on('done', function (layer) {
console.log(layer);

layer.getSubLayer(0).setInteraction(true);
layer.getSubLayer(0).on('featureOver', function(e, pos, pixel, data) {
// print data to console log
console.log("Event #" + data.cartodb_id + ", name " + data.name + ", max population: " + data.pop_max);
});
//layer.getSubLayer(0).show();
//cdb.vis.Vis.addInfowindow(map, layer.getSubLayer(0), ['cartodb_id']);
});

Any one with pointers on why i specifically need to have cdb.viv.Vis.addInfowindow inorder for the layer to show up on the map? Am I doing something wrong if one needs to render without the addinfowindow?




Answer



Please check all the variables you have introduced within your markerLayerSource (the console will tell you what is wrong anyway). I have replicated your code in this working example. But I have used a different methodology to add the tooltip:


var tooltip = layer.leafletMap.viz.addOverlay({
type: 'tooltip',
layer: layer,
template: '

{{name}}

{{pop_max}} inhabitants

',
width: 200,
position: 'bottom|right',
fields: [{ name: 'name' }, { pop_max: 'pop_max' }]
});


$('body').append(tooltip.render().el);

So first, check that all your variables are well declared (baseSql and cartoCss) and secondly, try to use this methodology to add the tooltip. This is a screenshot of the result:


enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...