Browse Source

修改地图

ccjgmwz 3 years ago
parent
commit
03149871c5
4 changed files with 317 additions and 70 deletions
  1. 2 3
      manifest.json
  2. 4 2
      pages/order/index.vue
  3. 171 0
      pages/order/map.nvue
  4. 140 65
      pages/order/map.vue

+ 2 - 3
manifest.json

@@ -20,7 +20,6 @@
         "modules" : {
             "Maps" : {},
             "VideoPlayer" : {},
-            "Bluetooth" : {},
             "OAuth" : {}
         },
         /* 应用发布信息 */
@@ -55,8 +54,8 @@
             "sdkConfigs" : {
                 "maps" : {
                     "amap" : {
-                        "appkey_ios" : "64541bb9b52fe4d41d8ac5c1959cf4b9",
-                        "appkey_android" : "8a601d5716a812aaf65291da18dae719"
+                        "appkey_ios" : "b1ce5ff5cafa861ce00623ac4788a721",
+                        "appkey_android" : "77d75fbe6f68fc8e415b990bfc70daaa"
                     }
                 },
                 "push" : {

+ 4 - 2
pages/order/index.vue

@@ -113,9 +113,11 @@
 
 					</view>
 					<view class="row5 flex flex-end">
-						<image class="jt-icon" src="@/static/images/order/position.png" mode='widthFix'
+						<!-- <image class="jt-icon" src="@/static/images/order/position.png" mode='widthFix'
 							@click.stop="toMap(good)">
-						</image>
+						</image> -->
+						<view class="start normal" @click.stop="toMap(good)">
+							查看轨迹</view>
 						<view class="stop" @click.stop="accept(good,1)" v-if="good.cargoOwnerStatus=='待接单'">接受
 						</view>
 						<!-- <view class="stop active" @click.stop="accept(good,1)">接受</view> -->

+ 171 - 0
pages/order/map.nvue

@@ -0,0 +1,171 @@
+<template>
+	<view>
+		<map
+			v-if="polyline[0].points.length > 0"
+			id="myMap"
+			:markers="markers"
+			:polyline="polyline"
+			:latitude="polyline[0].points[0].latitude"
+			:longitude="polyline[0].points[0].longitude"
+			style="width: 100%; height: 2000rpx"
+			@updated="test"
+		/>
+		<view class="hcp-bottom">
+			<button v-if="startMove" @click="handleStopMove()">暂停移动</button>
+			<button v-else @click="handleStartMove()">开始移动</button>
+		</view>
+	</view>
+</template>
+
+<script>
+	 const img = '/static/logo.png';
+export default {
+	data() {
+		return {
+			scaleNum:10,
+			mapContext: null,			//地图对象
+			startMove: false,			//是否开始回放
+			nextPointIndex: 1,		//下一个坐标点的索引
+			durationTime: 1000,		//相邻两点动画持续时长默认1秒
+			//路线信息
+			polyline: [
+				{
+					width: 20,
+					points: [],
+					arrowLine: true,
+					color: '#3591FC',
+				}
+			],
+			//标记点(即移动标记物)
+			markers: [
+				{
+					id: 1,
+					width: 40,
+					height: 40,
+					latitude: 0,
+					longitude: 0,
+					iconPath: img,
+					anchor: {
+						x: 0.5,
+						y: 1
+					}
+				}
+			]
+		}
+	},
+	onLoad(option) {
+		this.getTrack()		//获取轨迹信息(只做演示,未进行远程请求)
+		
+	},
+	methods: {
+		//模拟获取远程数据
+		getTrack() {
+			this.polyline[0].points = [
+				{latitude: 39.997761, longitude: 116.478935},
+				{latitude: 39.997825, longitude: 116.478939},
+				{latitude: 39.998549, longitude: 116.478912},
+				{latitude: 39.998555, longitude: 116.478998},
+				{latitude: 39.998566, longitude: 116.479282},
+				{latitude: 39.998528, longitude: 116.479658},
+				{latitude: 39.998453, longitude: 116.480151},
+				{latitude: 39.998302, longitude: 116.480784},
+				{latitude: 39.998184, longitude: 116.481149},
+				{latitude: 39.997997, longitude: 116.481573},
+				{latitude: 39.997846, longitude: 116.481863},
+				{latitude: 39.997718, longitude: 116.482072},
+				{latitude: 39.997718, longitude: 116.482362},
+				{latitude: 39.998935, longitude: 116.483633},
+				{latitude: 39.998968, longitude: 116.48367},
+				{latitude: 39.999861, longitude: 116.484648}
+			]
+			for(var i =0 ;i<7200;i++){
+				var latitude = this.polyline[0].points[this.polyline[0].points.length -1].latitude + 0.0001
+				var longitude = this.polyline[0].points[this.polyline[0].points.length -1].longitude + 0.0001
+				this.polyline[0].points.push({latitude,longitude})
+			}
+			this.durationTime = Math.ceil(30000 / this.polyline[0].points.length)	//默认播放全程使用30秒,计算相连两点动画时长
+			this.initMapData()
+		},
+		//设置地图
+		initMapData() {
+			this.initMarkers()
+			this.mapContext = uni.createMapContext('myMap', this)
+			
+		},
+		test(){
+			console.log("1111111111111111")
+			this.mapContext.includePoints({
+				points:this.polyline[0].points,
+				padding:[100,100,1000,100]
+			})
+		},
+		//设置位置(从起点开始)
+		initMarkers() {
+			this.markers[0].latitude = this.polyline[0].points[0].latitude
+			this.markers[0].longitude = this.polyline[0].points[0].longitude
+		},
+		//开始移动
+		handleStartMove() {
+			
+			console.log("222222")
+			this.startMove = true
+			this.movePoint()
+		},
+		//停止移动
+		handleStopMove() {
+			this.startMove = false
+		},
+		//移动坐标
+		movePoint() {
+			/*
+			//也可以用这个方法
+			this.mapContext.moveAlong({
+				duration: 30000,
+				markerId: this.markers[0].id,
+				path: this.polyline[0].points
+			})
+			return
+			*/
+		   this.mapContext.moveAlong({
+		   	duration: 10000,
+		   	markerId: this.markers[0].id,
+		   	path: this.polyline[0].points
+		   })
+		   console.log("this.nextPointIndex1 ",this.nextPointIndex ,this.polyline[0].points.length - 1)
+		   console.log("this.startMove1",this.startMove)
+			// this.mapContext.translateMarker({
+			// 	duration: this.durationTime,
+			// 	markerId: this.markers[0].id,
+			// 	destination: {
+			// 		latitude: this.polyline[0].points[this.nextPointIndex].latitude,
+			// 		longitude: this.polyline[0].points[this.nextPointIndex].longitude
+			// 	},
+			// 	animationEnd: res => {
+					
+			// 		console.log("this.nextPointIndex ",this.nextPointIndex ,this.polyline[0].points.length - 1)
+			// 		console.log("this.startMove",this.startMove)
+			// 		//播放结束,继续移动到下一个点,最后一个点时结束移动
+			// 		if (this.nextPointIndex < this.polyline[0].points.length - 1) {
+			// 			this.nextPointIndex++
+			// 			if (this.startMove) {
+			// 				this.movePoint()
+			// 			}
+			// 		} else {
+			// 			this.nextPointIndex = 1
+			// 			this.startMove = false
+			// 		}
+			// 	}
+			// })
+		}
+	}
+};
+</script>
+
+<style lang="scss" scoped>
+.hcp-bottom {
+	left: 0;
+	bottom: 0;
+	width: 750rpx;
+	position: fixed;
+}
+</style>

+ 140 - 65
pages/order/map.vue

@@ -1,79 +1,154 @@
 <template>
-	<view class="shareImage">
-		<view style="">
-			<web-view id="mapContainer" :src="srcHandler()"></web-view>
+	<view>
+		<map
+			v-if="polyline[0].points.length > 0"
+			id="myMap"
+			:markers="markers"
+			:polyline="polyline"
+			:include-points="polyline[0].points"
+			:latitude="polyline[0].points[0].latitude"
+			:longitude="polyline[0].points[0].longitude"
+			style="width: 100%; height: calc(100vh - 90px)"
+		/>
+		<view class="hcp-bottom">
+			<button v-if="startMove" @click="handleStopMove()">暂停移动</button>
+			<button v-else @click="handleStartMove()">开始移动</button>
 		</view>
 	</view>
 </template>
+
 <script>
-	export default {
-		data() {
-			return {
-				bgColor: '#317AFE',
-				bool: false,
-				lat: '',
-				lng: ''
-			}
+	 const img = '/static/logo.png';
+export default {
+	data() {
+		return {
+			mapContext: null,			//地图对象
+			startMove: false,			//是否开始回放
+			nextPointIndex: 1,		//下一个坐标点的索引
+			durationTime: 1000,		//相邻两点动画持续时长默认1秒
+			//路线信息
+			polyline: [
+				{
+					width: 28,
+					points: [],
+					arrowLine: true,
+					color: '#3591FC',
+				}
+			],
+			//标记点(即移动标记物)
+			markers: [
+				{
+					id: 1,
+					width: 140,
+					height: 140,
+					latitude: 0,
+					longitude: 0,
+					iconPath: img,
+					anchor: {
+						x: 0.5,
+						y: 1
+					}
+				}
+			]
+		}
+	},
+	onLoad(option) {
+		this.getTrack()		//获取轨迹信息(只做演示,未进行远程请求)
+	},
+	methods: {
+		//模拟获取远程数据
+		getTrack() {
+			this.polyline[0].points = [
+				{latitude: 39.997761, longitude: 116.478935},
+				{latitude: 39.997825, longitude: 116.478939},
+				{latitude: 39.998549, longitude: 116.478912},
+				{latitude: 39.998555, longitude: 116.478998},
+				{latitude: 39.998566, longitude: 116.479282},
+				{latitude: 39.998528, longitude: 116.479658},
+				{latitude: 39.998453, longitude: 116.480151},
+				{latitude: 39.998302, longitude: 116.480784},
+				{latitude: 39.998184, longitude: 116.481149},
+				{latitude: 39.997997, longitude: 116.481573},
+				{latitude: 39.997846, longitude: 116.481863},
+				{latitude: 39.997718, longitude: 116.482072},
+				{latitude: 39.997718, longitude: 116.482362},
+				{latitude: 39.998935, longitude: 116.483633},
+				{latitude: 39.998968, longitude: 116.48367},
+				{latitude: 39.999861, longitude: 116.484648}
+			]
+			this.durationTime = Math.ceil(30000 / this.polyline[0].points.length)	//默认播放全程使用30秒,计算相连两点动画时长
+			this.initMapData()
+		},
+		//设置地图
+		initMapData() {
+			this.initMarkers()
+			this.mapContext = uni.createMapContext('myMap', this)
+		},
+		//设置位置(从起点开始)
+		initMarkers() {
+			this.markers[0].latitude = this.polyline[0].points[0].latitude
+			this.markers[0].longitude = this.polyline[0].points[0].longitude
 		},
-		created() {
-			this.getLngLat();
+		//开始移动
+		handleStartMove() {
+			this.startMove = true
+			this.movePoint()
 		},
-		onLoad(options) {
-			console.log(options)
-			this.obj = options
+		//停止移动
+		handleStopMove() {
+			this.startMove = false
 		},
-		methods: {
-			back(){
-				uni.navigateBack({
+		//移动坐标
+		movePoint() {
+			/*
+			//也可以用这个方法
+			this.mapContext.moveAlong({
+				duration: 30000,
+				markerId: this.markers[0].id,
+				path: this.polyline[0].points
+			})
+			return
+			*/
+		   // this.mapContext.moveAlong({
+		   // 	duration: 10000,
+		   // 	markerId: this.markers[0].id,
+		   // 	path: this.polyline[0].points
+		   // })
+		   console.log("this.nextPointIndex1 ",this.nextPointIndex ,this.polyline[0].points.length - 1)
+		   console.log("this.startMove1",this.startMove)
+			this.mapContext.translateMarker({
+				duration: this.durationTime,
+				markerId: this.markers[0].id,
+				destination: {
+					latitude: this.polyline[0].points[this.nextPointIndex].latitude,
+					longitude: this.polyline[0].points[this.nextPointIndex].longitude
+				},
+				animationEnd: res => {
 					
-				})
-			},
-			srcHandler() {
-				return `/hybrid/html/map.html?obj=${encodeURI(encodeURI(JSON.stringify(this.obj)))}`
-			},
-			getLngLat() {
-				uni.getLocation({
-					type: 'wgs84',
-					success: res => {
-						if (res.latitude) {
-							this.lat = res.latitude + ',' + res.longitude;
-							// this.lng = res.longitude;
-						} else {
-							if (uni.getSystemInfoSync().platform == 'android') {
-								var context = plus.android.importClass("android.content.Context");
-								var locationManager = plus.android.importClass(
-									"android.location.LocationManager");
-								var main = plus.android.runtimeMainActivity();
-								var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
-								this.bool = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)
-							}
-							if (this.bool === false) {
-								uni.showModal({
-									title: '提示',
-									content: '请打开定位服务',
-									success: ({
-										confirm,
-										cancel
-									}) => {
-										if (confirm) {
-											if (uni.getSystemInfoSync().platform == 'android') {
-												var Intent = plus.android.importClass(
-													'android.content.Intent');
-												var Settings = plus.android.importClass(
-													'android.provider.Settings');
-												var intent = new Intent(Settings
-													.ACTION_LOCATION_SOURCE_SETTINGS);
-												var main = plus.android.runtimeMainActivity();
-												main.startActivity(intent); // 打开系统设置GPS服务页面
-											}
-										}
-									}
-								});
-							}
+					console.log("this.nextPointIndex ",this.nextPointIndex ,this.polyline[0].points.length - 1)
+					console.log("this.startMove",this.startMove)
+					//播放结束,继续移动到下一个点,最后一个点时结束移动
+					if (this.nextPointIndex < this.polyline[0].points.length - 1) {
+						this.nextPointIndex++
+						if (this.startMove) {
+							this.movePoint()
 						}
+					} else {
+						this.nextPointIndex = 1
+						this.startMove = false
 					}
-				});
-			}
+				}
+			})
 		}
 	}
+};
 </script>
+
+<style lang="scss" scoped>
+.hcp-bottom {
+	left: 0;
+	bottom: 0;
+	width: 750rpx;
+	position: fixed;
+}
+</style>