uniapp map组件自定义markers标记点

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

<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>
<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>
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp中使用map组件进行标记的操作,需要进行以下几个步骤: 1. 首先,在map标签中绑定要标记,可以通过在data里定义一个markers数组,并将要标记以对象的形式添加到该数组中。 2. 在map组件中设置markers属性为markers数组,以将数组中的显示在地图上。 以下是一个示例代码片段,展示了如何在uniapp中使用map组件进行标记: ``` <template> <view> <map style="width:750rpx; height:100vh;" scale="17" show-location="true" :latitude="latitude" :longitude="longitude" :markers="markers"></map> </view> </template> <script> export default { data() { return { title: 'map', longitude: '122.106863', latitude: '30.016028', markers: [ { id: 1, latitude: 30.016028, longitude: 122.106863, title: '标记1' }, { id: 2, latitude: 30.015, longitude: 122.106, title: '标记2' }, // 可以添加更多的标记 ] } } } </script> ``` 在上面的示例中,markers数组中包含了两个标记,每个标记都有一个唯一的id、经纬度和标题。这样,在地图上就会显示这些标记的位置。 注意:以上示例仅为演示代码,实际使用时需要根据具体需求进行调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [【记录4】uniapp Map地图组件 动态渲染markers](https://blog.csdn.net/weixin_44390036/article/details/124861312)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [uniapp map地图显示图标markers问题,自定义图标不显示](https://blog.csdn.net/web13985085406/article/details/123431764)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值