简体   繁体   English

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

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

I have the below code: 我有以下代码:

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;
            }
        }
    }
}

How would I add a class to the selected region? 如何将课程添加到所选区域? I have tried several routes based on similar questions found through Google and Stack Overflow to no avail. 我已经根据通过Google和Stack Overflow找到的类似问题尝试了几种路线,但均无济于事。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

Check my way to fix it: 检查我的解决方法:

http://pastebin.com/s5GwcEMy http://pastebin.com/s5GwcEMy

i add this method "setSelectedRegionStyle" 我添加此方法“ setSelectedRegionStyle”

You need get reference to the map: 您需要参考地图:

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

After you can set your custom color: 设置自定义颜色后:

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

In my case only need change the color, but you can use the firebug to check the another options. 就我而言,只需更改颜色即可,但您可以使用萤火虫检查其他选项。

This is the added method (Check in the pastbin) 这是添加的方法(在Pastbin中检查)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM