EDIT: Link to repo containing the files. Open the index.html
file in the imports
and exports
folders.
I can get everything except featurecClick
to work.
My JS:
window.onload = function(){
var cartoDbTableName = 'sipri_import_export_map_1950_2014';
var domId = 'map';
var mapStyle = document.getElementsByClassName('map-style');
var lat = 0;
var lon = 0;
var zoomLvl = 2;
var options = {
center: [lat,lon],
zoom: zoomLvl
};
var mapObject = new L.Map(domId,options);
var layerSource = {
user_name: 'chrismp',
type: 'cartodb',
sublayers: [
{
sql: "SELECT * FROM "+cartoDbTableName+" WHERE (gwsyear <= 1950 AND gwsyear > 0)",
cartocss: mapStyle[0].innerHTML
}
]
};
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')
.addTo(mapObject);
cartodb.createLayer(mapObject,layerSource)
.addTo(mapObject)
.on('done',function(layer){
layer.getSubLayer(0).on('featureClick', function(e, latlng, pos, data, subLayerIndex) {
console.log(e, latlng, pos, data, subLayerIndex);
}).on('error',function(err){
console.log('featureClick error: '+err);
});
}).on('error',function(err){
console.log(err);
});
};
The map loads, but I can't actually click any country. What gives?
subLayerInde
should matchsubLayerIndex
layer.getSubLayer(0).setInteraction(true);
docs.cartodb.com/cartodb-platform/…subLayerInde
typo. I addedsetInteraction(true)
. Still won't work.