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);
			},
		}
	}
相关推荐
ps酷教程5 小时前
Jackson 解决没有无参构造函数的反序列化问题
java
NiceCloud喜云5 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
wordbaby6 小时前
React Native + RNOH:跨页面数据回传的最佳实践与避坑指南
前端·react native
丷丩6 小时前
MapLibre GL JS第22课:查看本地GeoJSON
前端·javascript·map·mapbox·maplibre gl js
_日拱一卒6 小时前
LeetCode:994腐烂的橘子
java·数据结构·算法·leetcode·深度优先
隔窗听雨眠7 小时前
Nginx网关响应慢排查手记
java·服务器·nginx
智慧物业老杨7 小时前
智慧物业合同周期管理系统:从风险预警到智能交接的全流程数智化落地方案
java·人工智能·python
Front思7 小时前
AI前端工程师需要具备能力+
前端·人工智能·ai
源码宝7 小时前
MES系统源码:Java8 + SpringBoot2.7 + MySQL8 + Redis,后端源码清爽易扩展
java·后端·源码·springboot·mes系统·源码二开·mes源码
JAVA社区8 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展