# 八.geo

# 1.json 方案

  • 中国地图

查看代码详情
<template>
  <WebMap :config="getOptions" :data="data" @changeData="getData"> </WebMap>
</template>

<script>
export default {
  data() {
    return {
      data: [],
    };
  },
  created() {
    this.getData(5);
  },
  methods: {
    async getData(url) {
      let res = await this.$api.getMap(url);
      if (res.data) {
        this.data = res.data.map((item) => ({ ...item, value: item.descript }));
      }
    },
    getOptions(data) {
      return {
        title: {
          text: "json地图",
          subtext: "单位:元",
        },
        geo: {
          roam: true,
          map: "china",
          zoom: 1,
          scaleLimit: {
            min: 1,
            max: 20,
          },
          ...{
            // 普通样式
            label: {
              show: true,
              color: "rgba(130,143,200,1)",
            },
            itemStyle: {
              show: true,
              borderWidth: 1,
              borderColor: "rgba(196,207,254,1)",
              areaColor: "rgba(229,236,249,1)",
            },
          },
          emphasis: {
            // hover样式
            label: {
              show: true,
              color: "rgba(130,143,200,1)",
            },
            itemStyle: {
              borderColor: "rgba(196,207,254,1)",
              borderWidth: 1,
              areaColor: "rgba(229,236,249,1)",
            },
          },
          ...{
            // 选中样式
            selectedMode: "single",
            select: {
              label: {
                color: "rgba(255,255,255,1)",
              },
              itemStyle: {
                areaColor: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    { offset: 0, color: "rgba(66,99,232,1)" },
                    { offset: 1, color: "rgba(55,183,249,1)" },
                  ],
                  
                },
              },
            },
            regions: [
              {
                name: "南海诸岛",
                ...{
                  // 普通样式
                  label: {
                    show: true,
                    color: "rgba(130,143,200,1)",
                  },
                  itemStyle: {
                    show: true,
                    borderWidth: 1,
                    borderColor: "rgba(196,207,254,1)",
                    areaColor: "rgba(229,236,249,1)",
                  },
                },
                emphasis: {
                  // hover样式
                  label: {
                    show: true,
                    color: "rgba(130,143,200,1)",
                  },
                  itemStyle: {
                    borderColor: "rgba(196,207,254,1)",
                    borderWidth: 1,
                    areaColor: "rgba(229,236,249,1)",
                  },
                },
              },
              ...data.map((item) => {
                return {
                  ...item,
                  label: {
                    color: "re96cc34d",
                  },
                  itemStyle: {
                    areaColor: "#96cc34",
                  },
                };
              }),
            ],
          },
        },
      };
    },
  },
};
</script>
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
124
125
126
127
128
129

# 2.svg 方案

  • 中国地图

查看代码详情
<template>
  <WebMap
    :config="getOptions"
    :data="data"
    @mapBeforeMount="beforeHandle"
    @changeData="getData"
  ></WebMap>
