map组件轨迹,定位,导航,定位点遮罩

news2024/10/6 16:18:00

小程序使用map组件实现轨迹,定位,导航,定位点遮罩

map组件常用属性说明,

看着还要自己研究写 我们立志成为cv工程师 直接上代码!!!

<template>
	<map id="map" class="map" :show-location="true" :longitude="centerLng" :latitude="centerLat" :scale="scale"
			:markers="markers" :circles="circles" :polyline="polyline" @updated="handleMapUpdate">
			</template>


:longitude="centerLng" //标记点经纬度
:latitude="centerLat" //标记点经纬度
:markers="markers"//标记点花样
:polyline="polyline"//轨迹

//定义变量自己的写名字吧
data(){
return{
	}
},


新增地图多个点需要显示

//跟methods同级
		onReady() {
			setTimeout(() => {
				this._mapContext = uni.createMapContext("map", this);
				// 
				// 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
				// 设置地图缩放是否聚合
				this._mapContext.initMarkerCluster({
					enableDefaultStyle: false,
					zoomOnClick: true,
					gridSize: 1000,
					complete(res) {
						console.log('initMarkerCluster', res)
					}
				});

				this._mapContext.on("markerClusterCreate", (e) => {
					console.log("markerClusterCreate", e);
				});

				this.addMarkers();
			}, 1500)
		},
// 地图
			async addMarkers() {
				uni.showLoading({
					title: '加载中'
				});
				let that = this
				await this.handleGetMapList()//获得标记点经纬度
				await this.handleGetPhoenCore()//判断手机类型
				const markers = []
				this.positions.forEach((p, i) => {
					markers.push(
						Object.assign({}, {
							id: Number(i + 1),
							iconPath: p.state == 1 ? that.img1 : that.img2,
							width: 40,
							height: 40,
							bgColor: 'white',
							zIndex: Number(199),
							// joinCluster: false, // 指定了该参数才会参与聚合,
							callout: {
								id: Number(i + 1),
								display: 'ALWAYS',
								width: 40,
								height: 40,
								padding: that.isIOS ? 2.1 : 5,
								borderRadius: 25,
								bgColor: p.state == 1 ? '#00c187' : '#cdcdcd',
								color: '#ffffff',
								border: '1px solid #ffffff',
								anchorX: 9,
								anchorY: that.isIOS ? 13 : 11,
								textAlign: "center",
								content: JSON.stringify(p.high_voltage_counts)
								// content: '99'
							},
							label: {
								width: 18,
								height: that.isIOS ? 18 : 22,
								// borderWidth: 1,  
								borderRadius: 25,
								bgColor: p.state == 1 ? '#00c187' : '#cdcdcd',
								color: '#fff',
								border: '1px solid #fff',
								anchorX: -14,
								anchorY: that.isIOS ? -45 : -52,
								content: JSON.stringify(p.low_voltage_counts)
								// content: '99'
							}
						}, p)
					)
				})
				that.mapList = markers
				// console.log(that.mapList,'33333')
				this._mapContext.addMarkers({
					markers,
					clear: false,
					// scale:60,
					complete(res) {
						console.log('addMarkers', res)
					}
				})
			},
			// 获取手机内核 调整不兼容问题
			handleGetPhoenCore() {
				uni.getSystemInfo({
					success: (res) => {
						// this.systemInfo = res
						// console.log("所获取设备数据皆来自设备本身 by kuiwaiwai")
						console.log('获取手机内核', res)
						console.log(res.osName == 'ios')
						if (res.osName == 'ios') {
							this.isIOS = true
							console.log(this.isIOS)
						}
					}
				})
			},

1,定位遮蔽罩

<script>
// 在地图渲染更新完成时触发
handleMapUpdate(e) {
				// 在地图缩放时更新圆形遮罩和标记点的位置
				if (e.type === 'end' && e.causedBy === 'scale') {
					this.circles = [];
					this.markers = [];
					this.polyline = [];
					// this.getCenterPosition()
					// this.drawCircle();
					this.drawMarkers();
					this.drawPolyline();
				}
			}
