Fly 5 hónapja%!(EXTRA string=óta)
szülő
commit
88d98a56a6

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 327 - 108
components/tiandituMap/tiandituMap - 副本.vue


+ 5 - 3
components/tiandituMap/tiandituMap.vue

@@ -326,7 +326,7 @@
 			},
 			addMapEvent() {
 				//移除地图的移动停止事件
-				this.getLocation()
+				// this.getLocation()
 				this.removeMapEvent()
 				if (Tmap) {
 					Tmap.addEventListener("moveend", this.MapMoveend);
@@ -368,6 +368,7 @@
 					// 		})
 					// 	}
 					// }
+					console.log('this.checkedDot === ' , this.checkedDot)
 					// 地图移动,判断是否缩放/移动地图,还是通过点位定位
 					if (!this.checkedDot) {
 						const v = e.target.getCenter()
@@ -482,7 +483,6 @@
 				}
 			},
 			initChartsRender() {
-				this.$ownerInstance.callMethod('compliteonLoadTianDiTu')
 				const {
 					lng,
 					lat
@@ -502,7 +502,9 @@
 				// 	console.log('addEventListener  = ' , e)
 				// });
 				this.addMapEvent()
-				this.$emit("handleSearch")
+				
+				this.$ownerInstance.callMethod('compliteonLoadTianDiTu')
+				// this.$emit("handleSearch")
 			},
 			// upDataChartsRender(lng, lat) {
 			// 	if (!Tmap) return

+ 85 - 45
pages/map/index.vue

@@ -1,6 +1,6 @@
 <template>
 	<view class="map-box">
-		<search ref="searchRef" @handleSearch="handleSearch" v-if="showMap" />
+		<search ref="searchRef" @handleSearch="handleSearch" v-show="showMap" />
 
 		<tiandituMap ref="tiandituMapRefs" @handleSearch="$refs.searchRef.onSearchFocus()" @clickMap="handleClickMap"
 			@moveMap="moveMapSearch" @onLoadTianDiTu="initMaps" @onSelect="selectPoint" :apiKey="apiKey"
@@ -8,7 +8,7 @@
 			:searchDot="searchDot" @openHint="$refs.HintContentRef.open()" @openFeedback="goPages('feedback')" />
 
 
-		<Touchbox ref="TouchboxRef" :maxHeight="0.8" v-if="showMap && siteListArr && siteListArr.length > 0"
+		<Touchbox ref="TouchboxRef" :maxHeight="0.8" v-show="showMap && siteListArr && siteListArr.length > 0"
 			:zIndex="1001" @currentHeight="e => TouchHeight = e">
 			<template #touchSlot>
 				<!-- 	<view class="centre-box" v-if="SearchText">
@@ -48,14 +48,24 @@
 	import search from "./model/search.vue"
 	import siteListModel from "./model/siteList.vue";
 	import tools from '@/components/tiandituMap/tools.js'
-	import { getMapCenterPoint_Api, getMapList_Api, getVisituvpv_Api } from "@/api/map.js"
+	import {
+		getMapCenterPoint_Api,
+		getMapList_Api,
+		getVisituvpv_Api
+	} from "@/api/map.js"
 	import siteDetails from "./model/siteDetails.vue"
 	import $config from "@/config/index.js"
-	import { EventBus } from "@/utils/vueBus.js"
-	import { getLocation } from "@/utils/tool.js"
+	import {
+		EventBus
+	} from "@/utils/vueBus.js"
+	import {
+		getLocation
+	} from "@/utils/tool.js"
 	import serviceCenter from "./model/service-center.vue"
 	import HintContent from "./model/hint.vue"
-	import { getUUID } from "@/utils/tool.js";
+	import {
+		getUUID
+	} from "@/utils/tool.js";
 	export default {
 		name: 'tdtmap',
 		components: {
@@ -80,8 +90,8 @@
 
 
 
-				longitude: undefined,
-				latitude: undefined,
+				longitude: '114.28944',
+				latitude: '30.66195',
 				apiKey: $config.tianKey,
 				winWidth: 0,
 				winHeight: 0,
@@ -102,9 +112,9 @@
 			}
 		},
 		created() {
-			getLocation();
+			// getLocation();
 
-			this.getMapCenterPoint()
+			// this.getMapCenterPoint()
 		},
 		mounted() {
 			const userLabel = getUUID();
@@ -117,7 +127,8 @@
 			// 	console.log("this.$refs.SelectMapNavigationRef = " , this.$refs.SelectMapNavigationRef)
 			// 	this.$refs.SelectMapNavigationRef.open()
 			// }, 3000)
-			this.disableScroll()
+			this.disableScroll();
+			this.open(this.longitude, this.latitude);
 		},
 		beforeDestroy() {
 			try {
@@ -135,16 +146,58 @@
 
 		},
 		methods: {
+			async initMaps() {
+				console.warn('--------天地图加载完成--------');
+				this.$emit('onLoad') 
+				try {
+					uni.showLoading()
+					const { longitude, latitude } = await getLocation();
+					// console.log("longitude, latitude = " , longitude, latitude)
+					if(longitude && latitude){
+						this.longitude = longitude;
+						this.latitude = latitude;
+						this.movePT({longitude , latitude} , true)
+						uni.hideLoading()
+						this.handleSearch()
+					}else{
+						throw new Error()	
+					}
+						// this.longitude = '114.25497';
+						// this.latitude = '30.62832';
+						// this.movePT({longitude:this.longitude , latitude:this.latitude} , true)
+						// uni.hideLoading()
+						// this.handleSearch()
+				} catch (error) {
+					uni.hideLoading()
+					this.getMapCenterPoint()
+				} finally{
+					this.showMap = true;
+				}
+			},
+			/**
+			 * 移动到中心点
+			 * PT 点位
+			 * refresh 移动之后是否刷新获取数据
+			*/
+			movePT(PT , refresh = false){
+				this.$refs.tiandituMapRefs.SelectedDot({longitude:this.longitude , latitude:this.latitude} , !refresh)
+			},
 			// 获取地图中心点
 			getMapCenterPoint() {
 				uni.showLoading()
-				this.showMap = false;
 				getMapCenterPoint_Api().then(res => {
-					const { longitude, latitude, mapTypeIcon } = res || {};
+					const {
+						longitude,
+						latitude,
+						mapTypeIcon
+					} = res || {};
 					this.longitude = longitude;
 					this.latitude = latitude;
-					this.open(longitude, latitude, mapTypeIcon);
-				}).catch(err => { this.open(null, null) }).finally(() => {
+					this.movePT({longitude , latitude} , true)
+					this.handleSearch()
+				}).catch(err => {
+					this.open(null, null)
+				}).finally(() => {
 					uni.hideLoading()
 				})
 			},
@@ -152,7 +205,6 @@
 				if (lon && lat) {
 					this.$nextTick(() => {
 						this.$refs.tiandituMapRefs.initCharts(lon, lat, mapTypeIcon)
-						this.showMap = true;
 					})
 				} else {
 					uni.showModal({
@@ -167,6 +219,7 @@
 
 			},
 			handleSearch(val = {}) {
+				this.showMap = true;
 				const parms = {
 					...val,
 					longitude: this.longitude,
@@ -204,28 +257,6 @@
 			},
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 			getScrollHeight(TouchHeight, centreText) {
 				const h = centreText ? this.centreTextHeight : 0
 				return TouchHeight - h - 15 + 'px'
@@ -234,7 +265,9 @@
 				if (typeof window.addEventListener === 'function') {
 					document.addEventListener('touchmove', function(e) {
 						e.preventDefault();
-					}, { passive: false });
+					}, {
+						passive: false
+					});
 					document.body.addEventListener('mousewheel', function(e) {
 						e.preventDefault();
 					});
@@ -278,10 +311,20 @@
 			},
 
 			moveMapSearch(parms) {
-				const { Lng, Lat } = parms;
+				console.log('moveMapSearch = ' ,1 )
+				const {
+					Lng,
+					Lat
+				} = parms;
 				this.longitude = Lng;
 				this.latitude = Lat;
-				this.$refs.searchRef.onSearchFocus()
+				
+				if(this.$refs.searchRef){
+					this.$refs.searchRef.onSearchFocus()
+				}else{
+					this.handleSearch()
+				}
+				// 
 				// console.log("moveMapSearch", Lng, Lat)
 			},
 
@@ -390,10 +433,7 @@
 				this.datalist = [e]
 				this.selectItem = e
 			},
-			initMaps() {
-				console.warn('--------天地图加载完成--------');
-				this.$emit('onLoad')
-			},
+
 			// start(e) {
 			// 	const clientY = e.changedTouches[0].clientY
 			// 	this.startY = clientY

+ 22 - 2
utils/tool.js

@@ -55,7 +55,7 @@ export const getLocation = () => {
 			uni.getLocation({
 				type: 'wgs84', // 返回可以用于uni.openLocation的经纬度
 				success: (res) => {
-					console.log("getLocation 1111111111111111111= ", res)
+					// console.log("getLocation 1111111111111111111= ", res)
 					// this.selfLatitude = res.longitude;
 					// this.selfLongitude = res.latitude;
 					resolve(res)
@@ -63,11 +63,16 @@ export const getLocation = () => {
 				fail: (err) => {
 					console.log('获取位置失败2 :', err);
 					reject()
+				},
+				complete() {
+					console.log('获取位置失败结束1');
 				}
 			});
 		} catch (error) {
 			console.log('获取位置失败 1:', error);
-			//TODO handle the exception
+			reject()
+		} finally{
+			console.log('获取位置失败结束2');
 		}
 	})
 }
@@ -180,4 +185,19 @@ export const getUUID = () => {
 			16
 		);
 	});
+}
+
+export const createTianditu = (key) => {
+	console.log("key keykeykeykeykeykeykeykeykeykey= " , key)
+  return new Promise((resolve, reject) => {
+    if (window.T) {
+      resolve(window.T);
+      return;
+    }
+    const script = document.createElement('script');
+    script.src = `https://api.tianditu.gov.cn/api?v=4.0&tk=${key}`;
+    script.onload = () => resolve(window.T);
+    script.onerror = reject;
+    document.head.appendChild(script);
+  });
 }