uniapp 谷歌地图 nvue

问题集合

安卓App端,开启点聚合

  1. 会导致@markertap和@labeltap的点击事件失效(未解决)
  2. 标记点Label属性失效(未解决)
html 复制代码
<view class="content">
		<map id="map" class="map" :show-location="true" :latitude="latitude" :longitude="longitude"
			@markertap="markertap" @labeltap="labeltap"></map>
	</view>
javascript 复制代码
const img = '/static/logo.png';

	export default {
		data() {
			return {
				latitude: 32.715738,
				longitude: -117.1610838,
			}
		},
		onReady() {
			this._mapContext = uni.createMapContext("map", this);
			// this.clusterEvent()
			this.addMarkers();
		},
		methods: {
			// 开启聚合
			clusterEvent(){
				// 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
				this._mapContext.initMarkerCluster({
					enableDefaultStyle: false,
					zoomOnClick: true,
					gridSize: 60,
					complete(res) {
						console.log('initMarkerCluster', res)
					}
				});
				// 缩放或拖动导致新的聚合簇产生时触发,仅返回新创建的聚合簇信息。
				this._mapContext.on("markerClusterCreate", (e) => {
					// console.log("markerClusterCreate", e);
				});
				// 聚合点击事件
				this._mapContext.on("markerClusterClick", (e) => {
					// console.log("markerClusterClick", e);
				})
			},
			// 添加标记点
			addMarkers() {
				const positions = [{
					latitude: 32.715738,
					longitude: -117.1610838,
				}, {
					latitude: 32.715180,
					longitude: -117.1610838,
				}, {
					latitude: 32.715180,
					longitude: -117.16217638,
				}]

				const markers = []

				positions.forEach((p, i) => {
					markers.push(
						Object.assign({}, {
							id: i + 1, // markertap点击事件必须指定id
							iconPath: img,
							width: 50,
							height: 50,
							// joinCluster: true, // 指定了该参数才会参与聚合
							label: { // 点聚合开启,label失效
								width: 50,
								height: 30,
								borderWidth: 1,
								borderRadius: 10,
								fontSize: 14,
								color: '#fff',
								textAlign: 'center',
								bgColor: '#1bff18',
								content: `label ${i + 1}`
							}
						}, p)
					)
				})
				this._mapContext.addMarkers({
					markers,
					clear: false,
					complete(res) {
						console.log('addMarkers', res)
					}
				})
			},
			// 标记点点击事件(注:安卓app,点聚合开启,标记点点击失效)
			markertap(evt) {
				console.log("Marker点击", evt);
			},
			// Label标签点击事件(注:安卓app,点聚合开启,Label标签点击失效)
			labeltap(evt) {
				console.log("Label点击", evt);
			},
		}
	}
相关推荐
captain3766 小时前
MyBatis(入门5)其他查询操作
java·数据库·spring boot·mybatis
jktantan6 小时前
Vue keep-alive 切标签后滚动位置回顶?因为 onDeactivated 里读到的 scrollTop 是 0
前端·javascript·vue.js
Novproxy_Z7 小时前
商用代理避坑:如何识别商家拿机房 IP 冒充住宅 IP
java·网络·tcp/ip
文丑颜不良啊7 小时前
LeetCode1481~1500题目解析
java·leetcode
2601_962885727 小时前
quotes 字段全解:涨跌幅、振幅、换手率的口径与单位
java·前端·spring
excel8 小时前
encodeURI 和 encodeURIComponent 有什么区别?
前端
前端精髓8 小时前
调用openrouter的免费API模型
java·前端·javascript
步行cgn8 小时前
Spring MVC 拦截器 Interceptor 详解:从执行流程到实战应用
java·spring·mvc
文丑颜不良啊8 小时前
LeetCode1381~1400题目解析
java·leetcode
赛博守夜人8 小时前
AI安全攻防与治理之十四:AI 安全测试不能脱离传统安全,Web、API、移动端与模型攻击面的组合拳
前端·人工智能·安全