uniapp map组件自定义markers标记点

需求是根据后端返回数据在地图上显示标记点,并且根据数据状态控制标记点颜色,标记点背景通过两张图片实现控制

html 复制代码
<map
	style="width: 100vw; height: 100vh;"
	:markers="markers"
	:longitude="locaInfo.longitude"
	:latitude="locaInfo.latitude"
	@markertap="markerClick"
	@callouttap='callouttap'
	>
	<!-- 使用callout进行自定义 -->
	<cover-view slot="callout">
		<template v-for="(item,index) in markers"> 
			<cover-view 
			style="position: relative; width: 100%;padding-right: 20px;"
			:marker-id="item.id"
			:key='index'>
				<cover-view class="marker-box" style="padding: 5px 5px 12px 5px;">
					<cover-image class="position-absolute" style="margin-right: 5px; width: 30rpx; height: 30rpx;" :src="item.options.img"></cover-image>
					<cover-view>{{item.options.labelName}}</cover-view>
					
					<cover-image class="position-absolute" style="position: absolute; left: 0;top: 0; z-index: -1; width: 100%; height: 100%;" :src="item.options.isStore?item.options.active_bg:item.options.bg"></cover-image>
				</cover-view>
				<cover-view style="position: absolute; right: 0px; top: 50%; transform: translateY(-65%); z-index: 2 ; width: 16px; height: 16px; border-radius: 50%; background-color: aquamarine;"></cover-view>
			</cover-view>
		</template>
	</cover-view>
</map>
js 复制代码
<script>
	export default {
		data() {
			return {
				storeIndex:0,
				locaInfo: {
					longitude:120.445172,
					latitude:36.111387
				},
				markers: [ // 标点列表
					{
						id: 1, //标记点id
						index: 0,
						clusterId: 1, //自定义点聚合簇效果时使用
						latitude: 36.116874, // 纬度
						longitude: 120.441515, // 经度
						iconPath:  '/static/tm.png', 
						options: {
							isStore: true,
							img: '/static/store.png', 
							bg: '/static/1.png',
							active_bg: '/static/2.png',
							labelName: '恩豪斯',
							name: '建材城名称(蓝鳌路店)',
							address: '高新区大学路101号',
							time1: '2024-02-28  16:30'
						},
						// 自定义窗口
						customCallout: {
							anchorX: 0,
							anchorY: 0,
							display: "ALWAYS" // 常显
						}
					},
					{
						id: 2, //标记点id
						index: 1,
						clusterId: 1, //自定义点聚合簇效果时使用
						latitude: 36.110543, // 纬度
						longitude: 120.454837, // 经度
						iconPath: '/static/tm.png', 
						options: {
							isStore: false,
							img: '/static/store.png', 
							bg: '/static/1.png',
							active_bg: '/static/2.png',
							labelName: '恩豪斯1111',
							name: '品牌名称(所属建材城)',
							address: '高新区大学路101号',
							time1: '2024-02-28  16:30',
							time2: '2024-02-28  16:30',
						},
						// 自定义窗口
						customCallout: {
							anchorX: 0,
							anchorY: 0,
							display: "ALWAYS" // 常显
						}
					},
				],
			}
		},
		methods: {
			callouttap(e){ // 点击气泡
				console.log(e.detail);
			}
		}
	}
</script>
<style lang="scss">
	// 地图标记点
	.marker-box {
		position: relative;
		display: flex;
		// align-items: center;
		justify-content: center;
		color: #fff;
		font-size: 28rpx;
		overflow: visible; 
	}
	

</style>
相关推荐
前端的日常1 分钟前
什么是 TypeScript 中的泛型?请给出一个使用泛型的示例。
前端
Struggler28112 分钟前
Chrome插件开发
前端
前端 贾公子24 分钟前
Monorepo + vite 怎么热更新
前端
coding随想33 分钟前
掌控网页的魔法之书:JavaScript DOM的奇幻之旅
开发语言·javascript·ecmascript
然我1 小时前
不用 Redux 也能全局状态管理?看我用 useReducer+Context 搞个 Todo 应用
前端·javascript·react.js
前端小巷子1 小时前
Web 实时通信:从短轮询到 WebSocket
前端·javascript·面试
神仙别闹1 小时前
基于C#+SQL Server实现(Web)学生选课管理系统
前端·数据库·c#
web前端神器1 小时前
指定阿里镜像原理
前端
枷锁—sha1 小时前
【DVWA系列】——CSRF——Medium详细教程
android·服务器·前端·web安全·网络安全·csrf
枷锁—sha1 小时前
跨站请求伪造漏洞(CSRF)详解
运维·服务器·前端·web安全·网络安全·csrf