2014-12-05 25 views
1

我使用的是kartograph.js,我有几个连接区域/路径的svg,我想突出显示点击区域的颜色,然后在另一个div上显示关于它的其他信息。点击新形状时,我无法消除形状的突出显示。我怎么能做到这一点?谢谢!kartograph.js如何通过路径ID获取元素?

var previd=0; 
var prevpath; 


function mapLoaded(map) { 
    map.addLayer('mylayer', { 

    tooltips: function(d) { 
    return [d.watershedname,"area: "+d.area]; 
    }, 


    styles: { 
     stroke: '#aaa', 
     fill: '#f6f4f2' 
    }, 

click: function(d, path) { 
     // @path is a Raphael.element, do with it whatever you like 
     // @d holds the data attached to each path 

    //retrieve and set text to other div 
    $("#infoname").text(d.watershedname); 
    $("#infoarea").text(numberWithCommas(Math.floor(d.area))+" hectares"); 
    //highlight the selected path 
    path.attr('fill', 'red'); 



    //i'm trying to get the previous path by id here 
    //so i can remove the previous highlight 
    //doesn't work 

    prevpath =mylayer.getById(previd); 
    prevpath.attr('fill','blue'); 

    //set the new id for later access 
    previd=path.attr('id'); 

    } 

});//end of add layer 


}//end of mapLoaded 
+0

我知道了ID,我使用了Layer.getPaths({column:value}); var templayer = map.getLayer('mylayer')。getPaths({watershedname:selected}); templayer.forEach(函数(条目){ //console.log(entry['data'].watershedname); 条目[ 'svgPath'] ATTR( '填充', '#f6f4f2'); }); – boydukot 2014-12-10 02:26:35

回答

0

II获得了ID,我使用了Layer.getPaths({column:value});



    var templayer = map.getLayer('mylayer').getPaths({watershedname:selected}); 

    templayer.forEach(function(entry) { 
     entry['svgPath'].attr('fill','#f6f4f2'); 
    });