</template>
<script>
export default {
  data() {
    return {
      data: [],
    };
  },
  created() {
    this.getData(1);
  },
  methods: {
    async getData(url) {
      let res = await this.$api.getMap(url);
      if (res.data) {
        this.data = res.data.map((item) => ({ ...item, value: item.descript }));
      }
    },
    beforeHandle(echarts) {
      echarts.registerMap("svgmap", this.$zhongguosvg);
    },
    getOptions(data, Map) {
      return {
        title: {
          text: "svg地图",
          subtext: "单位:元",
        },
        geo: [
          {
            tooltip: {
              formatter: function (params) {
                return [
                  '<div style="max-width:200px;">' + params.des + "</div>",
                ];
              },
            },
            top: 90,
            map: "svgmap",
            roam: true,
            zoom: 1.1,
            scaleLimit: {
              min: 1,
              max: 9,
            },
            ...{
              // 普通样式
              label: {
                show: true,
                color: "rgba(130,143,200,1)",
              },
              itemStyle: {
                borderWidth: 1,
                borderColor: "rgba(196,207,254,1)",
                areaColor: "rgba(229,236,249,1)",
              },
            },
            emphasis: {
              // hover样式
              label: {
                show: true,
                color: "rgba(130,143,200,1)",
              },
              itemStyle: {
                borderColor: "rgba(196,207,254,1)",
                borderWidth: 1,
                areaColor: "rgba(229,236,249,1)",
              },
            },
            ...{
              // 选中样式
              selectedMode: "single",
              select: {
                label: {
                  color: "#333",
                },
                itemStyle: {
                  areaColor: {
                    type: "linear",
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      { offset: 0, color: "rgba(66,99,232,1)" },
                      { offset: 1, color: "rgba(55,183,249,1)" },
                    ],
                    
                  },
                },
              },
            },
          },
        ],
        series: [
          {
            geoIndex: 0,
            type: "effectScatter",
            coordinateSystem: "geo",
            symbolSize: function (val) {
              return [6, 3];
            },
            showEffectOn: "render",
            zlevel: 2,
            rippleEffect: {
              period: 2.5, //波纹秒数
              brushType: "stroke", //stroke(涟漪)和fill(扩散),两种效果
              scale: 6, //波纹范围
            },
            hoverAnimation: true,
            label: {
              formatter: function ({ data }) {
                return "{text|" + data.name + "}";
              },
              distance: 18,
              position: "top",
              show: true,
              textStyle: {
                rich: {
                  text: {
                    fontSize: 14, //字体大小
                    color: "#023AFD",
                    backgroundColor: "lightgray",
                    padding: [4, 4, 4, 4],
                  },
                },
              },
            },
            itemStyle: {
              color: "#0579FA", //字体和点颜色
            },
            data: data.map((item) => {
              let value = Map.convertToPixel("geo", item.value);
              let [x, y] = value;
              return {
                ...item,
                value: [2 * x + 110, 3 * y + 4],
                label: {
                  formatter: "{b}",
                  color: "red",
                },
                itemStyle: {
                  color: "#96cc34",
                },
              };
            }),
          },
        ],
      };
    },
  },
};
</script>
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  • 中国地图二

查看代码详情
  <template>
    <WebMap
      :config="getOptions"
      :data="data"
      @mapBeforeMount="beforeHandle"
      @changeData="getData"
    ></WebMap>
  </template>
  <script>
  export default {
    data() {
      return {
        data: [],
      };
    },
    created() {
      this.getData(1);
    },
    methods: {
      async getData(url) {
        let res = await this.$api.getMap(url);
        if (res.data) {
          this.data = res.data.map((item) => ({ ...item, value: item.descript }));
        }
      },
      beforeHandle(echarts) {
        echarts.registerMap("svgmap", this.$zhongguosvg2);
      },
      getOptions(data, Map) {
        return {
          title: {
            text: "svg地图",
            subtext: "单位:元",
          },
          geo: {
            tooltip: {
              formatter: function (params) {
                return [
                  '<div style="max-width:200px;">' + params.des + "</div>",
                ];
              },
            },
            map: "svgmap",
            roam: true,
            ...{
              // 普通样式
              label: {
                show: false,
                color: "rgba(130,143,200,1)",
              },
              itemStyle: {
                borderWidth: 1,
                borderColor: "rgba(196,207,254,1)",
                areaColor: "rgba(229,236,249,1)",
              },
            },
            emphasis: {
              // hover样式
              label: {
                show: true,
                color: "rgba(130,143,200,1)",
              },
              itemStyle: {
                borderColor: "rgba(196,207,254,1)",
                borderWidth: 1,
                areaColor: "rgba(229,236,249,1)",
              },
            },
            ...{
              // 选中样式
              selectedMode: "single",
              select: {
                label: {
                  color: "#333",
                },
                itemStyle: {
                  areaColor: {
                    type: "linear",
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      { offset: 0, color: "rgba(66,99,232,1)" },
                      { offset: 1, color: "rgba(55,183,249,1)" },
                    ],
                    
                  },
                },
              },
            },
            regions: [
              ...data.map((item) => {
                return {
                  ...item,
                  label: {
                    color: "re96cc34d",
                  },
                  itemStyle: {
                    areaColor: "#96cc34",
                  },
                };
              }),
            ],
          },
          series: [
            {
              geoIndex: 0,
              type: "effectScatter",
              coordinateSystem: "geo",
              symbolSize: function (val) {
                return [6, 3];
              },
              showEffectOn: "render",
              zlevel: 2,
              rippleEffect: {
                period: 2.5, //波纹秒数
                brushType: "stroke", //stroke(涟漪)和fill(扩散),两种效果
                scale: 6, //波纹范围
              },
              hoverAnimation: true,
              label: {
                formatter: function ({ data }) {
                  return "{text|" + data.name + "}";
                },
                distance: 18,
                position: "top",
                show: true,
                textStyle: {
                  rich: {
                    text: {
                      fontSize: 14, //字体大小
                      color: "#023AFD",
                      backgroundColor: "lightgray",
                      padding: [4, 4, 4, 4],
                    },
                  },
                },
              },
              itemStyle: {
                color: "#0579FA", //字体和点颜色
              },
              data: data.map((item) => {
                let value = Map.convertToPixel("geo", item.value);
                let [x, y] = value;
                return {
                  ...item,
                  value: [2 * x + 110, 3 * y + 4],
                  label: {
                    formatter: "{b}",
                    color: "red",
                  },
                  itemStyle: {
                    color: "#96cc34",
                  },
                };
              }),
            },
          ],
        };
      },
    },
  };
  </script>
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  • 省级地图

