|
@@ -1,17 +1,21 @@
|
|
|
<template>
|
|
|
<view class="map-box">
|
|
|
|
|
|
- <search @handleSearch="handleSearch" v-if="showMap" />
|
|
|
- <tiandituMap ref="tiandituMapRefs" @onLoadTianDiTu="initMaps" @onSelect="selectPoint" :apiKey="apiKey">
|
|
|
+ <search ref="searchRef" @handleSearch="handleSearch" v-if="showMap" />
|
|
|
+ <tiandituMap ref="tiandituMapRefs" @handleSearch="handleSearch" @clickMap="handleClickMap" @moveMap="moveMapSearch"
|
|
|
+ @onLoadTianDiTu="initMaps" @onSelect="selectPoint" :apiKey="apiKey">
|
|
|
</tiandituMap>
|
|
|
- <bab-Touchbox v-if="showMap && siteList && siteList.length > 0" :zIndex="1001" :minHeight="0.35" :maxHeight="0.8" :touchHeight="64"
|
|
|
- @currentHeight="setTouchHeight" @maxtHeight="setScrollMaxHeight">
|
|
|
+ <bab-Touchbox ref="TouchboxRef" v-if="showMap && siteListArr && siteListArr.length > 0" :zIndex="1001"
|
|
|
+ :minHeight="0.35" :maxHeight="0.8" :touchHeight="64" @currentHeight="setTouchHeight"
|
|
|
+ @maxtHeight="setScrollMaxHeight">
|
|
|
<scroll-view :style="{'height':TouchHeight - 40 +'px' }" scroll-y="true" :show-scrollbar="false">
|
|
|
- <template v-for="item in siteList">
|
|
|
+ <template v-for="item in siteListArr">
|
|
|
<siteListModel :info="item" />
|
|
|
</template>
|
|
|
</scroll-view>
|
|
|
</bab-Touchbox>
|
|
|
+
|
|
|
+ <siteDetails ref="siteDetailsRef" />
|
|
|
</view>
|
|
|
</template>
|
|
|
<script>
|
|
@@ -19,15 +23,19 @@
|
|
|
import search from "./model/search.vue"
|
|
|
import siteListModel from "./model/siteList.vue";
|
|
|
import { getMapCenterPoint_Api, getMapList_Api } from "@/api/map.js"
|
|
|
+ import { getLocation } from "@/utils/tool.js"
|
|
|
+ import siteDetails from "./model/siteDetails.vue"
|
|
|
export default {
|
|
|
name: 'tdtmap',
|
|
|
components: {
|
|
|
- // tiandituMap,
|
|
|
search,
|
|
|
- siteListModel
|
|
|
+ siteListModel,
|
|
|
+ siteDetails
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ selfLatitude: undefined,
|
|
|
+ selfLongitude: undefined,
|
|
|
showMap: false,
|
|
|
longitude: undefined,
|
|
|
latitude: undefined,
|
|
@@ -45,113 +53,108 @@
|
|
|
apikey: '123123',
|
|
|
},
|
|
|
|
|
|
- siteList: [],
|
|
|
+ siteListArr: [],
|
|
|
TouchHeight: 0,
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
- // if (navigator.geolocation) {
|
|
|
- // navigator.geolocation.getCurrentPosition(function(position) {
|
|
|
- // var latitude = position.coords.latitude;
|
|
|
- // var longitude = position.coords.longitude;
|
|
|
- // // 在这里处理获取到的经纬度
|
|
|
- // console.log("Longitude is :", latitude , longitude);
|
|
|
- // });
|
|
|
- // } else {
|
|
|
- // // 处理不支持 Geolocation 的情况
|
|
|
- // console.error("Error Code = " + error.code + " - " + error.message);
|
|
|
- // }
|
|
|
- // try {
|
|
|
- // uni.getLocation({
|
|
|
- // type:'wgs84',
|
|
|
- // cacheTimeout: 30 * 60,
|
|
|
- // success: Location => {
|
|
|
- // console.log("getLocation" , Location)
|
|
|
- // // const address = Location.address;
|
|
|
- // // // 缓存全局的定位信息
|
|
|
- // // app.globalData.location = address;
|
|
|
- // // this.location = address;
|
|
|
- // // if (!address.city) {
|
|
|
- // // uni.showToast({
|
|
|
- // // title: '获取定位失败',
|
|
|
- // // icon: 'none'
|
|
|
- // // })
|
|
|
- // // } else {
|
|
|
- // // uni.showToast({
|
|
|
- // // title: '获取定位成功,请开始抽奖',
|
|
|
- // // icon: 'none'
|
|
|
- // // })
|
|
|
- // // }
|
|
|
-
|
|
|
- // },
|
|
|
- // fail: LocationErr => {
|
|
|
- // console.log("LocationErr = " , LocationErr)
|
|
|
- // }
|
|
|
- // })
|
|
|
- // } catch (error) {
|
|
|
- // console.log("LocationErr = catch" , LocationErr)
|
|
|
- // }
|
|
|
- // // uni.getSystemInfo({
|
|
|
- // // success: function(res) {
|
|
|
- // // that.winWidth = res.windowWidth
|
|
|
- // // that.winHeight = res.windowHeight
|
|
|
- // // that.winTop = res.windowTop
|
|
|
- // // }
|
|
|
- // // });
|
|
|
+ console.log('获取位置失败 22211---------------');
|
|
|
+ try {
|
|
|
+ navigator.geolocation.getCurrentPosition(function(position) {
|
|
|
+ console.log("Latitude is :", position.coords.latitude);
|
|
|
+ console.log("Longitude is :", position.coords.longitude);
|
|
|
+ }, function(error) {
|
|
|
+ console.error("Error Code = " + error.code + " - " + error.message);
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ //TODO handle the exception
|
|
|
+ console.log('获取位置失败 999999999999 ---------------', error);
|
|
|
+ }
|
|
|
+ console.log('获取位置失败 22233---------------');
|
|
|
+ this.getMapCenterPoint()
|
|
|
},
|
|
|
mounted() {
|
|
|
- // this.open(114.294, 30.534)
|
|
|
- this.getMapCenterPoint()
|
|
|
+
|
|
|
+ getLocation().then(res => {
|
|
|
+ this.selfLatitude = res.longitude;
|
|
|
+ this.selfLongitude = res.latitude;
|
|
|
+ })
|
|
|
},
|
|
|
watch: {
|
|
|
- siteList: {
|
|
|
+ siteListArr: {
|
|
|
handler(newArr) {
|
|
|
- this.$refs.tiandituMapRefs.clearIcon();
|
|
|
- (newArr || []).forEach(el => {
|
|
|
- const { longitude, latitude, mapTypeIcon } = el
|
|
|
- this.$refs.tiandituMapRefs.setIcon(longitude, latitude, false, mapTypeIcon);
|
|
|
+ console.log('newArr === ' , newArr)
|
|
|
+ try {
|
|
|
+ this.$refs.tiandituMapRefs.clearIcon();
|
|
|
+ } catch (error) {}
|
|
|
+ this.$nextTick(() => {
|
|
|
+ (newArr || []).forEach(el => {
|
|
|
+ const { longitude, latitude, mapTypeIcon } = el
|
|
|
+ this.$refs.tiandituMapRefs.setIcon(longitude, latitude, false, mapTypeIcon);
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
deep: true
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 点击地图
|
|
|
+ handleClickMap() {
|
|
|
+ if (this.$refs.TouchboxRef) {
|
|
|
+ this.$refs.TouchboxRef.concealList()
|
|
|
+ }
|
|
|
+ },
|
|
|
// 获取地图中心点
|
|
|
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)
|
|
|
-
|
|
|
+ this.open(longitude, latitude, mapTypeIcon)
|
|
|
+ // this.$nextTick(() => {
|
|
|
+ // this.handleSearch()
|
|
|
+ // })
|
|
|
}).catch(err => { this.open(null, null) }).finally(() => {
|
|
|
uni.hideLoading()
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
+ moveMapSearch(parms) {
|
|
|
+ const { Lng, Lat } = parms;
|
|
|
+ this.longitude = Lng;
|
|
|
+ this.latitude = Lat;
|
|
|
+ this.$refs.searchRef.onSearchFocus()
|
|
|
+ // console.log("moveMapSearch", Lng, Lat)
|
|
|
+ },
|
|
|
handleSearch(val = {}) {
|
|
|
- const parms = { ...val, longitude: this.longitude, latitude: this.latitude };
|
|
|
+ const parms = {
|
|
|
+ ...val,
|
|
|
+ longitude: this.longitude,
|
|
|
+ latitude: this.latitude,
|
|
|
+ radius: 5000,
|
|
|
+ selfLatitude: this.selfLatitude,
|
|
|
+ selfLongitude: this.selfLongitude
|
|
|
+ };
|
|
|
getMapList_Api(parms).then(res => {
|
|
|
- if(!res || res.length === 0){
|
|
|
+ if (!res || res.length === 0) {
|
|
|
uni.showToast({
|
|
|
- title:"搜索结果为空",
|
|
|
- icon:'none'
|
|
|
+ title: "当前区域无服务",
|
|
|
+ icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
- this.siteList = res || [];
|
|
|
+ this.siteListArr = res || [];
|
|
|
}).catch(err => {
|
|
|
- this.siteList = [];
|
|
|
+ this.siteListArr = [];
|
|
|
})
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
- open(lon, lat , mapTypeIcon) {
|
|
|
+ open(lon, lat, mapTypeIcon) {
|
|
|
if (lon && lat) {
|
|
|
this.$nextTick(() => {
|
|
|
- this.$refs.tiandituMapRefs.initCharts(lon, lat , mapTypeIcon)
|
|
|
+ this.$refs.tiandituMapRefs.initCharts(lon, lat, mapTypeIcon)
|
|
|
this.showMap = true;
|
|
|
})
|
|
|
} else {
|
|
@@ -159,7 +162,7 @@
|
|
|
title: '提示',
|
|
|
content: '地图中心点获取错误,请联系管理员!',
|
|
|
success: res => {
|
|
|
- console.log("showModal == ", res)
|
|
|
+ // console.log("showModal == ", res)
|
|
|
if (res.confirm) {}
|
|
|
}
|
|
|
})
|
|
@@ -198,7 +201,7 @@
|
|
|
},
|
|
|
tk: this.apiKey,
|
|
|
}
|
|
|
- let resData = await tools.createRequest('http://api.tianditu.gov.cn/geocoder', params, true)
|
|
|
+ let resData = await tools.createRequest('https://api.tianditu.gov.cn/geocoder', params, true)
|
|
|
if (resData.status === '0') {
|
|
|
const location = resData.location
|
|
|
const formateOne = tools.formatterAdressLocation(resData, 3)
|
|
@@ -219,7 +222,7 @@
|
|
|
type: 'query',
|
|
|
tk: this.apiKey,
|
|
|
}
|
|
|
- let resData = await tools.createRequest('http://api.tianditu.gov.cn/v2/search', params, true)
|
|
|
+ let resData = await tools.createRequest('https://api.tianditu.gov.cn/v2/search', params, true)
|
|
|
if (resData.status.infocode === 1000) {
|
|
|
const {
|
|
|
pois: aPoints,
|
|
@@ -286,7 +289,7 @@
|
|
|
|
|
|
|
|
|
setTouchHeight(val) {
|
|
|
- console.log('setScrollHeight = ', val)
|
|
|
+ // console.log('setScrollHeight = ', val)
|
|
|
// 实时返回的滑动组件高度
|
|
|
this.TouchHeight = val;
|
|
|
},
|
|
@@ -294,6 +297,8 @@
|
|
|
//最大高度
|
|
|
this.scrollMaxHeight = val;
|
|
|
},
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
</script>
|