uniapp实现轨迹polyline和标记点markers最终实现效果

这篇具有很好参考价值的文章主要介绍了uniapp实现轨迹polyline和标记点markers最终实现效果。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

uniapp 使用map组件,实现自定义标记点markers图标及内容文字

<template>
	<view>
		<!--顶部轨迹-->
		<scroll-view class="scroll-view_H" scroll-x="true" scroll-left="0">
			<view class="topbox">
				<view class="locusnum" :class="{'selectlocusnum' : rSelect.indexOf(value.id)!=-1}"
					v-for="(value,index) in infoArr" :key="index" @tap="tapInfo(value.id)">
					{{value.name}}
				</view>
			</view>
		</scroll-view>

		<!--轨迹地图-->
		<view class="mapbox">
			<map class="mapstyle" :latitude="latitude" :longitude="longitude" :markers="markers" :polyline="polyline">
				<cover-view slot="callout">
					<block v-for="(item, index) in customCalloutMarkerIds" :key="index">
						<cover-view class="customCallout" :marker-id="item">
							<cover-view class="content">
								{{markersinit[index].stationName}}
							</cover-view>
						</cover-view>
					</block>
				</cover-view>
				<view class="map-floatA">共计3段轨迹</view>
				<view class="map-floatB">2022/09/28</view>
			</map>
		</view>

		<!--底部盒子-->
		<view class="bottomBox">
			<view class="oneTier">
				<view class="placeBox">
					<view class="twig">
						<view class="tag">起</view>
						<view class="taginfo">江门豪爵研发中心</view>
					</view>
					<view class="twig">
						<view class="tag">终</view>
						<view class="taginfo">席帽山森林公园</view>
					</view>
				</view>
				<view class="rideBox">
					<text class="ride-mileage">骑行里程/</text>
					<view class="ride-text">
						<text class="ride-textA">25.9</text>
						<text class="ride-textB">km</text>
					</view>
				</view>
			</view>

			<view class="num-storey">
				<view class="ride-numbox">
					<view class="ride-num numA">01:19:46</view>
					<view class="ride-name">骑行时长</view>
				</view>
				<view class="ride-numbox">
					<view class="ride-num">
						<text class="numA">78</text>
						<text class="numB">km/h</text>
					</view>
					<view class="ride-name">最高速度</view>
				</view>
				<view class="ride-numbox">
					<view class="ride-num">
						<text class="numA">59.3</text>
						<text class="numB">km/h</text>
					</view>
					<view class="ride-name">平均速度</view>
				</view>
			</view>

			<view class="num-storey">
				<view class="ride-numbox">
					<view class="ride-num">
						<text class="numA">178</text>
						<text class="numB">次</text>
					</view>
					<view class="ride-name">急刹车次数</view>
				</view>
				<view class="ride-numbox">
					<view class="ride-num">
						<text class="numA">131</text>
						<text class="numB">次</text>
					</view>
					<view class="ride-name">急加速次数</view>
				</view>
				<view class="ride-numbox">
					<view class="ride-num">
						<text class="numA">59</text>
						<text class="numB">次</text>
					</view>
					<view class="ride-name">急转弯次数</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				infoArr: [{
					name: "全天轨迹",
					id: -1
				}, {
					name: "轨迹1",
					id: 1
				}, {
					name: "轨迹2",
					id: 2
				}],
				rSelect: [-1], //按钮选中状态数组
				latitude: 39.909,
				longitude: 116.397,
				customCalloutMarkerIds: [0, 1, 3, 4],
				markersinit: [{
					id: 0,
					polylineId: 1,
					longitude: 116.368904,
					latitude: 39.913423,
					iconPath: "/static/img/icon/green.png",
					width: 38,
					height: 38,
					stationName: '1',
					customCallout: {
						anchorY: 22,
						anchorX: 0,
						display: 'ALWAYS',
					}
				}, {
					id: 1,
					polylineId: 1,
					longitude: 116.398258,
					latitude: 39.904600,
					iconPath: "/static/img/icon/red.png",
					width: 38,
					height: 38,
					stationName: '1',
					customCallout: {
						anchorY: 22,
						anchorX: 0,
						display: 'ALWAYS',
					}
				}, {
					id: 3,
					polylineId: 2,
					longitude: 116.358258,
					latitude: 39.904600,
					iconPath: "/static/img/icon/green.png",
					width: 38,
					height: 38,
					stationName: '2',
					customCallout: {
						anchorY: 22,
						anchorX: 0,
						display: 'ALWAYS',
					}
				}, {
					id: 4,
					polylineId: 2,
					longitude: 116.398258,
					latitude: 39.924600,
					iconPath: "/static/img/icon/red.png",
					width: 38,
					height: 38,
					stationName: '终',
					customCallout: {
						anchorY: 22,
						anchorX: 0,
						display: 'ALWAYS',
					}
				}],
				markers: [],
				polylineinit: [{ //初始值
						name: 'Track 1',
						arrowLine: true,
						color: '#27bd09e6',
						width: 8,
						id: 1,
						points: [{
								longitude: 116.368904,
								latitude: 39.913423
							},
							{
								longitude: 116.382122,
								latitude: 39.901176
							},
							{
								longitude: 116.387271,
								latitude: 39.912501
							},
							{
								longitude: 116.398258,
								latitude: 39.904600
							},
						],
					},
					{
						name: 'Track 2',
						arrowLine: true,
						color: '#27bd09e6',
						width: 8,
						id: 2,
						points: [{
								longitude: 116.358258,
								latitude: 39.904600
							},

							{
								longitude: 116.388258,
								latitude: 39.914600
							},
							{
								longitude: 116.398258,
								latitude: 39.924600
							},
						],
					},
				],
				polyline: [], //展示值
			};
		},
		// mounted(){
		// 	this.locusBtn()
		// },
		onShow() {
			this.locusBtn()
		},
		methods: {
			tapInfo(e) {
				if (this.rSelect.indexOf(e) == -1) {
					this.rSelect.splice(0, this.rSelect.length); //清空
					this.rSelect.push(e);
				} else {
					this.rSelect.splice(this.rSelect.indexOf(e), 1); //取消
				}
				this.locusBtn();
			},

			locusBtn() {
				if (this.rSelect.length > 0) {
					if (this.rSelect[0] === -1) {
						//全天轨迹
						this.polyline = JSON.parse(JSON.stringify(this.polylineinit));
						this.markers = JSON.parse(JSON.stringify(this.markersinit));
					} else {
						//非全天轨迹
						let arr = JSON.parse(JSON.stringify(this.polylineinit));
						let obj = arr.find(item => {
							return item.id == this.rSelect[0]
						});
						this.polyline = [obj];

						let markerArr = JSON.parse(JSON.stringify(this.markersinit));
						this.markers.splice(0, this.markers.length); //清空
						for (var i = 0; i < markerArr.length; i++) {
							if (markerArr[i].polylineId === this.rSelect[0]) {
								this.markers.push(markerArr[i])
							}
						}
					}
				}
			}
		},
	};