查看代码详情
  <template>
    <WebMap
      :config="getOptions"
      :data="data"
      @mapBeforeMount="beforeHandle"
      @changeData="getData"
    ></WebMap>
  </template>
  <script>
  export default {
    data() {
      return {
        data: [],
      };
    },
    created() {
      this.getData(1);
    },
    methods: {
      async getData(url) {
        let res = await this.$api.getMap(url);
        if (res.data) {
          this.data = res.data.map((item) => ({ ...item, value: item.descript }));
        }
      },
      beforeHandle(echarts) {
        echarts.registerMap("svgmap", this.$beijingsvg);
      },
      getOptions(data, Map) {
        return {
          title: {
            text: "svg地图",
            subtext: "单位:元",
          },
          tooltip: {
            show: true,
            formatter: function (params) {
              var tipHtml = "";
              tipHtml =
                "<div >" +
                '    <div style="height:50px;width:100%;border-radius:5px;background:#F8F9F9;border-bottom:1px solid #F0F0F0">' +
                '        <span style="line-height:50px;margin-left:18px">' +
                params.name +
                "</span>" +
                '        <span style="float:right;line-height:50px;margin-right:18px;color:#5396E3;cursor:pointer" onclick="mapTooltipClick(this);">点击查看详情</span>' +
                "    </div>" +
                '    <div style="height:110px;width:100%;background:#fff">' +
                '        <div style="padding-left:18px;padding-top:22px">' +
                '            <span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:rgba(92,169,235,1)"></span> ' +
                "            <span>上传表格数量</span>" +
                '            <span style="float:right;margin-right:18px">' +
                "params.data.tipData[0]" +
                "万</span>" +
                "        </div>" +
                '        <div style="padding-left:18px;padding-top:14px">' +
                '            <span style="display:inline-block;margin-right:5px;width:10px;height:10px;background-color:rgba(92,169,235,1)"></span> ' +
                "            <span>上传数据条数</span>" +
                '            <span style="float:right;margin-right:18px">' +
                "params.data.tipData[1]" +
                "条</span>" +
                "        </div>" +
                "    </div>";
              ("</div>");
              return tipHtml;
            },
            position: function (point, params, dom, rect, size) {
              var x = 0;
              var y = 0;
              var pointX = point[0];
              var pointY = point[1];
              var boxWidth = size.contentSize[0];
              var boxHeight = size.contentSize[1];
              if (boxWidth > pointX) {
                x = pointX + 10;
              } else {
                x = pointX - boxWidth - 5;
              }
              if (boxHeight > pointY) {
                y = 5;
              } else {
                y = pointY - boxHeight;
              }
              return [x, y];
            },
          },
          geo: {
            map: "svgmap",
            roam: true,
            zoom: 0.2,
            // layoutCenter: ["70%", "70%"],
            // 设定坐标系大小
            // top:-100,
            // left:0,
            // layoutSize: 300,
            // center: [116.410886, 389.881949],
            // center:[0,0],
            boundingCoords: [
              // 定位左上角经纬度
              [-180, 90],
              // 定位右下角经纬度
              [180, -90],
            ],
            ...{
              // 普通样式
              label: {
                show: true,
                color: "rgba(130,143,200,1)",
              },
              itemStyle: {
                borderWidth: 1,
                borderColor: "rgba(196,207,254,1)",
                areaColor: "rgba(229,236,249,1)",
              },
            },
            emphasis: {
              // hover样式
              label: {
                show: true,
                color: "rgba(130,143,200,1)",
              },
              itemStyle: {
                borderColor: "rgba(196,207,254,1)",
                borderWidth: 1,
                areaColor: "rgba(229,236,249,1)",
              },
            },
            ...{
              // 选中样式
              selectedMode: "single",
              select: {
                label: {
                  color: "#333",
                },
                itemStyle: {
                  areaColor: {
                    type: "linear",
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      { offset: 0, color: "rgba(66,99,232,1)" },
                      { offset: 1, color: "rgba(55,183,249,1)" },
                    ],
                    
                  },
                },
              },
            },
          },
          series: {
            type: "effectScatter",
            coordinateSystem: "geo",
            geoIndex: 0,
            symbolSize: 5,
            showEffectOn: "render",
            zlevel: 1,
            rippleEffect: {
              period: 6,
              scale: 3,
              brushType: "stroke",
            },
            hoverAnimation: true,
            label: {
              formatter: function (params) {
                return params.data.name;
              },
              fontSize: 16,
              position: "right",
              offset: [15, 0],
              color: "#fff",
              show: true,
            },
            itemStyle: {
              color: "#fff",
              shadowBlur: 20,
            },
            symbolSize: 10,
            data: data.map((item) => {
              let value = Map.convertToPixel("geo", item.value);
              let [x, y] = value;
              return {
                ...item,
                value,
                label: {
                  formatter: "{b}",
                  color: "red",
                },
                itemStyle: {
                  color: "#96cc34",
                },
              };
            }),
          },
        };
      },
    },
  };
  </script>
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  • 省级地图二

