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);
			},
		}
	}
相关推荐
处处清欢几秒前
MaintenanceController
java·开发语言
Sam90295 分钟前
【Webpack--007】处理其他资源--视频音频
前端·webpack·音视频
Code成立6 分钟前
HTML5精粹练习第1章博客
前端·html·博客·html5
飞翔的佩奇12 分钟前
Java项目: 基于SpringBoot+mybatis+maven校园资料分享平台(含源码+数据库+答辩PPT+毕业论文)
java·spring boot·spring·毕业设计·maven·mybatis·校园资料分享平台
不平衡的叉叉树16 分钟前
Java对象列表属性映射工具类
java
架构师ZYL18 分钟前
node.js+Koa框架+MySQL实现注册登录
前端·javascript·数据库·mysql·node.js
缘友一世28 分钟前
mac系统安装最新(截止2024.9.13)Oracle JDK操作记录
java·macos·oracle
跃ZHD39 分钟前
BolckingQueue
java
西岭千秋雪_1 小时前
谷粒商城のElasticsearch
java·大数据·服务器·spring boot·elasticsearch·搜索引擎
yueqingll1 小时前
020、二级Java选择题综合知识点(持续更新版)
java·开发语言