javascript - jVectorMap mark selected state - Stack Overflow

i found the plugin jVectorMap and i'm trying to mark the state that i selected with a diferente co

i found the plugin jVectorMap and i'm trying to mark the state that i selected with a diferente color

the same way that hover happens, but i what i want is, when clicked, the state keep "active" with some color.

the plugin have some actions like onRegionClick:

$('#map-teste').vectorMap({
    map: 'br_en',
    onRegionClick: function(event, code){
        alert(code); // return the state
    }
});

but i dont have any idea how to do this.

anyone achieve this ?

i found the plugin jVectorMap and i'm trying to mark the state that i selected with a diferente color

the same way that hover happens, but i what i want is, when clicked, the state keep "active" with some color.

the plugin have some actions like onRegionClick:

$('#map-teste').vectorMap({
    map: 'br_en',
    onRegionClick: function(event, code){
        alert(code); // return the state
    }
});

but i dont have any idea how to do this.

anyone achieve this ?

Share Improve this question edited Mar 29, 2012 at 14:33 fglez 8,5524 gold badges50 silver badges78 bronze badges asked Jan 23, 2012 at 18:04 Ricardo BinnsRicardo Binns 3,2466 gold badges45 silver badges71 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You can set the color for selected regions by adding regionStyle config parameters to the instantiation of your map. You would also want to set the regionSelectable to true:

$('#map-teste').vectorMap({
    map: 'br_en',
    onRegionClick: function(event, code){
        alert(code); // return the state
    },
    regionsSelectable: true,
    regionStyle: {
        selected: {
            fill: 'orange'
        }
    }
});

You can do this:

$('#map-teste').vectorMap({
    map: 'br_en',
    onRegionClick: function(event, code){
        $('#map-teste').vectorMap('set', 'colors', code, '#000000');
        alert(code); // return the state
    }
});

Works fine for me. This would result in multiple selections with no toggling. If you need it 'toggled' for a 'single-selection' effect, you could do it like this:

currentSelected = '';
defaultColor = '#00FF00';
selectedColor = '#FF00FF'; 
maphandle = $('#map-teste'); 

maphandle.vectorMap({
    map: 'br_en',
    onRegionClick: function(event, code){
        if(currentSelected !== code) {
            if(currentSelected !== ''){
                // Deselect, then select new choice
                maphandle.vectorMap('set', 'colors', currentSelected, defaultColor);
                maphandle.vectorMap('set', 'colors', code, selectedColor);
                currentSelected = code;
            } else {
                // Nothing currently selected, go ahead and select
                maphandle.vectorMap('set', 'colors', code, selectedColor);
                currentSelected = code;
            }
        } else {
            // Deselect
            maphandle.vectorMap('set', 'colors', code, defaultColor);
            currentSelected = '';
        }
        alert(code); // return the state
    }
});

Hope that helps! :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745212073a4616902.html

相关推荐

  • javascript - jVectorMap mark selected state - Stack Overflow

    i found the plugin jVectorMap and i'm trying to mark the state that i selected with a diferente co

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信