I'm trying to personalize a layer created with CartoDB. The layer is created at runtime and the problem is that I cannot make work even easy things like custom infowindow or legends or click interactions. No errors shown in the js console.
I tried with other layers (the ones used with the CartoDB tutorial) and those are working. What it's wrong with mine?
Here's the code I'm using:
function main() {
var map;
var urbino = new google.maps.LatLng(43.7292108173, 12.6530746836);
var mapOptions = {
zoom: 15,
center: urbino,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
cartodb.createLayer(map, {
user_name: 'my_user',
type: 'cartodb',
infowindow: true,
legends: true,
sublayers: [{
sql: "SELECT * FROM raw_output",
cartocss: '#raw_output { marker-opacity: 0.9;}'
}]
})
.addTo(map)
.on('done', function(layer) {
var sublayer = layer.getSubLayer(0);
sublayer.infowindow.set('template', $('#infowindow_template').html());
sublayer.on('featureClick', function(e, pos, latlng, data) {
alert("Hey! You clicked " + data.cartodb_id);
});
}).on('error', function() {
console.log("some error occurred");
});
}
Seems that using runtime layers is not that flexible as using predefined visualizations with the UI...Am I wrong?
No comments:
Post a Comment