jVectorMap:如何将类添加到所选区域

jVectorMap: How do I add a class to the selected region?

本文关键字:区域 添加 jVectorMap      更新时间:2023-09-26

我有以下代码:

onRegionClick: function (event, code) {
    // search for the state based on the code of the region clicked.
    for (var r = 0; r < mapData.stateList.length; r++) {
        if (mapData.stateList[r].state == code) {
            if (mapData.stateList[r].markets.length == 1) {
                // state only has one region - navigate to it.
                window.location = mapData.stateList[r].markets[0].url;
                break;
            } else {
                // state has multiple regions - zoom into it on the map and show the markets.
                $("#map-reset").show();
                $('.map-label').text('Click a city below to view communities in that area.');
                $('body').addClass('map-zoomed');
                showState(code);
                break;
            }
        }
    }
}

如何将类添加到所选区域? 我已经根据通过Google和Stack Overflow发现的类似问题尝试了几种路线,但无济于事。 任何帮助将不胜感激。

检查我的解决方法:

http://pastebin.com/s5GwcEMy

我添加此方法"设置所选区域样式"

您需要获取对地图的引用:

map = $("#world-map-gdp").vectorMap('get', 'mapObject');

设置自定义颜色后:

map.setSelectedRegionStyle('IT', '#b2c9cb'); 

就我而言,只需要更改颜色,但您可以使用火虫检查其他选项。

这是添加的方法(检查过去垃圾箱)

setSelectedRegionStyle : function (r,c) {
return this.regions[r].element.style.selected.fill = c;
},