vue + echarts + china.js 中國地圖

效果圖


原型


點擊標(biāo)點

1. 引入echarts?

npm install echarts --save

2.在main.js

//?引入echarts

import?echarts?from?'echarts'

Vue.prototype.$echarts?=?echarts

3.在需要引入地圖的頁面

//?引入基本模板

let?echarts?=?require('echarts/lib/echarts')

import?'@/assets/js/china.js'?//?引入中國地圖數(shù)據(jù)

引入的china.js代碼在這里拿? https://blog.csdn.net/qq_42221334/article/details/95493484

4.全部代碼

<template>

??<div?class="post-new">

????<div?class="map-btn">

??????<el-button?class="btn"?type="primary"?size="medium">今年項目</el-button>

??????<el-button?class="btn"?type="primary"?size="medium">全部</el-button>

??????<div?class="year-select">

????????<span>其他年份?:?</span>

??????????<el-date-picker

??????????v-model="value3"

??????????@change="selectChange"

??????????type="year"

??????????placeholder="選擇年">

????????</el-date-picker>

??????</div>

??????<el-button?type="primary"?class="btn"?size="medium">十億以上項目</el-button>

??????<el-button?type="danger"?class="btn"?size="medium">十億以下項目</el-button>

????</div>

????<div?class="Page">

??????<div?id="myChartChina"?ref="myEchart"?:style="{width:?'100%',?height:?'710px'}"></div>

?????????<div?id="box"?v-if="ifbox">

??????????<div?class="box_left">

????????????<div?class="box_title">xxx智慧工地項目?<i?class="el-icon-close?close-box"?@click="closeBox"></i></div>

????????????<div>

??????????????<div>項目詳情</div>

??????????????<div>項目名稱:</div>

??????????????<div>項目編號:</div>

??????????????<div>項目概述:</div>

??????????????<div>項目狀態(tài):</div>

??????????????<div>工地項目管理系統(tǒng):?<el-button?type="primary"?plain?class="btn"?size="mini">點擊進入</el-button></div>

??????????????<div>項目效果圖集:?<el-button?type="primary"?plain?class="btn"?size="mini">點擊進入</el-button></div>

????????????</div>

??????????</div>

??????</div>

??????<!--?<div?class="box_Tips">

????????<p>提示:滾動鼠標(biāo)滾輪控制地圖縮放</p>

??????</div>?-->

??</div>

??</div>

</template>

<script>

//?引入基本模板

let?echarts?=?require('echarts/lib/echarts')

import?'@/assets/js/china.js'?//?引入中國地圖數(shù)據(jù)

export?default?{

??name:?"projectMap",

??components:?{},

??data()?{

????return?{

??????selectVal1:"",

??????ifbox:false,

??????TipsList:[],

??????value3:''

????};

??},

??computed:?{


??},

??watch:?{},

??created()?{},

??mounted()?{

????this.$nextTick(()=>{

??????this.ChinaMap();

????})

??},

??methods:?{

????selectChange(e){

??????console.log(e)

????},

????closeBox(){

??????this.ifbox?=?false

????},

????ChinaMap(){

??????var?that=this;


??????//模擬數(shù)據(jù)

??????let?data?=?[

??????????{name:?'海門',?value:?90?,num:?5,id:8},

??????????{name:?'鄂爾多斯',?value:?102?,?num:?15,?id:16},

??????????{name:?'齊齊哈爾',?value:?140,?num:?30?,id:20}

??????];

??????let?geoCoordMap?=?{

??????????'海門':[121.15,31.89],

??????????'鄂爾多斯':[109.781327,39.608266],

??????????'齊齊哈爾':[123.97,47.33]

??????};


??????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),?

//一定要有value這個字段,?寫法一定要geoCoord.concat(data[i].itemId),

????????????????????num:?geoCoord.concat(data[i].num),

????????????????????id:?geoCoord.concat(data[i].id)

??????????????????});

??????????????}

??????????}

??????????return?res;

??????};

??????let?myChartChina?=?echarts.init(document.getElementById('myChartChina'))?//這里是為了獲得容器所在位置????

????????window.onresize?=?myChartChina.resize;

