Echarts绘制地图带标记tooltip

全国各地区JSON文件网址

.agency_information {
  width: 250px;
  padding: 5px 0;
  background: transparent;
  border-radius: 5px;
}
.agency_title {
  min-width: 150px;
  height: auto;
  margin-bottom: 6px;
  font-size: 14px;
  color: #ffffff;
  font-weight: normal;
  text-align: center;
}
.agency_type {
  color: #fe0101;
}
.agency_info_row {
  box-sizing: border-box;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  height: auto;
  padding-left: 10px;
  background: #ffffff33;
  margin-bottom: 4px;
  font-size: 12px;
  color: #ffffff;
  font-weight: normal;
}
.agency_info_row > label:first-child {
  width: 60px;
  height: auto;
  margin-right: 20px;
  text-align: left;
}


<div class="map" id="map" style="width:900px;height:900px;"></div>


function ecMapServicer(name) {
  var uploadedDataURL = "json/wuhan.json";
  // 基于准备好的dom,初始化echarts实例
  const myChart = echarts.init(document.getElementById(name));

  /*  {name:'武汉', geoCoord:[114.31, 30.52]}, x-y坐标轴起点[113.45, 29.95] */
  var data_type_1 = [{
      type: "一类",
      name: "五零四文化广场",
      value: [114.31, 30.1222, 120]
    },
    {
      type: "一类",
      name: "五零四文化广场",
      value: [114.41, 30.32, 120]
    },
    {
      type: "一类",
      name: "五零四文化广场",
      value: [114.39, 30.52, 120]
    },
    {
      type: "一类",
      name: "五零四文化广场",
      value: [114.73, 30.72, 120]
    }
  ];
  var data_type_2 = [{
      type: "二类",
      name: "五零四文化广场",
      value: [114.2133, 30.1222, 120]
    },
    {
      type: "二类",
      name: "五零四文化广场",
      value: [114.01, 30.3222, 120]
    },
    {
      type: "二类",
      name: "五零四文化广场",
      value: [114.59, 30.82, 120]
    },
    {
      type: "二类",
      name: "五零四文化广场",
      value: [114.73, 30.72, 120]
    }
  ];
  var data_type_3 = [{
      type: "三类",
      name: "五零四文化广场",
      value: [114.27, 31.292, 120]
    },
    {
      type: "三类",
      name: "五零四文化广场",
      value: [114.21, 30.72, 120]
    },
    {
      type: "三类",
      name: "五零四文化广场",
      value: [114.429, 30.12, 120]
    },
    {
      type: "三类",
      name: "五零四文化广场",
      value: [114.73, 30.62, 120]
    }
  ];

  // 显示加载动画
  myChart.showLoading();
  $.getJSON(uploadedDataURL, null, function (data) {
    echarts.registerMap("mapData", data);
    myChart.hideLoading();

    option = {
      color: ["#91c7ae", "#749f83", "#ca8622"], //颜色组
      tooltip: {
        trigger: "item",
        show: true,
        padding: 0,
        backgroundColor: "#ffffff33",
        formatter: function (params) {
          var str = `
          <div class="agency_information">
          <div class="agency_title">
            ${params.name}
            <label class="agency_type">(${params.data.type})</label>
          </div>
          <div class="agency_info_row">
            <label>建立时间:</label><label> 2007(使用)</label>
          </div>
          <div class="agency_info_row">
            <label>负责人:</label><label> 张建华 </label>
          </div>
          <div class="agency_info_row">
            <label>床位数: </label><label> 200 </label>
          </div>
          <div class="agency_info_row">
            <label>联系方式:</label><label> 125697415266</label>
          </div>
          <div class="agency_info_row">
            <label>地址:</label><label> 武汉市xxxxxxxx</label>
          </div>
        </div>
          `;
          return str;
          /* if (typeof params.value[2] == "undefined") {
            return params.name + " : " + params.value;
          } else {
            return params.name + " : " + params.value[2];
          } */
        }
      },
      grid: {
        top: 100
      },
      legend: {
        orient: "vertical",
        icon: "pain",
        right: '10%',
        bottom: '10%',
        itemWidth: 20,
        itemHeight: 12,
        align: "left",
        textStyle: {
          color: "#fff",
          fontSize: 12
        },
        data: ["一类", "二类", "三类"]
      },
      xAxis: {
        show: false
      },
      yAxis: {
        show: false
      },
      geo: {
        show: true,
        map: "mapData",
        label: {
          normal: {
            show: false
          },
          emphasis: {
            show: false
          }
        },
        zoom: 1.2,
        roam: true,
        itemStyle: {
          areaColor: "#1A2B75",
          borderColor: "#3fdaff",
          borderWidth: 1
        },
        emphasis: {
          itemStyle: {
            areaColor: "#2B91B7"
          }
        }
      },
      series: [
        // 一类
        {
          name: "一类",
          type: "scatter",
          coordinateSystem: "geo",
          symbol: "image://img/icon_location_1.png",//自行找图标
          symbolSize: [14, 16],
          label: {
            normal: {
              show: false,
              backgroundColor: "#0D1151",
              position: "right",
              color: "#ffffff",
              fontSize: "14",
              padding: 20
            },
            emphasis: {
              show: false
            }
          },
          itemStyle: {
            normal: {
              color: "#00A0E9", //控制图例和地图标记点的颜色
              borderWidth: 2
            }
          },
          data: data_type_1
        },
        // 二类
        {
          name: "二类",
          type: "scatter",
          coordinateSystem: "geo",
          symbol: "image://img/icon_location_2.png",
          symbolSize: [14, 16],
          label: {
            normal: {
              show: false,
              backgroundColor: "#2B91B7",
              position: "right",
              color: "#ffffff",
              fontSize: "14",
              padding: 20
            },
            emphasis: {
              show: false
            }
          },
          itemStyle: {
            normal: {
              color: "#11D53F", //控制图例和地图标记点的颜色
              borderWidth: 2
            }
          },
          data: data_type_2
        },
        // 三类
        {
          name: "三类",
          type: "scatter",
          coordinateSystem: "geo",
          symbol: "image://img/icon_location_3.png",
          symbolSize: [14, 16],
          label: {
            normal: {
              show: false,
              backgroundColor: "#2B91B7",
              position: "right",
              color: "#ffffff",
              fontSize: "14",
              padding: 20
            },
            emphasis: {
              show: false
            }
          },
          itemStyle: {
            normal: {
              color: "#E39F28",
              borderWidth: 2
            }
          },
          data: data_type_3
        }
      ]
    };
    myChart.setOption(option);
  });
  myChart.setOption(option);
}