查看代码详情
  <template>
    <WebMap
      :config="getOptions"
      :data="data"
      @mapBeforeMount="beforeHandle"
      @changeData="getData"
    ></WebMap>
  </template>
  <script>
  export default {
    data() {
      return {
        data: [],
      };
    },
    created() {
      this.getData(3);
    },
    methods: {
      async getData(url) {
        let res = await this.$api.getMap(url);
        if (res.data) {
          this.data = res.data.map((item) => ({ ...item, value: item.descript }));
        }
      },
      beforeHandle(echarts) {
        echarts.registerMap("svgmap", this.$beijingsvg2);
      },
      getOptions(data, Map) {
        return {
          title: {
            text: "svg地图",
            subtext: "单位:元",
          },
          geo: {
            tooltip: {
              formatter: function (params) {
                return [
                  '<div style="max-width:200px;">' + params.des + "</div>",
                ];
              },
            },
            map: "svgmap",
            roam: true,
            ...{
              // 普通样式
              label: {
                show: true,
                color: "rgba(130,143,200,1)",
              },
              itemStyle: {
                borderWidth: 1,
                borderColor: "rgba(196,207,254,1)",
                areaColor: "rgba(229,236,249,1)",
              },
            },
            emphasis: {
              // hover样式
              label: {
                show: true,
                color: "rgba(130,143,200,1)",
              },
              itemStyle: {
                borderColor: "rgba(196,207,254,1)",
                borderWidth: 1,
                areaColor: "rgba(229,236,249,1)",
              },
            },
            ...{
              // 选中样式
              selectedMode: "single",
              select: {
                label: {
                  color: "#333",
                },
                itemStyle: {
                  areaColor: {
                    type: "linear",
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      { offset: 0, color: "rgba(66,99,232,1)" },
                      { offset: 1, color: "rgba(55,183,249,1)" },
                    ],
                    
                  },
                },
              },
            },
          },
          series: {
            type: "effectScatter",
            coordinateSystem: "geo",
            geoIndex: 0,
            symbolSize: 5,
            showEffectOn: "render",
            zlevel: 1,
            rippleEffect: {
              period: 6,
              scale: 3,
              brushType: "stroke",
            },
            hoverAnimation: true,
            label: {
              formatter: function (params) {
                return params.data.name;
              },
              fontSize: 16,
              position: "right",
              offset: [15, 0],
              color: "#fff",
              show: true,
            },
            itemStyle: {
              color: "#fff",
              shadowBlur: 20,
            },
            symbolSize: 10,
            data: data.map((item) => {
              let value = Map.convertToPixel("geo", item.value);
              let [x, y] = value;
              return {
                ...item,
                value: [x + 240, y + 240],
                label: {
                  formatter: "{b}",
                  color: "red",
                },
                itemStyle: {
                  color: "#96cc34",
                },
              };
            }),
          },
        };
      },
    },
  };
  </script>
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140