????????myChartChina.setOption({?//?進行相關(guān)配置

??????????backgroundColor:?'#fff',//地圖背景色

??????????geo:?{?//?這個是重點配置區(qū)

????????????map:?'china',?//?表示中國地圖

????????????label:?{

??????????????normal:{

????????????????show:?true,?//?是否顯示對應(yīng)地名

????????????????textStyle:?{?//字體顏色

??????????????????color:?'#797979'

????????????????}

??????????????},

??????????????emphasis:?{

????????????????show:?false,

????????????????textStyle:?{

??????????????????color:?'#fff'

????????????????}

??????????????}

????????????},

????????????roam:?true,

????????????itemStyle:?{

??????????????normal:?{

????????????????borderWidth:?1,?//?地圖邊框?qū)挾?/p>

????????????????borderColor:?'#474646',?//?地圖邊框顏色

????????????????areaColor:?'#fff'?//?地圖顏色

??????????????},

??????????????emphasis:?{//選中省份的顏色

????????????????areaColor:?'#CCEBEB',

????????????????shadowOffsetX:?0,

????????????????shadowOffsetY:?0,

????????????????shadowBlur:?0,

????????????????borderWidth:?1,

????????????????shadowColor:?'#fff'

??????????????}

????????????}

??????????},

??????????//滑動顯示數(shù)據(jù)

??????????//?tooltip:?{

??????????//?????trigger:?'item',

??????????//?????formatter:?function(params)?{

??????????//?????????return?params.name?+?'?已接入:?'?+?params.data.num[2];

??????????//?????}

??????????//?},

??????????series:?[{

??????????????name:?'散點',

??????????????type:?'scatter',

??????????????coordinateSystem:?'geo',

??????????????//?color:function(params){

??????????????//???var?colorlist?=?['#F56C6C','#409EFF'];

??????????????//???console.log(params)

??????????????//???console.log(params.dataIndex)

??????????????//???return?colorlist[0];

??????????????//?},//點的顏色

??????????????data:?convertData(data),

??????????????symbolSize:?25,//點的大小

??????????????symbol:"pin",//點的樣式

??????????????cursor:"pointer",//鼠標(biāo)放上去的效果

??????????????label:?{

????????????????normal:?{//默認展示

????????????????????show:?false

????????????????},

????????????????emphasis:?{//滑過展示

????????????????????show:?false

????????????????}

??????????????},

??????????????itemStyle:?{

?????????????????color:function(params){

??????????????????var?colorlist?=?['#F56C6C','#409EFF'];

??????????????????console.log(params)

??????????????????console.log(params.dataIndex)?//這里判斷顏色

??????????????????return?colorlist[0];

????????????????},//點的顏色

????????????????emphasis:?{

??????????????????//?borderColor:?'#5c8f6e',

??????????????????//?borderWidth:?5

????????????????}

??????????????}

????????????},


????????????{

??????????????type:?'map',

??????????????map:?'china',

??????????????geoIndex:?0,

??????????????aspectScale:?0.75,

??????????????tooltip:?{

??????????????????show:?false

??????????????}

????????????},


??????????],

????????})

????????//?if?(myChartChina?&&?typeof?myChartChina?===?"object")?{

????????//?????myChartChina.setOption(myChartChina,?true);

????????//?}

????????myChartChina.on('click',?function?(params)?{?//點擊事件

??????????if?(params.componentType?===?'series')?{

????????????if(params.data){

??????????????that.TipsList=params.data

??????????????that.ifbox=true

??????????????that.boxPosition()

????????????}else{

??????????????that.ifbox=false

????????????}

??????????}

????????});

????},

????//點擊地點顯示對應(yīng)位置數(shù)據(jù)

????boxPosition(){

??????var?e?=?event?||?window.event;

??????var?x?=?e.clientX-233+"px"

??????var?y?=?e.clientY-510+"px"

??????clearTimeout(t)

??????var?t?=?setTimeout(function?(){

????????document.getElementById('box').style.top?=?y

????????document.getElementById('box').style.left?=?x?

??????},?50);

??????t

????},

??},

};

</script>

<style?lang="scss"?scoped>

??.map-btn{

????margin:?50px?auto?70px;

????text-align:?center;

????.btn{

??????margin:?0?10px;

????}

????.year-select{

??????display:?inline-block;

??????margin:?0?30px;

????}

??}

??::v-deep{


??}

??.Page{

??position:?relative;

}

.projectList{

??position:?absolute;

??bottom:0;

??left:0;

??z-index:?100;

??width:?280px;

??height:?150px;

??background:?linear-gradient(#1d4978,?#081630);

??display:?flex;

??flex-wrap:wrap;

??justify-content:space-around;

??align-items:center;??

}

.projectList>div{

??width:?120px;

??height:?55px;

}

.projectList>div>p{

??color:?#fff;

??font-size:?16px;

}

.projectList>div>p>i{

??color:?#12baf9;

}

.inputList{

??width:?120px;

??height:?30px;

??background:?#1a3c7b;

??border:?2px?solid?#0f5390;

??margin-top:7px;

??border-radius:?5px;

??letter-spacing:5px;

??color:?#65ddd3;

??line-height:?26px;

??text-indent:?1em;

}


#box{

??width:270px;

??height:?240px;

??line-height:?29px;

??font-size:?14px;

??padding:?5px?15px;

??background:?#fff;

??//?color:?#081630;

??//?background:?#026295;

??box-shadow:?0?0?10px?#3d4141;

??position:?absolute;

??top:10px;

??left:?50%;

??margin-left:?-140px;

}

