我可以获得除featurecClick
之外的所有内容。
我的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, subLayerInde);
}).on('error',function(err){
console.log('featureClick error: '+err);
});
}).on('error',function(err){
console.log(err);
});
};
我的地图加载了样式,但我的光标在一个国家/地区时没有切换到手指指针,因此点击它时没有任何反应。是什么给了什么?
答案 0 :(得分:0)
我有类似的问题 - 我觉得CartoDB的文档有点不完整......我相信你需要添加这个:
cdb.vis.Vis.addInfowindow(map, sublayers, [/*ADD DESIRED INFO FIELDS HERE*/]);
例如:
cartodb.createLayer(mapObject,layerSource)
.addTo(mapObject)
.on('done',function(layer){
//ADD THESE TWO LINES HERE
sublayers = layer.getSubLayer(0);
cdb.vis.Vis.addInfowindow(map, sublayers, [/*ADD DESIRED INFO FIELDS HERE*/]);
layer.getSubLayer(0).on('featureClick', function(e, latlng, pos, data, subLayerIndex) {
console.log(e, latlng, pos, data, subLayerInde);
}).on('error',function(err){
console.log('featureClick error: '+err);
});
})
希望有所帮助。