v3+ECharts 地图实现多个自定义图片的图标

在这里插入图片描述
备注:地图json, 图标图片 准备替换下

<template>
    <div ref="mapEcharts" class="map-echart"></div>
</template>

<script setup lang='ts'>
import * as echarts from 'echarts'
import mapcity from "@/tool/map/map.json"
import { ref, nextTick, onMounted } from 'vue'
const mapEcharts = ref(null)
onMounted(() => {
    //获取山东地图
    initEcharts()

})
function initEcharts() {
    echarts.registerMap('mapcity', mapcity)
    nextTick(() => {
        const map = echarts.init(mapEcharts.value, null, {
            renderer: 'canvas',
        })
        let LableData = [
            {
                name: "济南",
                value: [117.000923,
                    36.675807],
            },
            {
                name: "日照",
                value: [119.461208,
                    35.428588],
            },

        ];
        const option = {
            // 悬浮窗
            tooltip: {
                trigger: 'item',
            },
            geo: {
                map: 'mapcity',
                zoom: 1.2,
                roam: false,
                label: {
                    show: true,
                    color: 'black',
                    position: 'inside',
                    distance: 0,
                    fontSize: 10,
                    rotate: 0,
                },
                // 所有地图的区域颜色
                itemStyle: {
                    areaColor: '#eee',
                    borderColor: '#02c0ff',
                },
                emphasis: {
                    itemStyle: {
                        areaColor: '#aaa',
                        shadowColor: 'rgba(0,0,0,0.8)',
                    },
                },
            },
            series: [
                {
                    name: "lable",
                    type: "scatter",
                    coordinateSystem: "geo",
                    symbol: 'image://' + new URL(`./003.png`, import.meta.url).href,
                    symbolSize: [30, 30],
                    symbolOffset: [0, "10%"],
                    hoverAnimation: true,
                    zlevel: 2,
                    label: {
                        normal: {
                            show: false,
                            textStyle: {
                                color: "#fff",
                                lineHeight: 15,
                            },
                            formatter(params) {
                                return params.data.value[2];
                            },
                        },
                    },

                    itemStyle: {
                        normal: {
                            color: "#6495ED", //标志颜色
                            opacity: 0.8,
                            borderColor: "#aee9fb",
                            borderWidth: 0.6,
                        },
                    },
                    showEffectOn: "render",
                    rippleEffect: {
                        brushType: "stroke",
                    },
                    data: LableData,
                },
                {
                    name: "lable",
                    type: "scatter",
                    coordinateSystem: "geo",
                    symbol: 'image://' + new URL(`./001.png`, import.meta.url).href,
                    symbolSize: [20, 20],
                    symbolOffset: [0, "-70%"],
                    hoverAnimation: true,
                    zlevel: 2,
                    label: {
                        normal: {
                            show: false,
                            textStyle: {
                                color: "#fff",
                                lineHeight: 15,
                            },
                            formatter(params) {
                                return params.data.value[2];
                            },
                        },
                    },

                    itemStyle: {
                        normal: {
                            color: "#6495ED", //标志颜色
                            opacity: 0.8,
                            borderColor: "#aee9fb",
                            borderWidth: 0.6,
                        },
                    },
                    showEffectOn: "render",
                    rippleEffect: {
                        brushType: "stroke",
                    },
                    data: LableData,
                },

            ],
        }
        map.setOption(option)
        map.on('click', function (params) {


        })

    })

}
</script>

<style scoped>
.map-echart {
    width: 100%;
    height: calc(100% - 50px);
}

.topbox {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mapTitle {
    width: 300px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 25px;
    font-weight: bold;
    cursor: pointer;
    color: #2d3436;
}
</style>

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值