//定位
drawMarkers() {
				console.log(this.centerLng, '经纬度')
				console.log(this.centerLat, '经纬度')
				// 在标记点数组中添加中心点标记点对象
				this.markers.push({
					id: 1, // 标记点唯一ID
					longitude: this.centerLng, // 标记点经度
					latitude: this.centerLat, // 标记点纬度
					title: '中心点', // 标记点标题
					iconPath: '/static/image/mark.png', // 标记点图标路径
					width: 30 + 'rpx', // 标记点图标宽度,使用相对单位rpx
					height: 30 + 'rpx', // 标记点图标高度,使用相对单位rpx
				});
				//在地图上就显示出来接口给的经纬度
			},
			// 这个和上一个方法冲突二选一  绘制起点到终点二个点的轨迹
	drawMarkers() {
				// 在标记点数组中添加中心点标记点对象
				// this.markers.push({
				// 	id: 1, // 标记点唯一ID
				// 	longitude: this.centerLng, // 标记点经度
				// 	latitude: this.centerLat, // 标记点纬度
				// 	title: '中心点', // 标记点标题
				// 	iconPath: '/static/image/mark.png', // 标记点图标路径
				// 	width: 30 + 'rpx', // 标记点图标宽度,使用相对单位rpx
				// 	height: 30 + 'rpx', // 标记点图标高度,使用相对单位rpx
				// });

				// 添加起点标记点对象
				this.markers.push({
					id: 2, // 起点标记点唯一ID
					longitude: this.polyline[0].longitude, // 起点经度
					latitude: this.polyline[0].latitude, // 起点纬度
					title: '起点', // 起点标题
					iconPath: '/static/image/marpq.png', // 起点图标路径
					width: 80 + 'rpx', // 终点图标宽度,使用相对单位rpx
					height: 80 + 'rpx', // 终点图标高度,使用相对单位rpx
				});

				// 添加终点标记点对象
				const lastIndex = this.polyline.length - 1;
				this.markers.push({
					id: 3, // 终点标记点唯一ID
					longitude: this.polyline[lastIndex].longitude, // 终点经度
					latitude: this.polyline[lastIndex].latitude, // 终点纬度
					title: '终点', // 终点标题
					iconPath: '/static/image/markz.png', // 终点图标路径
					width: 80 + 'rpx', // 终点图标宽度,使用相对单位rpx
					height: 80 + 'rpx', // 终点图标高度,使用相对单位rpx
				});
			},
	//遮蔽罩
		drawCircle() {
				// 获取地图当前视图的宽高定位处于遮蔽罩的中心 看着有点偏 实际是中心点 
				uni.createSelectorQuery()
					.select('#map')
					.boundingClientRect(async (res) => {
						// 圆心位置为地图视图中心点
						const centerX = res.width / 2;
						const centerY = res.height / 2;

						// // 绘制圆形遮罩
						const circle = {
							latitude: this.centerLat, // 圆心纬度
							longitude: this.centerLng, // 圆心经度
							color: '#54C3FF',
							// 填充颜色
							fillColor: '#58d0eb6a',//注意格式格式 !!!!!!!!!!!!!
							borderColor: '#58d0eb6a',//注意格式格式 !!!!!!!!!!!!!
							borderWidth: 0,
							radius: Math.min(res.width, res.height) / 4, // 半径为地图视图宽高的四分之一
							strokeWidth: 0 // 边框宽度
						};
						this.circles.push(circle);

						// 更新标记点的位置为圆心
						this.markers[0].left = centerX - 15;
						this.markers[0].top = centerY - 15;
					})
					.exec();
			},
</script>

2,上面二步奏我没传入经纬度 在地图上展示如下

在这里插入图片描述

3,轨迹

// 在地图渲染更新完成时触发
handleMapUpdate(e) {
				// 在地图缩放时更新圆形遮罩和标记点的位置
				if (e.type === 'end' && e.causedBy === 'scale') {
					this.circles = [];
					this.markers = [];
					this.polyline = [];
					// this.getCenterPosition()
					// this.drawCircle();
					this.drawMarkers();
					this.drawPolyline();
				}
			}
	// 绘制行动路线
drawPolyline() {
				// 绘制行动路线
				const polyline = {
					points: JSON.parse(JSON.stringify(this.polyline)),
					color: '#ff0000', // 线路颜色
					width: 2 // 线路宽度
				};
				this.polyline.push(polyline);
				console.log(this.polyline)
			},
	

