0

除了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);
        });
};

我的地图加载了样式,但是当它在一个国家/地区上空时,我的光标不会切换到手指指针,所以当我单击它时没有任何反应。是什么赋予了?

4

1 回答 1

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);
            });
    })

希望有帮助。

于 2015-09-14T17:25:38.870 回答