一次高亮显示一个城市,并在悬停其他城市时删除颜色填充

Highlight one city at a time and remove color fill when other City is hovered on

本文关键字:城市 其他 悬停 删除 填充 颜色 高亮 一次 显示 一个      更新时间:2023-10-09

当另一个城市悬停时,我想删除旧城市的颜色填充。目前,当我悬停在地图上时,它会在悬停时突出显示每个城市。

$('area').hover(function () {
        var coordinates = $(this).attr("coords");
        canvas = document.getElementById("canvas");
        context = canvas.getContext("2d");
        v
    });

好吧,既然你对我的评论发表了评论,我会给你留下我认为可能会解决你问题的代码:

$('area').hover(function () {
        var coordinates = $(this).attr("coords");
        canvas = document.getElementById("canvas");
        context = canvas.getContext("2d");
        context.clearRect ( 0 , 0 , canvas.width, canvas.height );
        var points = coordinatess.split(",");
        context.moveTo(points[0], points[1]);
        for (var i = 0; i < points.length; i += 2) {
         var   x = parseInt(points[i]);
           var y = parseInt(points[i + 1]);
            context.lineTo(x, y);
            context.fillStyle = 'blue';
            context.fill();
        }
    });