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>

相关推荐

  1. vue3定义v-model以及定义修饰符

    2024-01-27 19:12:02       13 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-27 19:12:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-27 19:12:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-27 19:12:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-27 19:12:02       20 阅读

热门阅读

  1. 天梯赛 L3-020 至多删三个字符

    2024-01-27 19:12:02       36 阅读
  2. 《动手学深度学习(PyTorch版)》笔记4.2 4.3

    2024-01-27 19:12:02       34 阅读
  3. Implement Trie (Prefix Tree)

    2024-01-27 19:12:02       27 阅读
  4. Oracle 数据库(卸载)详细过程

    2024-01-27 19:12:02       34 阅读
  5. spring自动配置的原理

    2024-01-27 19:12:02       32 阅读
  6. 【重点问题】攻击面发现及管理

    2024-01-27 19:12:02       35 阅读
  7. 深度学习在医学影像分析中的应用

    2024-01-27 19:12:02       36 阅读
  8. 11Docker数据持久化

    2024-01-27 19:12:02       34 阅读