我已经在服务器中实现了这张我们的地图,但我试图根据 mysql 响应更改某些状态的颜色,但我无法做到
这是我的代码
<script type="text/javascript" src="includes/js/jquery-2.1.0.min.js">
</script>
<script src="includes/js/jquery.vmap.js"></script>
<script src="includes/js/jquery.vmap.canada.js"></script>
<script src="includes/js/jquery.vmap.usa.js"></script>
<script>
$(document).ready(function(){
var states_colors = {};
var states = {};
$.post("state_service.php", function(data) {
var states_data = data.split(',');
for (var i = 0; i < states_data.length; i++) {
states[i] = states_data[i].replace(/[""\[\]]+/g, '');
states_colors[i] = states[i]+': #8EE5EE,';
};
console.log(states_colors);
$('#vmap').vectorMap('set', 'colors', states_colors);
});
$('#vmap').vectorMap({
map: 'usa_en',
backgroundColor: null,
color: '#F58025',
hoverColor: '#754200',
selectedColor: '#754200',
enableZoom: false,
showTooltip: false,
onRegionClick: function(element, code)
{
var arr = [];
arr = code.split('-');
var url = 'search.php?';
var query = 'keywords=&city=&state='+arr[1];
window.location.href = url + query;
}
});
});
</script>
<div id="vmap" style="width: 600px; height: 600px;"></div>
这就是 Json 响应给我带来的,这是我想要强调的状态
["AB","CO","UT"]