导航

	toMapAPP() {
				if (that.centerLat != '' && that.centerLng != '') {
					let that = this
					// 获取用户是否开启 授权获取当前的地理位置、速度的权限。
					uni.getSetting({
						success: (res) => {
							// 如果没有授权
							if (!res.authSetting['scope.userLocation']) {
								// 则拉起授权窗口
								uni.authorize({
									scope: 'scope.userLocation',
									success: () => {
										//如果授权了
										const latitudes = that.centerLat
										const longitudes = that.centerLng
										const address = that.address
										uni.openLocation({
											latitude: parseInt(latitudes), //到达的纬度
											longitude: parseInt(longitudes), //到达的经度
											name: address, //到达的名字
											scale: 12,
											success() {
												console.log('success')
											}
										})
									},
									fail(error) {
										//点击了拒绝授权后--就一直会进入失败回调函数--此时就可以在这里重新拉起授权窗口
										console.log('拒绝授权', error)

										uni.showModal({
											title: '提示',
											content: '若点击不授权,将无法使用位置功能',
											cancelText: '不授权',
											cancelColor: '#999',
											confirmText: '授权',
											confirmColor: '#f94218',
											success(res) {
												console.log(res)
												if (res.confirm) {
													// 选择弹框内授权
													uni.openSetting({
														success(res) {
															console.log(res
																.authSetting)
														}
													})
												} else if (res.cancel) {
													// 选择弹框内 不授权
													console.log('用户点击不授权')
												}
											}
										})
									}
								})
							} else {
								console.log('有授权');
								console.log(that.centerLat, that.centerLng)
								// 有权限则直接获取
								uni.getLocation({
									type: 'wgs84',
									success: (res) => {
										const latitudes = that.centerLat
										const longitudes = that.centerLng
										const address = that.address
										uni.openLocation({
											latitude: parseInt(latitudes), //到达的纬度
											longitude: parseInt(longitudes), //到达的经度
											name: address, //到达的名字
											scale: 12,
											success: (res) => {
												console.log('success', )
											},
											fail: (err) => {
												console.log('err', err)
											}
										})
									},
									fail(error) {
										uni.showToast({
											title: '请勿频繁调用!',
											icon: 'none',
										})
										console.log('失败', error)
									}
								})
							}
						}
					})
				} else {
					uni.showToast({
						title: '暂无信息',
						icon: 'none',
					})
				}

			},

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/974166.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

天软高频因子日内及隔夜动量因子

天软因子序列课程再次启动&#xff0c;本周四&#xff08;9月7日&#xff09;下午4点相约腾讯会议&#xff0c;可直接扫描下方二维码&#xff0c;欢迎大家参会&#xff01; 本次会议主要内容有&#xff1a; 1.介绍日内及隔夜动量因子的构造逻辑&#xff0c;如何选择市 场代理变…

Spring AOP与静态代理/动态代理

文章目录 一、代理模式静态代理动态代理代理模式与AOP 二、Spring AOPSping AOP用来处理什么场景jdk 动态代理cglib 动态代理面试题&#xff1a;讲讲Spring AOP的原理与执行流程 总结 一、代理模式 代理模式是一种结构型设计模式&#xff0c;它允许对象提供替代品或占位符&…

说说MySQL主从复制?

分析&回答 主从复制原理 主库记录binlog日志 在每次准备提交事务完成数据更新前&#xff0c;主库将数据更新的事件记录到二进制日志binlog中。主库上的sync_binlog参数控制binlog日志刷新到磁盘。 从库IO线程将主库的binlog日志复制到其本地的中继日志relay log中 从库会…

K8S的CKA考试环境和题目

CKA考试这几年来虽然版本在升级&#xff0c;但题目一直没有大的变化&#xff0c;通过K8S考试的方法就是在模拟环境上反复练习&#xff0c;通过练习熟悉考试环境和考试过程中可能遇到的坑。这里姚远老师详细向大家介绍一下考试的环境和题目&#xff0c;需要详细资料的同学请在文…

解决C++ 遇笔试题输入[[1,2,3,...,],[5,6,...,],...,[3,1,2,...,]]问题

目录 0 引言1 思路2 测试结果3 完整代码4 总结 0 引言 现在面临找工作问题&#xff0c;做了几场笔试&#xff0c;遇到了一个比较棘手的题目就是题目输入形式如下&#xff1a; [ [3,1,1], [3,5,3], [3,2,1] ] 当时遇到这个问题还是比较慌的&#xff0c;主要是之前没有遇到这样的…

RHCA之路---EX280(2)

RHCA之路—EX280(2) 1. 题目 Associate the share named /exports/registry to the built-in registry running within your OpenShift Enterprise instance so that it will be used for permanent storage Use exam-registry-volume for the volume name and exam-registry-…

公司内部传文件怎么安全——「用绿盾透明加密软件」

为保证公司内部文件传递的安全性&#xff0c;可以使用天锐绿盾透明加密软件来进行保护。以下是具体的操作步骤&#xff1a; 在公司内部部署天锐绿盾加密软件&#xff0c;确保需要传递的文件都能受到加密保护。 在员工的工作电脑上安装天锐绿盾客户端&#xff0c;并设置好相关的…

C++学习记录——삼십이 C++IO流

文章目录 1、C标准IO流2、C文件IO流1、二进制读写2、文本读写 3、stringstream 1、C标准IO流 C语言的printf和scanf无法很好的输入输出自定义类型&#xff0c;且还需要程序员自己确定类型&#xff0c;所以C就引入了输入流和输出流&#xff0c;是设备和内存之间的沟通。 其实io…

Gin学习记录3——模版与渲染