在这里插入图片描述

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
使用ECharts绘制武安市的地图并标记坐标非常简单。以下是一个简单的步骤指南: 1. 首先,确保你已经引入了ECharts库的JavaScript文件。 2. 创建一个div元素,用于容纳地图。 ```html <div id="map" style="width: 800px; height: 600px;"></div> ``` 3. 在JavaScript文件中,使用echarts.init方法初始化地图,并设置图表的宽度和高度。 ```javascript var myChart = echarts.init(document.getElementById('map')); ``` 4. 定义地图的配置项,包括地图类型和数据。 ```javascript var option = { tooltip: { trigger: 'item', formatter: '{b}' }, series: [ { name: '武安市', type: 'map', mapType: '武安市', roam: false, label: { show: true, position: 'inside' }, data: [] // 在这里填入你的数据 } ] }; ``` 5. 使用echarts.registerMap方法注册地图。 ```javascript echarts.registerMap('武安市', 武安市的地图数据); ``` 6. 将配置项应用到图表中。 ```javascript myChart.setOption(option); ``` 7. 若要标记坐标,可以在数据项中添加坐标的地理位置信息。 ```javascript data: [ {name: '坐标1', value: [经度, 纬度]}, {name: '坐标2', value: [经度, 纬度]}, // ... ] ``` 8. 最后要根据数据项中的坐标进行标记。 ```javascript series: [ { name: '武安市', type: 'map', mapType: '武安市', roam: false, label: { show: true, position: 'inside' }, data: [ {name: '坐标1', value: [经度, 纬度]}, {name: '坐标2', value: [经度, 纬度]}, // ... ], markPoint: { symbolSize: 10, label: { show: false }, itemStyle: { color: 'red' }, data: [ {name: '坐标1', value: [经度, 纬度]}, {name: '坐标2', value: [经度, 纬度]}, // ... ] } } ] ``` 以上就是使用ECharts绘制武安市的地图并标记坐标的基本步骤。你可以根据实际需要修改配置项和数据。希望对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值