配置项如下
echarts.registerMap('hjkj', {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"adcode": 500120,
"name": "璧山区",
"center": [106.231126, 29.593581],
"centroid": [106.191948, 29.561371],
"childrenNum": 0,
"level": "district",
"acroutes": [100000, 500000],
"parent": {
"adcode": 500000
}
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[106.253436, 29.532845],
[106.252214, 29.530547],
[106.253394, 29.529068],
[106.253123, 29.525006],
[106.253282, 29.519712],
[106.254339, 29.518093],
[106.261983, 29.51651],
[106.262674, 29.51665],
[106.264309, 29.518348],
[106.265389, 29.520737],
[106.267514, 29.520955],
[106.268193, 29.519524],
[106.267508, 29.517687],
[106.264971, 29.513557],
[106.263511, 29.510264],
[106.262605, 29.506729],
[106.261894, 29.500252],
[106.260991, 29.497328],
[106.260589, 29.494278],
[106.261442, 29.490426],
[106.262737, 29.490226],
[106.263422, 29.490954],
[106.265386, 29.49455],
[106.26701, 29.495005],
[106.267435, 29.492379],
[106.266845, 29.490189],
[106.264638, 29.486993],
[106.264292, 29.484906],
[106.26616, 29.48339],
[106.268694, 29.483177],
[106.27183, 29.483432],
[106.272795, 29.482571],
[106.273804, 29.480545],
[106.273023, 29.47884],
[106.271389, 29.477845],
[106.270031, 29.477888],
[106.267303, 29.479623],
[106.265271, 29.480205],
[106.263725, 29.479453],
[106.262483, 29.477894],
[106.261475, 29.474667],
[106.261518, 29.473344],
[106.26277, 29.46934],
[106.262325, 29.46806],
[106.260266, 29.466034],
[106.260658, 29.462187],
[106.261535, 29.460021],
[106.263923, 29.455683],
[106.264177, 29.454324],
[106.262724, 29.451599],
[106.260849, 29.45055],
[106.2605, 29.448929],
[106.258042, 29.442394],
[106.256642, 29.439172],
[106.25568, 29.437563],
[106.252267, 29.433406],
[106.250046, 29.431149],
[106.24863, 29.429255],
[106.247631, 29.426761],
[106.246781, 29.421583],
[106.246129, 29.413759],
[106.245549, 29.40988],
[106.243665, 29.402996],
[106.24212, 29.39848],
[106.238509, 29.389573],
[106.229979, 29.372177],
[106.228424, 29.368187],
[106.2259, 29.360025],
[106.22363, 29.353988],
[106.222069, 29.35123],
[106.217499, 29.345612],
[106.214985, 29.34467],
[106.211974, 29.343042],
[106.210702, 29.341676],
[106.209091, 29.339064],
[106.206047, 29.334805],
[106.202875, 29.332631],
[106.195725, 29.327448],
[106.17662, 29.308431],
[106.170911, 29.304755],
[106.16443, 29.302476],
[106.163261, 29.302245],
[106.160167, 29.302853],
[106.157446, 29.302804],
[106.156085, 29.301972],
[106.154777, 29.29849],
[106.153505, 29.29649],
[106.153235, 29.294491],
[106.152283, 29.293665],
[106.150886, 29.294266],
[106.147819, 29.294169],
[106.14631, 29.292394],
[106.145401, 29.292686],
[106.143391, 29.296594],
[106.142541, 29.296539],
[106.140841, 29.295172],
[106.137513, 29.29564],
[106.136403, 29.294844],
[106.138604, 29.291799],
[106.138673, 29.290705],
[106.137296, 29.290602],
[106.135214, 29.29158],
[106.134295, 29.291416],
[106.134028, 29.289465],
[106.131616, 29.288158],
[106.129587, 29.286384],
[106.126256, 29.286682],
[106.124098, 29.286293],
[106.123119, 29.285089],
[106.122589, 29.283485],
[106.12363, 29.281187],
[106.120082, 29.278877],
[106.117565, 29.280002],
[106.114563, 29.282154],
[106.113288, 29.284013],
[106.111812, 29.289404],
[106.111223, 29.292753],
[106.110432, 29.29491],
[106.109193, 29.29539],
[106.10752, 29.295354],
[106.104426, 29.294655],
[106.103144, 29.293737],
[106.10065, 29.29076],
[106.098687, 29.290091],
[106.096101, 29.291361],
[106.086128, 29.297955],
[106.084668, 29.300313],
[106.0854, 29.302415],
[106.08652, 29.303856],
[106.086362, 29.307064],
[106.084504, 29.31026],
[106.08201, 29.313183],
[106.072927, 29.32099],
[106.06616, 29.323384],
[106.063438, 29.323609],
[106.058045, 29.322467],
[106.051571, 29.323269],
[106.046132, 29.325012],
[106.04344, 29.325498],
[106.044458, 29.327351],
[106.044155, 29.329781],
[106.045921, 29.332236],
[106.047463, 29.336506],
[106.04969, 29.340625],
[106.050003, 29.341864],
[106.049248, 29.349408],
[106.04823, 29.35174],
[106.048369, 29.353247],
[106.049637, 29.35485],
[106.051311, 29.356217],
[106.055759, 29.36127],
[106.060038, 29.366827],
[106.062921, 29.372401],
[106.065606, 29.37579],
[106.06639, 29.379342],
[106.065494, 29.384758],
[106.065468, 29.386307],
[106.066331, 29.389282],
[106.067833, 29.390933],
[106.06781, 29.391929],
[106.066703, 29.393987],
[106.064687, 29.395402],
[106.062641, 29.396148],
[106.061442, 29.398826],
[106.061712, 29.401752],
[106.06106, 29.402899],
[106.059745, 29.402784],
[106.058552, 29.401752],
[106.057709, 29.401752],
[106.055933, 29.403015],
[106.055815, 29.403816],
[106.057772, 29.406135],
[106.060127, 29.406942],
[106.062773, 29.406918],
[106.065313, 29.408466],
[106.065794, 29.409231],
[106.064235, 29.411343],
[106.064453, 29.41606],
[106.063652, 29.418961],
[106.065873, 29.424533],
[106.067375, 29.426415],
[106.067342, 29.430475],
[106.070212, 29.43553],
[106.071325, 29.439081],
[106.071526, 29.441975],
[106.070802, 29.444378],
[106.071385, 29.445895],
[106.073256, 29.448857],
[106.073681, 29.451672],
[106.073319, 29.45524],
[106.072014, 29.456842],
[106.071484, 29.458905],
[106.071813, 29.461489],
[106.073918, 29.464305],
[106.075829, 29.468345],
[106.076211, 29.470377],
[106.075414, 29.472847],
[106.075351, 29.474594],
[106.077015, 29.483359],
[106.078013, 29.491184],
[106.078152, 29.493331],
[106.077997, 29.497638],
[106.076969, 29.502574],
[106.076771, 29.507002],
[106.077753, 29.511871],
[106.07919, 29.515692],
[106.081822, 29.519621],
[106.082389, 29.520816],
[106.082916, 29.523423],
[106.083038, 29.527267],
[106.085976, 29.530578],
[106.087027, 29.535501],
[106.088698, 29.541224],
[106.089142, 29.546401],
[106.089976, 29.547832],
[106.088003, 29.549741],
[106.087238, 29.552293],
[106.08796, 29.554633],
[106.089663, 29.556658],
[106.091903, 29.558179],
[106.09443, 29.55821],
[106.096262, 29.559683],
[106.100328, 29.567138],
[106.104828, 29.576029],
[106.105853, 29.578635],
[106.107048, 29.583071],
[106.108274, 29.589076],
[106.109108, 29.592045],
[106.110063, 29.593833],
[106.111964, 29.595765],
[106.11231, 29.601455],
[106.113091, 29.602988],
[106.115348, 29.605793],
[106.117568, 29.610076],
[106.117664, 29.611348],
[106.116675, 29.613935],
[106.113941, 29.615692],
[106.113769, 29.616268],
[106.115018, 29.618461],
[106.117552, 29.624645],
[106.119113, 29.627813],
[106.119799, 29.63003],
[106.12077, 29.634567],
[106.121775, 29.63722],
[106.122731, 29.638807],
[106.125577, 29.639655],
[106.126167, 29.640206],
[106.129237, 29.64777],
[106.130087, 29.648872],
[106.13586, 29.653396],
[106.139546, 29.658029],
[106.142943, 29.661395],
[106.144814, 29.662952],
[106.147592, 29.664671],
[106.150649, 29.665919],
[106.154105, 29.666088],
[106.156698, 29.667293],
[106.161109, 29.674171],
[106.16448, 29.674528],
[106.165804, 29.675776],
[106.165613, 29.678585],
[106.162875, 29.68005],
[106.163241, 29.681327],
[106.16473, 29.683416],
[106.166081, 29.683967],
[106.168232, 29.687532],
[106.169313, 29.689881],
[106.168812, 29.692139],
[106.16669, 29.695596],
[106.163692, 29.700093],
[106.163294, 29.701885],
[106.161735, 29.702206],
[106.156925, 29.701515],
[106.155861, 29.702526],
[106.156092, 29.704003],
[106.156154, 29.70936],
[106.156856, 29.710431],
[106.158918, 29.712349],
[106.16105, 29.718686],
[106.163442, 29.721101],
[106.164595, 29.727128],
[106.163719, 29.729839],
[106.164562, 29.734074],
[106.166354, 29.73739],
[106.166387, 29.74073],
[106.167412, 29.745595],
[106.168848, 29.749182],
[106.169369, 29.751475],
[106.169072, 29.752576],
[106.165939, 29.754355],
[106.160793, 29.759709],
[106.160454, 29.760834],
[106.161788, 29.761983],
[106.164638, 29.762425],
[106.167385, 29.763774],
[106.168555, 29.765461],
[106.171925, 29.76779],
[106.176544, 29.76972],
[106.178538, 29.769889],
[106.180537, 29.771559],
[106.182844, 29.774795],
[106.185209, 29.778544],
[106.187443, 29.780722],
[106.194576, 29.785385],
[106.196733, 29.786461],
[106.202331, 29.788366],
[106.206403, 29.789171],
[106.211701, 29.791553],
[106.216527, 29.794462],
[106.219772, 29.797032],
[106.222451, 29.797957],
[106.226915, 29.800769],
[106.231132, 29.803944],
[106.233043, 29.805691],
[106.246824, 29.820075],
[106.254141, 29.827801],
[106.258319, 29.831361],
[106.260559, 29.835424],
[106.264885, 29.840948],
[106.267906, 29.844418],
[106.274868, 29.850909],
[106.281579, 29.857291],
[106.286946, 29.861811],
[106.29083, 29.865244],
[106.298589, 29.871498],
[106.301695, 29.873722],
[106.307846, 29.879329],
[106.312577, 29.882314],
[106.314416, 29.884869],
[106.317387, 29.881788],
[106.318504, 29.878441],
[106.322043, 29.875105],
[106.325657, 29.872731],
[106.3271, 29.870139],
[106.327377, 29.867268],
[106.326507, 29.864271],
[106.329396, 29.859654],
[106.330556, 29.859642],
[106.334565, 29.861304],
[106.336384, 29.860228],
[106.336618, 29.858059],
[106.335689, 29.856004],
[106.331824, 29.851121],
[106.331014, 29.849712],
[106.330961, 29.84834],
[106.333521, 29.848086],
[106.335287, 29.847319],
[106.335791, 29.845173],
[106.336924, 29.845052],
[106.338585, 29.845651],
[106.341725, 29.845856],
[106.343154, 29.844533],
[106.342456, 29.842532],
[106.337577, 29.834541],
[106.337705, 29.833731],
[106.339609, 29.832443],
[106.340562, 29.832371],
[106.342439, 29.833175],
[106.345059, 29.835744],
[106.345876, 29.836113],
[106.347345, 29.83465],
[106.347121, 29.833997],
[106.344047, 29.831652],
[106.342683, 29.827033],
[106.342518, 29.822402],
[106.343125, 29.819283],
[106.342308, 29.817348],
[106.342439, 29.81655],
[106.346406, 29.813019],
[106.349062, 29.812155],
[106.351279, 29.812409],
[106.353595, 29.814754],
[106.355664, 29.815299],
[106.358263, 29.815377],
[106.361588, 29.813678],
[106.363337, 29.813255],
[106.368338, 29.813968],
[106.372354, 29.814307],
[106.372506, 29.813243],
[106.37047, 29.811296],
[106.36452, 29.804361],
[106.359107, 29.79751],
[106.349078, 29.785596],
[106.344377, 29.782899],
[106.344222, 29.779307],
[106.337946, 29.773119],
[106.335656, 29.771819],
[106.333481, 29.771268],
[106.332309, 29.77154],
[106.330131, 29.772901],
[106.328757, 29.774988],
[106.327087, 29.775502],
[106.324283, 29.774837],
[106.322883, 29.773452],
[106.321091, 29.770046],
[106.317819, 29.767827],
[106.316495, 29.76649],
[106.315981, 29.764899],
[106.315991, 29.761493],
[106.315747, 29.759031],
[106.313398, 29.754657],
[106.312406, 29.752443],
[106.312709, 29.750925],
[106.310726, 29.748583],
[106.307629, 29.743979],
[106.306374, 29.740936],
[106.305112, 29.733602],
[106.304315, 29.730492],
[106.3024, 29.725403],
[106.29958, 29.71664],
[106.298091, 29.710982],
[106.297067, 29.706454],
[106.296632, 29.705419],
[106.295073, 29.703634],
[106.294029, 29.703289],
[106.291716, 29.703852],
[106.290438, 29.705565],
[106.289248, 29.705395],
[106.287901, 29.703876],
[106.287143, 29.701528],
[106.288145, 29.699306],
[106.287387, 29.697908],
[106.285611, 29.697914],
[106.28316, 29.69956],
[106.281743, 29.702992],
[106.280449, 29.703289],
[106.280205, 29.700529],
[106.280459, 29.697448],
[106.280343, 29.69516],
[106.278152, 29.693386],
[106.278119, 29.691709],
[106.279101, 29.690826],
[106.27837, 29.684693],
[106.278406, 29.679111],
[106.278693, 29.676684],
[106.280004, 29.675194],
[106.281612, 29.675497],
[106.283463, 29.67652],
[106.284501, 29.675285],
[106.284228, 29.67023],
[106.284445, 29.668667],
[106.287733, 29.665289],
[106.28769, 29.663503],
[106.285638, 29.660057],
[106.285071, 29.657865],
[106.284402, 29.656854],
[106.281628, 29.656484],
[106.280403, 29.655419],
[106.279411, 29.652536],
[106.27924, 29.647007],
[106.280004, 29.644397],
[106.281282, 29.643289],
[106.28401, 29.642968],
[106.287278, 29.641914],
[106.28966, 29.640224],
[106.290158, 29.638976],
[106.289565, 29.637214],
[106.288148, 29.636033],
[106.285723, 29.636015],
[106.282307, 29.637468],
[106.279118, 29.637832],
[106.277187, 29.636723],
[106.27524, 29.633967],
[106.273049, 29.631623],
[106.273787, 29.630388],
[106.275299, 29.629146],
[106.278508, 29.627323],
[106.281299, 29.627129],
[106.282758, 29.626148],
[106.282271, 29.624839],
[106.277882, 29.620338],
[106.276976, 29.618436],
[106.27582, 29.61425],
[106.274897, 29.612227],
[106.273682, 29.610852],
[106.272456, 29.610276],
[106.26986, 29.610203],
[106.2676, 29.608525],
[106.265584, 29.60589],
[106.263142, 29.600716],
[106.260016, 29.592615],
[106.259617, 29.590966],
[106.25938, 29.587573],
[106.258948, 29.585064],
[106.256332, 29.577762],
[106.256296, 29.575217],
[106.259222, 29.572489],
[106.260177, 29.571253],
[106.25991, 29.57058],
[106.257884, 29.569477],
[106.257156, 29.569501],
[106.254942, 29.570817],
[106.254072, 29.569768],
[106.25344, 29.567914],
[106.252007, 29.562277],
[106.25171, 29.559422],
[106.251763, 29.546001],
[106.251311, 29.543928],
[106.25111, 29.539332],
[106.251657, 29.53712],
[106.253436, 29.532845]
]
]
]
}
}]
});
var geoCoordMap = {
'北碚': [106.252214, 29.800547],
'城口': [106.280004, 29.675194],
'大足': [106.273049, 29.631623],
'垫江': [106.22638, 29.387573],
'丰都': [106.252007, 29.562277],
'教委': [106.231126, 29.593581],
};var hjDatas = [
[{
name: '北碚',
value: 5
}],
[{
name: '垫江',
value: 1
}]
];
var convertData = function(data) {
var res = [];
for (var i = 0; i < data.length; i++) {
var dataItem = data[i];
var fromCoord = geoCoordMap[dataItem[0].name];
var toCoord = [106.231126, 29.593581];
if (fromCoord && toCoord) {
res.push([{
coord: fromCoord,
value: dataItem[0].value
}, {
coord: toCoord
}]);
}
}
return res;
};
var series = [];
[
['教委', hjDatas]
].forEach(function(item, i) {
console.log(item)
series.push({
type: 'lines',
zlevel: 2,
effect: {
show: true,
period: 4, //箭头指向速度,值越小速度越快
trailLength: 0.02, //特效尾迹长度[0,1]值越大,尾迹越长重
symbol: 'arrow', //箭头图标
symbolSize: 15, //图标大小
},
lineStyle: {
normal: {
width: 1, //尾迹线条宽度
opacity: 1, //尾迹线条透明度
curveness: .1 //尾迹线条曲直度
}
},
data: convertData(item[1])
}, {
type: 'effectScatter',
coordinateSystem: 'geo',
zlevel: 2,
rippleEffect: { //涟漪特效
period: 4, //动画时间,值越小速度越快
brushType: 'stroke', //波纹绘制方式 stroke, fill
scale: 8 //波纹圆环最大限制,值越大波纹越大
},
label: {
normal: {
show: true,
position: 'right', //显示位置
offset: [5, 0], //偏移设置
formatter: function(params) { //圆环显示文字
return params.data.name;
},
fontSize: 16
},
emphasis: {
show: true
}
},
symbol: 'circle',
symbolSize: function(val) {
return 5 + val[2] * 2; //圆环大小
},
itemStyle: {
normal: {
show: false,
color: '#f00'
}
},
data: item[1].map(function(dataItem) {
return {
name: dataItem[0].name,
value: geoCoordMap[dataItem[0].name].concat([dataItem[0].value])
};
}),
},
//被攻击点
{
type: 'effectScatter',
coordinateSystem: 'geo',
zlevel: 2,
rippleEffect: {
period: 4,
brushType: 'image',
scale: 8
},
label: {
normal: {
show: true,
position: 'right', //显示位置
offset: [5, 0], //偏移设置
formatter: function(params) { //圆环显示文字
return params.data.name;
},
fontSize: 16
},
emphasis: {
show: true
}
},
symbol: 'circle',
symbolSize: function(val) {
return 2 + val[2] * 2; //圆环大小
},
itemStyle: {
normal: {
show: false,
color: '#0f0'
}
},
data: [{
name: item[0],
value: geoCoordMap[item[0]].concat([10]),
}],
}
);
});
option = {
tooltip: {
trigger: 'item',
backgroundColor: 'rgba(166, 200, 76, 0.82)',
borderColor: '#FFFFCC',
showDelay: 0,
hideDelay: 0,
enterable: true,
transitionDuration: 0,
extraCssText: 'z-index:100',
formatter: function(params, ticket, callback) {
//根据业务自己拓展要显示的内容
var res = "";
var name = params.name;
var value = params.value[params.seriesIndex + 1];
res = "<span style='color:#fff;'>" + name + "</span><br/>数据:" + value;
return res;
}
},
backgroundColor: "#013954",
geo: {
map: 'hjkj',
zoom: 1.2,
label: {
emphasis: {
show: false
}
},
roam: true, //是否允许缩放
itemStyle: {
normal: {
color: 'rgba(51, 69, 89, .5)', //地图背景色
borderColor: '#516a89', //省市边界线00fcff 516a89
borderWidth: 1
},
emphasis: {
color: 'rgba(37, 43, 61, .5)' //悬浮背景
}
}
},
series: series
};