模版与渲染 一. 返回二. 模版2.1 基础模版2.2 同名模版2.3 模版继承2.4 模版语法 一. 返回 如果只是想返回数据&#xff0c;可以使用以下函数&#xff1a; func (c *Context) JSON(code int, obj any) func (c *Context) JSONP(code int, obj any) func (c *Context) String(…

阿里后端开发:抽象建模经典案例

0.引言 在互联网行业&#xff0c;软件工程师面对的产品需求大都是以具象的现实世界事物概念来描述的&#xff0c;遵循的是人类世界的自然语言&#xff0c;而软件世界里通行的则是机器语言&#xff0c;两者间跨度太大&#xff0c;需要一座桥梁来联通&#xff0c;抽象建模便是打…

一文读懂HOOPS Native平台:快速开发桌面端、移动端3D应用程序!

HOOPS Native Platform是用于在桌面和移动平台以及混合现实应用程序上构建3D工程应用程序的首要工具包。它由三个集成良好的软件开发工具包(SDK)组成&#xff1a;HOOPS Visualize、HOOPS Exchange、HOOPS Publish。HOOPS Visualize 是一个强大的图形引擎&#xff0c;适用于本机…

lement-ui 加载本地图片

实现图片展示时&#xff0c;发先本地的图片加载不了。 代码&#xff1a; <template><div><el-image src"../assets/logo.png" ></el-image></div> </template>结果发现不对&#xff0c;加载不出来&#xff0c;一查资料&#xf…

【Java】Jxls--轻松生成 Excel

1、介绍 Jxls 是一个小型 Java 库&#xff0c;可以轻松生成 Excel 报告。Jxls 在 Excel 模板中使用特殊标记来定义输出格式和数据布局。 Java 有一些用于创建 Excel 文件的库&#xff0c;例如Apache POI。这些库都很好&#xff0c;但都是一些较底层的库&#xff0c;因为它们要…

代码随想录算法训练营第42天 | ● 01背包问题,你该了解这些! ● 01背包问题,你该了解这些! 滚动数组 ● 416. 分割等和子集

文章目录 前言一、01背包问题&#xff0c;你该了解这些&#xff01;二、01背包问题&#xff0c;你该了解这些&#xff01; 滚动数组三、416. 分割等和子集总结 前言 01背包 一、01背包问题&#xff0c;你该了解这些&#xff01; 确定dp数组以及下标的含义 对于背包问题&#x…

2605. 从两个数字数组里生成最小数字

文章目录 Tag题目来源题目解读解题思路方法一&#xff1a;枚举比较法方法二&#xff1a;集合的位运算表示法 写在最后 Tag 【贪心】【位运算】【数组】 题目来源 2605. 从两个数字数组里生成最小数字 题目解读 给定两个各自只包含数字 1 到 9 的两个数组&#xff0c;每个数组…

git中的cherry-pick和merge有些区别以及cherry-pick怎么用

git中的cherry-pick和merge在使用场景上有些区别: cherry-pick用于将另一个分支的某一次或几次commit应用到当前分支。它可以选择性地拉取代码修改。merge用于将两个分支合并成一个新分支。它会把整个分支上的所有修改都合并过来。 具体区别:cherry-pick通常用于将bug修复从发…

Knife4j框架

简介&#xff1a;Knife4j是一款在线API文档框架&#xff0c;可以基于当前项目的控制器类中的配置生成文档&#xff0c;并自带调试功能。通俗来说就是将controller里面请求的接口文档化&#xff0c;便于前端人员熟知请求方式和参数。并且能自动化根据controller的更新而跟新。 用…

“历久弥新 | 用AI修复亚运珍贵史料”活动震撼来袭!

时隔近半个世纪&#xff0c;新中国第一次参与亚运会的影像资料将首次对外披露。只是年代久远&#xff0c;老照片老视频都有了岁月痕迹&#xff0c;画面不再清晰&#xff0c;这些珍贵史料急需你的帮助&#xff01; 一、活动介绍 2023年&#xff0c;正值亚运110周年&#xff0c…

VBA技术资料MF52:VBA_在Excel中突出显示前 10 个值

【分享成果&#xff0c;随喜正能量】一言之善&#xff0c;重于千金。善良不分大小&#xff0c;有时候你以为的一句话&#xff0c;小小的举手之劳&#xff0c;也可能就是别人的救赎&#xff01;不要吝啬你的善良&#xff0c;因为你永远不知道那小小的善良能给多少人带来光明。。…

RTSP协议学习

文章目录 RTSP协议学习单播&#xff0c;组播&#xff0c;广播单播&#xff08;Unicast&#xff09;和组播&#xff08;Multicast&#xff09;广播&#xff08;Broadcast&#xff09;学习思维导图一览 RTSP协议学习 ##工作原理 RTSP&#xff08;Real-Time Streaming Protocol&…