当前位置:   article > 正文

echarts 2d 地图 tooltip提示牌_echarts地图上 如何生产提示

echarts地图上 如何生产提示

在这里插入图片描述
代码:


<template>
  <div class="bg">
    <div class="zindex">
      <div id="mapLine"></div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { mapJson } from "../../../../assets/js/map_js/gansu.js";
export default {
  data() {
    return {};
  },
  mounted() {
    this.$nextTick(() => {
      this.getMap();
    });
  },
  methods: {
    getMap() {
      var dom = document.getElementById("mapLine");
      var myChart = echarts.init(dom);
      var option;
      var geoJson = mapJson;

      myChart.showLoading();
      myChart.hideLoading();
      echarts.registerMap("gansu", geoJson);
      myChart.setOption(
        (option = {
          //地理坐标系组件。地理坐标系组件用于地图的绘制,支持在地理坐标系上绘制散点图,线集。
          geo: {
            z: 5,
            name: "甘肃地图",
            show: true,
            map: "gansu",
            layoutCenter: ["50%", "50%"], //地图位置
            layoutSize: "80%", //地图大小
            // zoom: 0.65, //地图缩放比例
            roam: false,
            label: {
              // show: true,
              fontFamily: " Microsoft YaHei",
              fontSize: 12,
              color: "#fff",
            },

            itemStyle: {
              //每一块区域的样式
              normal: {
                areaColor: "#00D3FD",
                borderColor: "#0F5A69",
                borderWidth: 1,
              },
            },
            // 鼠标经过样式--区域颜色、和提示
            emphasis: {
              label: {
                show: true,
                color: "#00D3FD",
                fontSize: "12",
              },
              itemStyle: {
                borderColor: "#0F5A69",
                borderWidth: 2,
                areaColor: "#DEF0F3",
              },
            },
            select: {
              disabled: true, //不能点击地图
            },

            // 对不同的区块进行着色
            regions: [
              {
                name: "兰州市",
                itemStyle: {
                  areaColor: "#00B346",
                },
              },
              {
                name: "陇南市",
                itemStyle: {
                  areaColor: "#00B346",
                },
              },
              {
                name: "白银市",
                itemStyle: {
                  areaColor: "#00B346",
                },
              },
              {
                name: "金昌市",
                itemStyle: {
                  normal: {
                    areaColor: "#00B346",
                    // areaColor: {
                    //   //地图色
                    //   type: "linear",
                    //   x: 0,
                    //   y: 1,
                    //   x2: 0,
                    //   y2: 0,
                    //   colorStops: [
                    //     {
                    //       offset: 0,
                    //       color: "#003ddf", // 0% 处的颜色
                    //     },
                    //     {
                    //       offset: 1,
                    //       color: "#0069e6", // 100% 处的颜色
                    //     },
                    //   ],
                    //   global: false, // 缺省为 false
                    // },
                  },
                },
              },
            ],
            // tooltip 有两个---这是第一个
            tooltip: {
              show: true,
              triggerOn: "click",
              trigger: "item",
              backgroundColor: "rgba(255,255,0,0.4)", // 提示框浮层的背景颜色。
              textStyle: {
                // 提示框浮层的文本样式。
                color: "#41feff",
                fontSize: 14,
              },
              padding: 10, // 提示框浮层内边距,
              formatter: function (params) {
                // console.log(params, "地图。。。。。。。。。。");
                let showname = params;
                return `
                <div style='width:150px;height:150px'>
                    <p  style="width:100%;height:30px; background: linear-gradient(#2caaab, #136692);  text-align: center;line-height: 30px;">${showname.name}</p>
                    <p  style="line-height: 30px; text-indent: 10px;">补助人数: 123423人</p>
                    <p style="line-height: 30px; text-indent: 10px;"> 金 额 : 54564万元</p>
                    <p style="line-height: 30px; text-indent: 10px;" >支出比例: %</p>
                    <p style="line-height: 30px; text-indent: 10px;">补助发生率: 346%</p>
              </div>
              `;
              },
            },
          },
          // 提示牌--- tooltip 有两个---这是第二个----必须写这个,要不然不能出现tooltip提示牌
          tooltip: {
            show: true,
          },

          series: [
            // 地图的样式---主要是为了添加阴影
            {
              type: "map",
              map: "gansu",
              layoutCenter: ["50%", "50%"],
              layoutSize: "80%",
              roam: false,
              itemStyle: {
                normal: {
                  shadowColor: "rgba(5,79,94,0.9)",
                  shadowBlur: 2,
                  shadowOffsetX: -5,
                  shadowOffsetY: 10,
                },
              },
            },
          ],
        })
      );

      if (option && typeof option === "object") {
        myChart.setOption(option);
      }
      // 屏幕适配
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    
    },
  },
};
</script>

<style scoped>
#mapLine {
  width: 900px;
  height: 500px;
  position: absolute;
  left: 50%;
  margin-left: -450px;
  /* transform-origin: center bottom;
  transform: rotateX(55deg) translateZ(80px) ; */
}
.bg {
  width: 100%;
  height: 88vh;
  background: url("../../../../assets/img/bj.png") no-repeat center;
  background-size: 100% 100%;
}
.zindex {
  width: 500px;
  height: 500px;
  background: url("../../../../assets/img/bg.png") no-repeat center;
  background-size: 80% 80%;
  margin: 0 auto;
  position: relative;
  /* transform-style: preserve-3d;
  perspective: 800px; */
}
</style>
  • 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
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/308595
推荐阅读
相关标签
  

闽ICP备14008679号