栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

echarts js 地图(echarts自定义地图geojson)

echarts js 地图(echarts自定义地图geojson)

echarts 引入百度地图

在写大数据相关的大屏中,会遇到需自定义定点图标的问题,这样就必须运用到echarts series的custom属性。
echarts百度地图 custom 属性的运用:
首先上效果图:

这样一个效果的地图,需要运用echarts的 bmap引入地图,通过mapStyle属性来对地图进行调色,代码如下:

bmap: {
          center: [
            parseFloat(elderInfo.longitude),
            parseFloat(elderInfo.latitude),
          ],//这里引入你的地图的中心点经纬度
          zoom: 14,
          roam: true,
          mapStyle: {
            styleJson: [
              {
                featureType: "water",
                elementType: "all",
                stylers: {
                  color: "#003483",
                },
              },
              {
                featureType: "land",
                elementType: "all",
                stylers: {
                  color: "#00023C",
                },
              },
              {
                featureType: "railway",
                elementType: "all",
                stylers: {
                  visibility: "off",
                },
              },
              {
                featureType: "highway",
                elementType: "all",
                stylers: {
                  color: "#000F54",
                },
              },
              {
                featureType: "highway",
                elementType: "labels",
                stylers: {
                  visibility: "off",
                },
              },
              {
                featureType: "arterial",
                elementType: "geometry",
                stylers: {
                  color: "#000F54",
                },
              },
              {
                featureType: "arterial",
                elementType: "geometry.fill",
                stylers: {
                  color: "#000F54",
                },
              },
              {
                featureType: "poi",
                elementType: "labels.text.fill",
                stylers: {
                  color: "#ffffff",
                  visibility: "on",
                },
              },
              {
                featureType: "poi",
                elementType: "labels.text.stroke",
                stylers: {
                  color: "#ffffff",
                  visibility: "on",
                },
              },
              {
                featureType: "green",
                elementType: "all",
                stylers: {
                  visibility: "off",
                },
              },
              {
                featureType: "subway",
                elementType: "all",
                stylers: {
                  visibility: "off",
                },
              },
              {
                featureType: "manmade",
                elementType: "all",
                stylers: {
                  color: "#000F52",
                },
              },
              {
                featureType: "local",
                elementType: "all",
                stylers: {
                  // visibility: "off",
                  color: "#000F52",
                },
              },
              {
                featureType: "arterial",
                elementType: "labels",
                stylers: {
                  visibility: "off",
                },
              },
              {
                featureType: "boundary",
                elementType: "all",
                stylers: {
                  color: "#000F52",
                },
              },
              {
                featureType: "building",
                elementType: "all",
                stylers: {
                  visibility: "off",
                  // 'color': '#000F52'
                },
              },
              {
                featureType: "label",
                elementType: "labels",
                stylers: {
                  color: "#00023C",
                },
              },
              {
                featureType: "poilabel",
                elementType: "labels",
                stylers: {
                  color: "#00023C",
                },
              },
              {
                featureType: "poilabel",
                elementType: "labels.text.fill",
                stylers: {
                  color: "#002F7D",
                },
              },
              {
                featureType: "label",
                elementType: "labels.text.fill",
                stylers: {
                  color: "#002F7D",
                },
              },
            ],
          },
        },

这样对地图调色完成后,需用到series中的custom属性来自定义图标

series:[
	{
			type: "custom",
            name: "站点",
            id: "homeMap",
            coordinateSystem: "bmap",
            renderItem: function (params, api) {
              return addImage(params, api, dataTemp);
            },
            data: dataTemp,
            zlevel: 1,
            label: {
              show: false,
            },
	}
]
//计算图片的位置,已经通过不同的状态显示不同的图片
var addImage = function (params, api, realData) {
        let imgUrl = "";
        if (realData[params.dataIndex].state == 1) {
          imgUrl = that.img1;
        } else if (realData[params.dataIndex].state == 2) {
          imgUrl = that.img2;
        }
        realData[params.dataIndex].x = api.coord([
          realData[params.dataIndex].lng,
          realData[params.dataIndex].lat,
        ])[0];
        realData[params.dataIndex].y =
          api.coord([
            realData[params.dataIndex].lng,
            realData[params.dataIndex].lat,
          ])[1] - 38;
        return {
          type: "image",
          style: {
            image: imgUrl,
            x:
              api.coord([
                realData[params.dataIndex].lng,
                realData[params.dataIndex].lat,
              ])[0] - 38,
            y:
              api.coord([
                realData[params.dataIndex].lng,
                realData[params.dataIndex].lat,
              ])[1] - 76,
            width: 76,
            height: 76,
          },
        };
      };

通过重复定义给点标明名称

series:[
	{
			name: "中心站点",
            type: "effectScatter",
            coordinateSystem: "bmap",
            data: data,
            encode: {
              value: 2,
            },
            symbolSize: function (val) {
              return val[2] / 10;
            },
            showEffectOn: "emphasis",
            rippleEffect: {
              brushType: "stroke",
            },
            hoverAnimation: true,
            label: {
              formatter: "{b}",
              position: "inside",
              show: true,
              color: "#fff",
              fontSize: 18,
            },
            itemStyle: {
              color: "#f4e925",
              shadowBlur: 10,
              shadowColor: "#333",
            },
            zlevel: 1,
	}
]
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/772198.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号