這幾天做了個小項目,關於地圖的。所以使用echart比較多,記錄一下,免得以后忘了。
首先是添加自定義按鈕:引用toolbox對象,官方上的寫的示例很清楚。下面附上寫的代碼
option.toolbox={
orient : 'vertical',
right:'3%',
top:'3%',
itemSize:40,
itemGap:25,
feature: {
myTool1: {
show: true,
title: '返回上級',
icon: 'image://../../img/up.png',
onclick: function (){
if(APP_AREA.level != 'province' ){
var url = window.location.pathname;
window.location = url.substring(0, url.lastIndexOf('/') + 1)
+ APP_AREA.parentId;
}
}
},
myTool2: {
show: true,
title: '返回下級',
icon: 'image://../../img/down.png',
onclick: function (){
if (APP_AREA.level != 'county' ) {
var url = window.location.pathname;
window.location = url.substring(0, url.lastIndexOf('/') + 1)
+ APP_AREA.selectAreaId;
}
}
}
}
}
關於icon屬性,可以用path,url。不過前面的image好像都要有。這兩個按鈕是實現返回上級和下級的。
關於選中地圖在右邊的散點圖上高亮該點顯示出來:循環遍歷一遍,將被選中的id取出來傳到散點圖中:
changeHigh:function(){
for(var i=0;i<PageObject.Xid.length;i++){
if(PageObject.Xid[i]==APP_AREA.selectAreaId){
var num = i;
}
}
this.myChart.dispatchAction({
type: 'downplay',
seriesIndex:0,
});
this.myChart.dispatchAction({
type: 'highlight',
seriesIndex:0,
seriesName:'鄉鎮',
dataIndex:num,
});
},
