import React, { Component } from "react";
import Echarts from "echarts";
import "./middle-top.less";
import ningbo from "../../util/ningbo.json";
export default class middleTop extends Component {
componentDidMount() {
let ningboGeo = Echarts.init(document.getElementById("ningboGeo"));
Echarts.registerMap("ningbo", ningbo);
let geoCoordMap = {
海曙: [121.369698, 29.804452],
江北: [121.439282, 29.968361],
北仑: [121.931303, 29.854452],
杭湾: [121.253162, 30.352107],
鄞州: [121.658436, 29.731662],
象山: [121.877091, 29.470206],
宁海: [121.432606, 29.299836],
余姚: [121.206294, 30.045404],
慈溪: [121.448052, 30.177142],
奉化: [121.41089, 29.562348],
镇海: [121.739282, 29.968361],
};
let geoCoordMap1 = {
海曙: [121.239698, 29.804452],
江北: [121.529282, 29.928361],
北仑: [121.801303, 29.854452],
杭湾: [121.103162, 30.352107],
鄞州: [121.558436, 29.731662],
象山: [121.777091, 29.470206],
宁海: [121.332606, 29.299836],
余姚: [121.056294, 30.045404],
慈溪: [121.308052, 30.177142],
奉化: [121.28089, 29.562348],
镇海: [121.639282, 29.968361],
};
let regions = [
{
name: "海曙", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "江北", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "北仑", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "杭湾", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "鄞州", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "象山", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "宁海", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "余姚", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "慈溪", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "奉化", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
{
name: "镇海", //区块名称
itemStyle: {
normal: {
areaColor: "#073978",
},
},
},
];
var data = [
{
name: "海曙",
value: 200,
show: false,
},
{
name: "江北",
value: 39,
show: false,
},
{
name: "镇海",
value: 152,
show: false,
},
{
name: "北仑",
value: 152,
show: false,
},
{
name: "杭湾",
value: 199,
show: false,
},
{
name: "鄞州",
value: 39,
show: false,
},
{
name: "余姚",
value: 152,
show: false,
},
{
name: "慈溪",
value: 152,
show: false,
},
{
name: "奉化",
value: 39,
show: false,
},
{
name: "宁海",
value: 152,
show: false,
},
{
name: "象山",
value: 152,
show: false,
},
];
var convertData = function (data) {
var res = [];
for (var i = 0; i < data.length; i++) {
var geoCoord = geoCoordMap[data[i].name];
if (geoCoord) {
res.push({
name: data[i].name,
value: geoCoord.concat(data[i].value),
});
}
}
return res;
};
var convertData1 = function (data) {
var res = [];
for (var i = 0; i < data.length; i++) {
var geoCoord = geoCoordMap1[data[i].name];
if (geoCoord) {
res.push({
name: data[i].name,
value: geoCoord.concat(data[i].value),
});
}
}
return res;
};
let option = {
tooltip: {
trigger: "item",
formatter: function (params) {
return params.name;
},
},
geo: {
show: true,
map: "ningbo",
label: {
normal: {
show: false,
},
emphasis: {
show: false,
},
},
zoom: 1.2,
roam: true,
itemStyle: {
normal: {
areaColor: "#073978",
borderColor: "#ffffff",
borderWidth: 2,
},
emphasis: {
areaColor: "#2B91B7",
},
},
regions: regions,
},
series: [
{
label: {
normal: {
formatter: "{b}",
position: "right",
show: true,
},
emphasis: {
show: true,
},
},
itemStyle: {
normal: {
color: "#fff",
},
},
name: "light",
type: "scatter",
coordinateSystem: "geo",
data: convertData1(data),
},
{
name: "Top 5",
type: "scatter",
coordinateSystem: "geo",
symbol: "pin",
symbolSize: [50, 50],
label: {
normal: {
show: true,
textStyle: {
color: "#fff",
fontSize: 9,
fontWeight: "bolder",
},
formatter(value) {
return value.data.value[2];
},
},
},
itemStyle: {
normal: {
color: "#00a7d9", //标志颜色
},
},
data: convertData(data),
showEffectOn: "render",
rippleEffect: {
brushType: "stroke",
},
hoverAnimation: true,
zlevel: 1,
},
{
name: "Top 5",
type: "scatter",
coordinateSystem: "geo",
symbol: "pin",
symbolSize: [50, 50],
label: {
normal: {
show: true,
textStyle: {
color: "#fff",
fontSize: 9,
fontWeight: "bolder",
},
formatter(value) {
return value.data.value[2];
},
},
},
itemStyle: {
normal: {
color: "#f6a301", //标志颜色
},
},
data: convertData1(data),
showEffectOn: "render",
rippleEffect: {
brushType: "stroke",
},
hoverAnimation: true,
zlevel: 1,
},
],
};
ningboGeo.setOption(option);
ningboGeo.on("click", function (params) {
regions.map((item) => {
item.itemStyle.normal.areaColor = "#073978";
if (item.name === params.name) {
item.itemStyle.normal.areaColor = "#3e82d5";
}
return true;
});
//逻辑控制
ningboGeo.setOption(option, true);
});
}
render() {
return (
<div className="middleTop">
<div className="middleTop-title f12 flex">
<div className="react">
<span className="text active">历史</span>
</div>
<div className="react">
<span className="text">当月</span>
</div>
</div>
<div className="middleTop-sum ">
<div>历史预警总数</div>
<div className="blod">
<div className="middleTop-box flex">
<div className="middleTop-small bg-orange"></div>
<span className="orange">1375</span>
</div>
<div className="middleTop-box flex">
<div className="middleTop-small bg-blue"></div>
<span className="blue">300</span>
</div>
</div>
</div>
<div className="middleTop-type">
<div className="middleTop-box flex">
<div className="middleTop-small bg-orange"></div>
<span>供电企业预警数</span>
</div>
<div className="middleTop-box flex">
<div className="middleTop-small bg-blue"></div>
<span>产业单位预警数</span>
</div>
</div>
<div
id="ningboGeo"
className="ningboGeo"
style={{ height: "55vh" }}
></div>
</div>
);
}
}
Hi,Athena!
Lifelong learning lifelong benefit
echarts Geo 地图高亮绘制
Athena·2020-07-01·1557 次阅读
Comments | 27 条评论
UeAOO7 It’аs actually a nice and useful piece of information. I’аm satisfied that you shared this useful information with us. Please keep us up to date like this. Thank you for sharing.
Modular Kitchens have changed the very idea of kitchen nowadays since it has provided household females with a comfortable yet a classy place in which they may invest their quality time and space.
It is in fact a cool and beneficial piece of details. I am content which you just shared this practical information and facts with us. Please retain us informed like this. Thank you for sharing.
Some truly great blog posts on this web site , thanks for contribution.
You made some good points there. I did a search on the issue and found most guys will approve with your site.
Nice blog here! Also your website loads up fast! What host are you using? Can I get your affiliate link to your host? I wish my web site loaded up as fast as yours lol
Im obliged for the blog post.Thanks Again. Really Great.
Wow, fantastic weblog format! How lengthy have you ever been blogging for? you made running a blog glance easy. The total glance of your web site is wonderful, let alone the content!
You will be my role models. Many thanks for the post
Thanks for sharing this fine piece. Very interesting ideas! (as always, btw)
very good submit, i definitely love this web site, carry on it
It as hard to come by experienced people on this topic, however, you sound like you know what you are talking about! Thanks
to my friends. I am confident they will be
Some genuinely prime articles on this web site , saved to favorites.
louis vuitton sortie ??????30????????????????5??????????????? | ????????
You have remarked very interesting details ! ps nice web site.
Thanks-a-mundo for the blog post.Really looking forward to read more. Great. sex photos
Wow, this piece of writing is good, my sister is analyzing such things, so I am going to let know her.
Wow, fantastic blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is wonderful, let alone the content!
Thanks a lot for the article. Keep writing.
Very fantastic information can be found on site.
It is truly a nice and helpful piece of info. I am glad that you simply shared this helpful information with us. Please stay us informed like this. Thanks for sharing.
Only wanna input that you have a very nice web site , I like the layout it really stands out.
There is certainly noticeably a bundle to understand about this. I assume you made certain nice points in attributes also.
Very good article. I definitely appreciate this site. Thanks!
Many thanks for sharing this very good post. Very inspiring! (as always, btw)
This site really has all the info I needed concerning this subject and didn at know who to ask.