I'm using kartograph.js and I have an svg of several connected areas/paths and I want to highlight the clicked area by coloring it and then displaying other information about it on another div. I'm having trouble with removing the highlight of a shape when you click a new shape. how can i accomplish this? thanks!
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
II got the ID, I used Layer.getPaths({column:value});