@林峰,请问map,如何设置点击“北京”不出现北京市地图,其他省份可以显示?
我在代码里面做了判断: for (var i = 0, l = option.series[0].data.length; i < l; i++) { name = option.series[0].data[i].name; option.series[0].data[i].selected = selected[name]; if (selected[name]) { if(name!='北京'&&name!='上海'&&name!='天津'&&name!='重庆'){ selectedProvince = name; }else{ getZhixiaCityInfo(name); } } }
对于北京,天津,重庆,上海四个直辖市,我点击的时候直接调用方法getZhixiaCityInfo(name);而不是跳到下级城市去,我现在这样确实实现了,但是会报错:Cannot read property 'getGeoJson' of undefined ,我看了下echarts-original-map.js,把'北京': { getGeoJson: function (callback) { require(['./geoJson/bei_jing_geo'], function (md){ callback(decode(md)); }); } },去掉,仍然会报错,报错的语句出现在else if (_mapParams[mt.replace(/|.*/, '')].getGeoJson) {,请问可否有解决方案?
关键是点击北京后你的实例渲染什么了?这错误发生在你指定了一个不存在的地图类型,mapType
var option = { tooltip : { trigger: 'item' }, dataRange:{ calculable : false, min: 0, max: 1000, color: ['#FF7F50','#FFC125','#8DD0ED','#BCEE68'], splitNumber:4 }, legend:{ x:'right', data:['报警数据'] }, textStyle:{ fontSize:28, fontWeight:'bolder' }, series : [ { name: '报警数', type: 'map', mapType: 'china', mapLocation: { x: 'left', y: 'top', width: '95%' }, itemStyle: { emphasis:{label:{show:true}}, normal: { borderWidth:0.5, borderColor:'white', label: { show:true } } }, markPoint : { symbolSize: 12, // 标注大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2 itemStyle: { normal: { label: { show: true } } },
data : [
<#list provinceCountList as provinceCount>
<#if (provinceCount.alertCount>1000)>
{name: '${(provinceCount.provinceName)}',value: ${(provinceCount.alertCount)}}
<#if provinceCount_has_next>,</#if>
</#if>
</#list>
]
},geoCoord : {
"北京":[116.46,39.92], // 支持数组[经度,维度]
"上海": {x: 121.48, y: 31.22}, // 支持对象{x:经度,y:纬度}
"天津": {x: 117.2, y: 39.12},
"河北": {x: 115.52, y: 38.05},
"山西": {x: 112.55, y: 37.87},
"内蒙古": {x: 111.73, y: 41.83},
"辽宁": {x: 123.43, y: 41.8},
"吉林": {x: 125.32, y: 43.9},
"黑龙江": {x: 126.53, y: 47.8},
"江苏": {x: 119.78, y: 33.07},
"浙江": {x: 120.15, y: 29.28},
"安徽": {x: 117.25, y: 31.83},
"福建": {x: 119.3, y: 26.08},
"江西": {x: 115.85, y: 28.68},
"山东": {x: 116.98, y: 36.67},
"河南": {x: 113.62, y: 34.75},
"湖北": {x: 114.3, y: 30.6},
"湖南": {x: 111.93, y: 28.23},
"广东": {x: 113.27, y: 23.13},
"广西": {x: 108.37, y: 22.82},
"海南": {x: 110.32, y: 19.68},
"重庆": {x: 106.55, y: 29.57},
"四川": {x: 104.07, y: 30.67},
"贵州": {x: 106.63, y: 26.65},
"云南": {x: 102.72, y: 25.05},
"西藏": {x: 91.13, y: 29.65},
"陕西": {x: 108.93, y: 34.27},
"甘肃": {x: 103.82, y: 36.07},
"青海": {x: 97.37, y: 37.37},
"宁夏": {x: 106.28, y: 38.47},
"新疆": {x: 87.62, y: 43.82},
"澳门": {x: 113.33, y: 22.13},
"台湾": {x: 121.5, y: 25.03}
},
selectedMode : 'single',
data:[
<#list provinceCountList as provinceCount>
{name: '${(provinceCount.provinceName)}',value: ${(provinceCount.alertCount)}}
<#if provinceCount_has_next>,</#if>
</#list>
]
}
],
animation: false
};
var fileLocation1 = '${basePath}/plugin/echarts-2.0.2/build/echarts';
var fileLocation = '${basePath}/plugin/echarts-2.0.2/build/echarts-original-map';
require.config({
paths:{
'echarts': fileLocation1,
'echarts/chart/map': fileLocation,
}
});
var pcChart;
var myChart;
var colorList;
var ecConfig;
var provinceData=[
<#list cityCountList as alert>
{name: '${(alert.citycn)}市',value: ${(alert.alertCount)}}
<#if alert_has_next>,</#if>
</#list>
];
require(
[
'echarts',
'echarts/chart/map'
],
function(ec) {
colorList = require('zrender/tool/color').getGradientColors(
['red','yellow','lightskyblue'], 10
);
myChart = ec.init(document.getElementById('main_china'));
myChart.setOption(option);
window.onresize = myChart.resize;
ecConfig = require('echarts/config');
//点击地图发生操作
myChart.on(ecConfig.EVENT.MAP_SELECTED, function (param){
var selected = param.selected;
var selectedProvince;
var selectedCity;
var name;
$("#chinaShow").attr("style","");
if((typeof option.series[0].data)!='undefined'){
for (var i = 0, l = option.series[0].data.length; i < l; i++) {
name = option.series[0].data[i].name;
option.series[0].data[i].selected = selected[name];
if (selected[name]) {
if(name!='北京'&&name!='上海'&&name!='天津'&&name!='重庆'){
selectedProvince = name;
}else{
getZhixiaCityInfo(name);
}
}
}
}
option.series[0] = {
type: 'map',
mapType: 'china',
mapLocation: {
x: 'left',
y: 'bottom',
width: '0%'
},
data:[
<#list provinceCountList as provinceCount>
{name: '${(provinceCount.provinceName)}',value: ${(provinceCount.alertCount)}}
<#if provinceCount_has_next>,</#if>
</#list>
]
};//将大地图缩小
option.series[1] = {};
option.series[1] = {
name: '报警数',
selectedMode:'single',
type: 'map',
mapType: selectedProvince,
itemStyle:{
normal:{label:{show:true}},
emphasis:{label:{show:true}}
},
mapLocation: {
x: 'center',
y: 'top',
width: '95%'
},
roam: true,
data:provinceData
};
if((typeof option.series[1])!='undefined'){
for (var i = 0, l = option.series[1].data.length; i < l; i++) {
name = option.series[1].data[i].name;
//alert(name);
option.series[1].data[i].selected = selected[name];
if (selected[name]) {//某个市被选择之后下面的代码可以写个ajax
selectedCity = name;
getCityInfo(name);
}
}
}
myChart.setOption(option, true);
});
}
); 这是我的完整的js
看不过来,想想setOption时的mapType是否内置了就好。 另外你为啥两个js都引?-map已经包含了所有。
刚才我根据你给的提示用一个很笨的方法暂时解决了问题,谢谢林峰哈
no thx~