</script>

<style lang="scss">
	page {
		background-color: white;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
	}

	.topbox {
		margin: 0px 0px 0px 6rpx;
		display: flex;
		align-items: center;
	}

	.locusnum {
		padding: 14rpx 20rpx;
		margin: 4rpx 12rpx;
		text-align: center;
		font-size: 28rpx;
		color: #9b9b9b;
		border-radius: 10rpx;
		background-color: #f7f7f7;
	}

	.selectlocusnum {
		padding: 14rpx 20rpx;
		margin: 4rpx 12rpx;
		text-align: center;
		font-size: 28rpx;
		color: white;
		border-radius: 10rpx;
		background-color: black;
	}

	.mapbox {
		margin: 10rpx 20rpx;
	}

	.mapstyle {
		width: 100%;
		height: 360px;
		position: relative;
	}

	.map-floatA {
		width: 22%;
		position: absolute;
		bottom: 110rpx;
		left: 20rpx;
		background-color: #292929a6;
		color: white;
		font-size: 24rpx;
		padding: 10rpx 30rpx;
		border-radius: 10rpx;
		letter-spacing: 2rpx;
		text-align: center;
	}

	.map-floatB {
		width: 22%;
		position: absolute;
		bottom: 40rpx;
		left: 20rpx;
		background-color: #292929a6;
		color: white;
		font-size: 24rpx;
		padding: 10rpx 30rpx;
		border-radius: 10rpx;
		letter-spacing: 2rpx;
		text-align: center;
	}


	.bottomBox {
		margin: 10rpx 20rpx;
	}

	.oneTier {
		display: flex;
		justify-content: space-between;
	}

	.twig {
		width: 96%;
		// margin-bottom: 20rpx;
		display: flex;
		justify-content: flex-start;
	}

	.tag {
		width: 10%;
		font-size: 14px;
		padding: 14rpx;
		color: white;
		text-align: center;
		background-color: #999999;
		border-top-left-radius: 10rpx;
		border-bottom-left-radius: 10rpx;
	}

	.taginfo {
		width: 90%;
		font-size: 14px;
		padding: 14rpx 20rpx;
		text-align: left;
		color: #767676;
		background-color: #f7f7f7;
		border-top-right-radius: 10rpx;
		border-bottom-right-radius: 10rpx;
	}

	.placeBox {
		width: 66%;
		height: 140rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.rideBox {
		width: 34%;
		height: 134rpx;
		padding: 5rpx 20rpx;
		background-color: #f7f7f7;
		border-radius: 10rpx;
	}

	.ride-mileage {
		font-size: 14px;
		color: #959595;
	}

	.ride-text {
		margin-top: 10rpx;
	}

	.ride-textA {
		font-size: 60rpx;
		font-weight: bold;
		font-style: italic;
	}

	.ride-textB {
		margin-left: 20rpx;
		color: #949494;
		font-style: italic;
	}

	.num-storey {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.ride-numbox {
		width: 27%;
		height: 120rpx;
		margin-top: 14rpx;
		padding: 5rpx 20rpx;
		background-color: #f7f7f7;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.ride-num {
		margin-bottom: 10rpx;
	}

	.numA {
		font-size: 32rpx;
		font-weight: bold;
		font-style: italic;
	}

	.numB {
		font-size: 24rpx;
		margin-left: 20rpx;
		color: #949494;
		font-style: italic;
	}

	.ride-name {
		font-size: 14px;
		color: #959595;
	}

	.customCallout {
		padding: 2rpx 8rpx;
		text-align: center;
		color: #2A7BE2;
		font-size: 26rpx;
		font-weight: bold;
		background: #ffffffb8;
		border-radius: 30rpx;
	}
</style>

最终实现效果: 

 uniapp地图polyline,uni-app,前端uniapp地图polyline,uni-app,前端

uniapp地图polyline,uni-app,前端文章来源地址https://www.toymoban.com/news/detail-731034.html

到了这里,关于uniapp实现轨迹polyline和标记点markers最终实现效果的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • uniapp - 微信小程序实现腾讯地图位置标点展示,将指定地点进行标记选点并以一个图片图标展示出来(详细示例源码,一键复制开箱即用)

    在uniapp微信小程序平台端开发,简单快速的实现在地图上进行位置标点功能,使用腾讯地图并进行标点创建和设置(可以自定义标记点的图片)。 你只需要复制代码,改个标记图标和位置即可。

    2024年02月08日
    浏览(35)
  • uniapp小程序拖动地图,标记物固定地图中心不动,展示拖动后的位置信息

    思路:将标记物固定在地图正中间,地图拖动结束后,获取地图中心位置的经纬度信息 html代码 css代码 js代码 (小程序解析经纬度获取地址信息需申请腾讯地图key并下载SDK文件)

    2024年02月14日
    浏览(36)
  • 基于微信小程序地图组件实现行车轨迹

    微信小程序是一款能够开发出各种功能的便捷工具,其中内置的地图组件,为我们提供了强大的地图展示和交互的能力,为我们的开发节约了不少时间和精力。同时,利用微信小程序内置的定时器,我们也能够简单地实现经纬度轨迹移动的效果。 在这个程序中,我们需要用到

    2024年02月03日
    浏览(38)
  • Unity地面交互效果——2、动态法线贴图实现轨迹效果

    回到目录 Unity引擎动态法线贴图制作球滚动轨迹   大家好,我是阿赵。   之前说了一个使用局部UV采样来实现轨迹的方法。这一篇在之前的基础上,使用法线贴图进行凹凸轨迹的绘制。   先来回顾一下,上一篇最终我们已经绘制了一个轨迹的贴图   可以思考一下,

    2024年02月06日
    浏览(56)
  • 地图轨迹跟踪系统设计与实现(Android+Eclipse+APP)

    目 录 1 在线地图轨迹APP概述 1 1.1 本论文的背景及意义 1 1.2 本论文的主要方法和研究进展 1 1.3 本论文的主要内容 1 1.4 本论文的结构安排 1 2 系统分析 3 2.1 研究目标 3 2.2 可行性分析 3 2.2.1 经济可行性 3 2.2.2 技术的可行性 3 2.3 需求分析 3 2.4 性能分析 4 3 系统开发环境及相关技术

    2024年02月15日
    浏览(22)
  • 微信小程序地图添加marker

    本文章是在uniapp开发的微信小程序中使用腾讯地图,在地图上添加标记 // 添加地图标记的方法     addMarkers(driverList) {   //driverList为需要添加到地图标记上的司机数组                 const markers = []   //地图标记数组                 driverList.forEach(item = {       

    2024年02月08日
    浏览(34)
  • 百度地图JavaScript API添加自定义Marker

    官网指导添加自定义Marker 实际使用中发现无法显示图标,找了一些博客 百度地图开发自定义图标无法显示的问题 百度地图自定义图标不显示问题解决方案 关于百度地图开放平台api覆盖物“自定义Marker图标”不能正常显示的解决方案 百度电子地图自定义marker图标 百度地图

    2024年02月07日
    浏览(35)
  • VUE3+TS+element UI +高德地图实现轨迹回放带进度条

    记录一下,由于项目需要做车辆的历史轨迹回放,查了很多资料,在高德地图里有这几种解决方案。 所用技术:vue3 + TS +element UI plus +高德地图  这是相关的Demo借鉴 高德地图的轨迹回放demo 轨迹巡航器控制 高德地图Amap UI 下面是效果图: 1,这是高德地图提供的轨迹回放demo

    2024年02月11日
    浏览(51)
  • Uniapp实现微信小程序跑步运动轨迹、历史轨迹和轨迹回放等功能

    一、先看效果 【跑跑步】微信小程序 二、实现功能         【跑跑步】是一款基于Uniapp开发的微信小程序,主要实现了跑步轨迹记录、历史轨迹、轨迹纠偏、轨迹回放和轨迹排名等功能。室内跑步记录正在开发,还没有发布,主要利用手机加速度传感器实现计步功能。更多

    2024年02月09日
    浏览(46)
  • uniapp 微信小程序实现运动轨迹、行车轨迹、历史轨迹、轨迹回放、不同速度有不同的路线颜色

    先看效果 实现效果: 根据不同速度绘制不同颜色的轨迹 根据终点起点获取地图中心点,尽可能在屏幕内完全展示轨迹 获取最快的路段并显示 自定义点图标 实现步骤: map组件 view标签部分 js部分 points 数据格式 注意:由于小程序会不断更新迭代,源码和体验效果可能有一定

    2024年02月11日
    浏览(55)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包