海量点标记 MassMarks批量切换样式实现不同zoom下显示不同样式坐标

1.将创建的massMark放在data中

this.massMarks = new AMap.MassMarks(this.markerList, {
                cursor: 'pointer',
                style: style
            })

2.监听zoom

this.map.on('zoomend', () => {
                let activeZoom = this.map.getZoom()
                if (activeZoom >= 12 && this.zoom < 12) {
                    this.changeMarkerIcon(activeZoom)
                } else if (activeZoom < 12 && this.zoom >= 12) {
                    this.changeMarkerIcon(activeZoom)
                }
                this.zoom = activeZoom
            })

3.实现切换icon的style

changeMarkerIcon(zoom) {
            let width, height
            if (zoom >= 12) {
                width = 32, height = 46
            } else {
                width = 50, height = 50
            }
            let style_zoom = [{
                url: normalLogo_zoom,//这里是用import引入了图片路径方便复用
                anchor: new AMap.Pixel((width / 2), (height * .8)),
                size: new AMap.Size(width, height),
                zIndex: 2
            }, {
                url: abnormalLogo_zoom,
                anchor: new AMap.Pixel((width / 2), (height * .8)),
                size: new AMap.Size(width, height),
                zIndex: 3
            }, {
                url: offlineLogo_zoom,
                anchor: new AMap.Pixel((width / 2), (height * .8)),
                size: new AMap.Size(width, height),
                zIndex: 1
            }]
            let style = [{
                url: normalLogo,
                anchor: new AMap.Pixel((width / 2), (height * .8)),
                size: new AMap.Size(width, height),
                zIndex: 2
            }, {
                url: abnormalLogo,
                anchor: new AMap.Pixel((width / 2), (height * .8)),
                size: new AMap.Size(width, height),
                zIndex: 3
            }, {
                url: offlineLogo,
                anchor: new AMap.Pixel((width / 2), (height * .8)),
                size: new AMap.Size(width, height),
                zIndex: 1
            }]
            if (zoom >= 12) {
                this.massMarks.setStyle(style_zoom)//setStyle实现icon样式的设置
            } else {
                this.massMarks.setStyle(style)
            }
        },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在Vue项目中添加高德地图的海量标记,可以参考以下步骤: 1. 在Vue项目中安装高德地图的JavaScript API库: ```bash npm install --save @amap/amap-jsapi-loader ``` 2. 在Vue组件中引入高德地图的JavaScript API: ```javascript import AMapLoader from '@amap/amap-jsapi-loader'; ``` 3. 在Vue组件的`mounted`生命周期钩子函数中加载地图并添加海量标记: ```javascript mounted() { AMapLoader.load({ // 申请的高德地图key key: 'your_amap_key', // 指定要加载的JSAPI版本,缺省时默认为 1.4.15 version: '1.4.15', // 是否需要使用高德UI组件库,默认为false uiVersion: '1.0', // 是否加载插件,默认为false plugins: [], }).then((AMap) => { // 创建地图实例 const map = new AMap.Map('mapContainer', { center: [116.397428, 39.90923], // 地图中心坐标 zoom: 13, // 地图缩放级别 }); // 创建海量标记图层 const massMarks = new AMap.MassMarks([], { // 海量样式配置 style: { url: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_bs.png', anchor: new AMap.Pixel(6, 6), size: new AMap.Size(11, 11), }, // 海量的单击事件处理函数 onClick: (event, data) => { console.log(data); }, }); // 添加海量标记数据 const massMarksData = [ { lnglat: [116.405285, 39.904989] }, { lnglat: [116.404285, 39.904989] }, { lnglat: [116.403285, 39.904989] }, ]; massMarks.setData(massMarksData); // 将海量标记图层添加到地图中 map.add(massMarks); }); } ``` 其中,`your_amap_key`为申请的高德地图key,`mapContainer`为地图容器元素的ID。海量标记样式可以根据实际需求进行修改,`onClick`事件处理函数可以根据需要进行扩展。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值