Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过路径id获取元素?_Javascript_Jquery_Gis_Kartograph - Fatal编程技术网

Javascript 如何通过路径id获取元素?

Javascript 如何通过路径id获取元素?,javascript,jquery,gis,kartograph,Javascript,Jquery,Gis,Kartograph,我正在使用kartograph.js,我有一个包含多个连接区域/路径的svg,我想突出显示单击的区域,方法是将其着色,然后在另一个div上显示有关该区域的其他信息。单击新形状时,我很难删除形状的突出显示。我怎样才能做到这一点?谢谢 var previd=0; var prevpath; function mapLoaded(map) { map.addLayer('mylayer', { tooltips: function(d) { return [d.water

我正在使用kartograph.js,我有一个包含多个连接区域/路径的svg,我想突出显示单击的区域,方法是将其着色,然后在另一个div上显示有关该区域的其他信息。单击新形状时,我很难删除形状的突出显示。我怎样才能做到这一点?谢谢

    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

我得到了ID,我使用了Layer.getpath{column:value}



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

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


我得到了它的ID,我使用Layer.getpath{column:value};var templayer=map.getLayer'mylayer'.getpath{watershedname:selected};templayer.forEachfunctionentry{//console.logentry['data'].watershedname;entry['svgPath'].attr'fill','f6f4f2';};