admin管理员组文章数量:1415111
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 badges2 Answers
Reset to default 4You 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! :)
本文标签: javascriptjVectorMap mark selected stateStack Overflow
版权声明:本文标题:javascript - jVectorMap mark selected state - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745212073a2647948.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论