.box_left{

??width:?239px;

??height:?80px;

??float:?left;

}

.box_title{

??width:?238px;

??height:?30px;

??border-bottom:?1px?solid?#2a2c2c;

??line-height:?30px;

}

.close-box{

??float:?right;

??font-size:?15px;

??margin:?4px;

}

.box_list{

??width:?119px;

??height:?50px;

??float:?left;

}

.box_lists{

??border-left:?1px?solid?#008b9a;

}

.box_list>p:nth-child(1){

??font-size:?20px;

??line-height:?28px;

??color:?yellow;

}

.box_lists>p:nth-child(1){

??color:?rgb(111,?185,?234);

}


.box_right{

??width:?39px;

??height:?80px;

??border-left:?1px?solid?#008b9a;

??float:?left;

}

.box_right?i{

??line-height:?80px;

}

.dilog?{

??/*?width:?180px;?*/

??height:?80px;

??background:?black;

??position:?absolute;

??border-radius:?5px;

??border:?solid?1px?rgb(0,?139,?154);

??z-index:?11111;

??display:?flex;

??box-shadow:?0?0?10px?rgb(0,?139,?154);

}

.dilog_title?{

??text-align:?center;

??height:?30px;

??border-bottom:?solid?1px?grey;

??line-height:?30px;

??color:?white;

}

.box_Tips{

??width:96%;

??height:?20px;

??position:?absolute;

??bottom:?5px;

??right:?5px;

??font-size:?14px;

??color:?#fff;

}

.box_Tips>p{

??white-space:?nowrap;

??position:?absolute;

??top:?0px;

??left:?0;

??animation:mymove?30s?infinite;

}

@keyframes?mymove

{

from?{left:?70%;}

to?{left:?0%;}

}

</style>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末砰奕,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌划纽,老刑警劉巖痊臭,帶你破解...
    沈念sama閱讀 217,907評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件胁后,死亡現(xiàn)場離奇詭異讯泣,居然都是意外死亡,警方通過查閱死者的電腦和手機嫁艇,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,987評論 3 395
  • 文/潘曉璐 我一進店門朗伶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人步咪,你說我怎么就攤上這事论皆。” “怎么了猾漫?”我有些...
    開封第一講書人閱讀 164,298評論 0 354
  • 文/不壞的土叔 我叫張陵点晴,是天一觀的道長。 經(jīng)常有香客問我悯周,道長粒督,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,586評論 1 293
  • 正文 為了忘掉前任禽翼,我火速辦了婚禮屠橄,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘闰挡。我一直安慰自己锐墙,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,633評論 6 392
  • 文/花漫 我一把揭開白布长酗。 她就那樣靜靜地躺著溪北,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上之拨,一...
    開封第一講書人閱讀 51,488評論 1 302
  • 那天茉继,我揣著相機與錄音,去河邊找鬼蚀乔。 笑死馒疹,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的乙墙。 我是一名探鬼主播,決...
    沈念sama閱讀 40,275評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼生均,長吁一口氣:“原來是場噩夢啊……” “哼听想!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起马胧,我...
    開封第一講書人閱讀 39,176評論 0 276
  • 序言:老撾萬榮一對情侶失蹤汉买,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后佩脊,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體蛙粘,經(jīng)...
    沈念sama閱讀 45,619評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,819評論 3 336
  • 正文 我和宋清朗相戀三年威彰,在試婚紗的時候發(fā)現(xiàn)自己被綠了出牧。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,932評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡歇盼,死狀恐怖舔痕,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情豹缀,我是刑警寧澤伯复,帶...
    沈念sama閱讀 35,655評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站邢笙,受9級特大地震影響啸如,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜氮惯,卻給世界環(huán)境...
    茶點故事閱讀 41,265評論 3 329
  • 文/蒙蒙 一叮雳、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧妇汗,春花似錦债鸡、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,871評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至告唆,卻和暖如春棺弊,著一層夾襖步出監(jiān)牢的瞬間晶密,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,994評論 1 269
  • 我被黑心中介騙來泰國打工模她, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留稻艰,地道東北人。 一個月前我還...
    沈念sama閱讀 48,095評論 3 370
  • 正文 我出身青樓侈净,卻偏偏與公主長得像尊勿,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子畜侦,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,884評論 2 354

推薦閱讀更多精彩內(nèi)容