map.vue
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<template>
<view class="qiun-columns">
<view class="qiun-charts" >
<!--#ifdef MP-ALIPAY -->
<canvas canvas-id="canvasMap" id="canvasMap" class="charts" :width="cWidth*pixelRatio" :height="cHeight*pixelRatio"
:style="{'width':cWidth+'px','height':cHeight+'px'}" @touchstart="touchMap"></canvas>
<!--#endif-->
<!--#ifndef MP-ALIPAY -->
<canvas canvas-id="canvasMap" id="canvasMap" class="charts" @touchstart="touchMap"></canvas>
<!--#endif-->
</view>
</view>
</template>
<script>
import uCharts from '@/components/u-charts/u-charts.js';
import { isJSON } from '@/common/checker.js';
var _self;
var canvaMap=null;
export default {
data() {
return {
cWidth:'',
cHeight:'',
pixelRatio:1,
textarea:''
}
},
onLoad() {
_self = this;
//#ifdef MP-ALIPAY
uni.getSystemInfo({
success: function (res) {
if(res.pixelRatio>1){
//正常这里给2就行,如果pixelRatio=3性能会降低一点
//_self.pixelRatio =res.pixelRatio;
_self.pixelRatio =2;
}
}
});
//#endif
this.cWidth=uni.upx2px(750);
this.cHeight=uni.upx2px(750);
this.getServerData();
},
methods: {
getServerData(){
uni.showLoading({
title:'加载中'
})
uni.request({
url: 'https://geo.datav.aliyun.com/areas_v2/bound/100000_full.json',
data:{
},
success: function(res) {
console.log(res);
uni.hideLoading()
let cMap={series:[]};
//这里我后台返回的是数组,所以用等于,如果您后台返回的是单条数据,需要push进去
// ssssconsole.log(newmap.features)
cMap.series=res.data.features
_self.showMap("canvasMap",cMap);
},
fail: () => {
_self.tips="网络错误,小程序端请检查合法域名";
},
});
},
showMap(canvasId,chartData){
canvaMap=new uCharts({
$this:_self,
canvasId: canvasId,
type: 'map',
fontSize:7,
padding:[0,0,0,0],
legend:{
show:false
},
background:'#FFFFFF',
pixelRatio:_self.pixelRatio,
series: chartData.series,
dataLabel:true,
width: _self.cWidth*_self.pixelRatio,
height: _self.cHeight*_self.pixelRatio,
extra: {
map: {
border:true,
borderWidth:1,
borderColor:'#666666',
fillOpacity:0.6
}
}
});
},
touchMap(e){
canvaMap.showToolTip(e, {
format: function (item) {
return item.properties.name
}
});
}
}
}
</script>
<style>
/*样式的width和height一定要与定义的cWidth和cHeight相对应*/
.qiun-charts {
width: 750upx;
height: 750upx;
background-color: #FFFFFF;
}
.charts {
width: 750upx;
height: 750upx;
background-color: #FFFFFF;
}
</style>