|
@@ -31,6 +31,7 @@
|
|
|
checkedDot: false,
|
|
|
Tmap: null,
|
|
|
option: {
|
|
|
+ // dotPath:dotPath,
|
|
|
type: '',
|
|
|
apikey: '',
|
|
|
lng: '',
|
|
@@ -41,7 +42,7 @@
|
|
|
},
|
|
|
|
|
|
created() {
|
|
|
-
|
|
|
+ console.log('===== ', this.option)
|
|
|
},
|
|
|
mounted() {
|
|
|
|
|
@@ -53,9 +54,11 @@
|
|
|
compliteonLoadTianDiTu() {
|
|
|
this.$emit('onLoadTianDiTu')
|
|
|
|
|
|
+
|
|
|
},
|
|
|
initCharts(lng, lat, iconPng) {
|
|
|
this.option = {
|
|
|
+ ...this.option,
|
|
|
apikey: this.apiKey,
|
|
|
lng,
|
|
|
lat,
|
|
@@ -109,9 +112,27 @@
|
|
|
<script module="Trenderjs" lang="renderjs">
|
|
|
import { EventBus } from "@/utils/vueBus.js"
|
|
|
import iconPath from '@/static/images/point.png'
|
|
|
+ import dotPath from '@/static/images/dot.png'
|
|
|
+ import locationPath from '@/static/images/location.png'
|
|
|
+ import $confog from "@/config/index.js"
|
|
|
+ import { mapGetters } from "vuex"
|
|
|
+ const { type } = $confog
|
|
|
var Tmap = null;
|
|
|
const left = -(uni.upx2px(150));
|
|
|
export default {
|
|
|
+ props: {
|
|
|
+ // 点位列表
|
|
|
+ siteListArr: {
|
|
|
+ type: Array,
|
|
|
+ default: () => {
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ searchDot: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
options: {},
|
|
@@ -120,17 +141,157 @@
|
|
|
MyLngLat: {
|
|
|
lng: '',
|
|
|
lat: ''
|
|
|
- }
|
|
|
+ },
|
|
|
+ // 中心点位
|
|
|
+ centreDot: null,
|
|
|
+ // 中心点位地址解析
|
|
|
+ centreText: null,
|
|
|
+ // 中心点信息
|
|
|
+ centreMarker: '',
|
|
|
+ // 我的点位信息
|
|
|
+ MyMarker: null
|
|
|
+
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ computed: {
|
|
|
+ ...mapGetters(['useLocation'])
|
|
|
+ },
|
|
|
mounted() {
|
|
|
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
this.removeMapEvent()
|
|
|
},
|
|
|
+
|
|
|
+ watch: {
|
|
|
+ siteListArr: {
|
|
|
+ handler(newL, oldL) {
|
|
|
+ this.handleSiteList(newL)
|
|
|
+ },
|
|
|
+ deep: true,
|
|
|
+ immediate: true
|
|
|
+ },
|
|
|
+ centreText: {
|
|
|
+ handler(newL, oldL) {
|
|
|
+ if (newL && newL !== oldL) {
|
|
|
+ this.$emit("centre-text-callback", newL)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
+ },
|
|
|
+ useLocation: {
|
|
|
+ handler(newL, oldL) {
|
|
|
+ if (this.MyMarker) this.setMyIcon()
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
+ }
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ handleSiteList(newArr) {
|
|
|
+ this.clearIcon().then(async (res) => {
|
|
|
+ const dotArr = []
|
|
|
+ if (Tmap) await this.getMapCenter();
|
|
|
+
|
|
|
+ const { Lng, Lat } = this.centreDot || {};
|
|
|
+ let maxIcon = false;
|
|
|
+ (newArr || []).forEach((el, index) => {
|
|
|
+ el.maxIcon = false;
|
|
|
+ // 通过搜索自动移动到收索返回的第一个点位
|
|
|
+ if (index === 0 && this.searchDot) {
|
|
|
+ this.SelectedDot(el, true, 12)
|
|
|
+ }
|
|
|
+ const { longitude, latitude, mapTypeIcon } = el;
|
|
|
+ if (Lng == el.longitude && Lat == el.latitude) {
|
|
|
+ el.maxIcon = true;
|
|
|
+ maxIcon = true;
|
|
|
+ };
|
|
|
+ this.setIcon(el);
|
|
|
+ });
|
|
|
+ // 是否标记中心点
|
|
|
+ if (!maxIcon) this.setCentre()
|
|
|
+ this.setMyIcon()
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ // console.log('siteListArr = ', newL)
|
|
|
+ // if (this.siteListArr && this.siteListArr.length) {
|
|
|
+ // setTimeout(() => {
|
|
|
+ // console.log("this.centreDot 1 = ", this.centreDot)
|
|
|
+ // const { longitude, latitude, mapTypeIcon } = el;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // }, 10);
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+ getMapCenter() {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ const Fn = () => {
|
|
|
+ if (Tmap) {
|
|
|
+ const c = Tmap.getCenter();
|
|
|
+ this.centreDot = {
|
|
|
+ Lng: c.getLng(),
|
|
|
+ Lat: c.getLat()
|
|
|
+ };
|
|
|
+ this.dotParse(c);
|
|
|
+ resolve()
|
|
|
+ } else {
|
|
|
+ setTimeout(() => {
|
|
|
+ Fn()
|
|
|
+ }, 100);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Fn()
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ // 中心点位逆解析
|
|
|
+ dotParse(v) {
|
|
|
+ try {
|
|
|
+ const geocode = new T.Geocoder();
|
|
|
+ geocode.getLocation(v, (result) => {
|
|
|
+ if (result.getStatus() == 0) {
|
|
|
+ let t = '';
|
|
|
+ const Address = result.getAddress()
|
|
|
+ try {
|
|
|
+ if (Address && Address.indexOf('湖北省武汉市') === 0) {
|
|
|
+ const lo = Address.split('湖北省武汉市')
|
|
|
+ lo.forEach((el, index) => {
|
|
|
+ if (index >= 1) {
|
|
|
+ t = `${t}${el}`
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ //TODO handle the exception
|
|
|
+ }
|
|
|
+ this.centreText = t || Address
|
|
|
+ } else {
|
|
|
+ this.centreText = null
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ this.centreText = null
|
|
|
+ }
|
|
|
+ },
|
|
|
onPosition() {
|
|
|
// const { longitude, latitude } = { longitude: 114.414431, latitude: 30.482926 };
|
|
|
// this.SelectedDot({ longitude, latitude })
|
|
@@ -142,13 +303,17 @@
|
|
|
// this.setMyIcon()
|
|
|
|
|
|
EventBus.$emit('TianDiTuSearch', (res) => {
|
|
|
- const { longitude, latitude } = res;
|
|
|
- this.SelectedDot({ longitude, latitude })
|
|
|
- this.MyLngLat = {
|
|
|
- lng: longitude,
|
|
|
- lat: latitude
|
|
|
+ const { longitude, latitude } = res || {};
|
|
|
+ if (longitude && latitude) {
|
|
|
+ this.SelectedDot({ longitude, latitude })
|
|
|
}
|
|
|
- this.clearIcon()
|
|
|
+
|
|
|
+ // // this.SelectedDot({ longitude, latitude })
|
|
|
+ // // this.MyLngLat = {
|
|
|
+ // // lng: longitude,
|
|
|
+ // // lat: latitude
|
|
|
+ // // }
|
|
|
+ // // this.clearIcon()
|
|
|
})
|
|
|
|
|
|
},
|
|
@@ -175,14 +340,36 @@
|
|
|
// 移动地图,获取中心点
|
|
|
MapMoveend(e) {
|
|
|
try {
|
|
|
- console.log('------------------')
|
|
|
+ // if (type === 'H6') {
|
|
|
+ // const v = e.target.getCenter()
|
|
|
+ // // 自然缩放移动,刷新接口
|
|
|
+ // const Lng = v.getLng();
|
|
|
+ // const Lat = v.getLat();
|
|
|
+ // this.$emit("moveMap", { Lng, Lat })
|
|
|
+ // } else {
|
|
|
+ // // 地图移动,判断是否缩放/移动地图,还是通过点位定位
|
|
|
+ // if (!this.checkedDot) {
|
|
|
+ // const v = e.target.getCenter()
|
|
|
+ // // 自然缩放移动,刷新接口
|
|
|
+ // const Lng = v.getLng();
|
|
|
+ // const Lat = v.getLat();
|
|
|
+ // this.$emit("moveMap", { Lng, Lat })
|
|
|
+ // } else {
|
|
|
+ // // 点位移动,做处理
|
|
|
+ // this.$nextTick(() => {
|
|
|
+ // this.checkedDot = false;
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // }
|
|
|
// 地图移动,判断是否缩放/移动地图,还是通过点位定位
|
|
|
if (!this.checkedDot) {
|
|
|
- // 自然缩放移动,刷新接口
|
|
|
const v = e.target.getCenter()
|
|
|
- const Lng = v.getLng();
|
|
|
- const Lat = v.getLat();
|
|
|
- this.$emit("moveMap", { Lng, Lat })
|
|
|
+ // 自然缩放移动,刷新接口
|
|
|
+ if (v) {
|
|
|
+ const Lng = v.getLng();
|
|
|
+ const Lat = v.getLat();
|
|
|
+ this.$emit("moveMap", { Lng, Lat })
|
|
|
+ }
|
|
|
} else {
|
|
|
// 点位移动,做处理
|
|
|
this.$nextTick(() => {
|
|
@@ -190,6 +377,7 @@
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+
|
|
|
} catch (error) {
|
|
|
//TODO handle the exception
|
|
|
}
|
|
@@ -197,10 +385,11 @@
|
|
|
|
|
|
// 点击地图标注的点位
|
|
|
clickMapSite({ type, target, lnglat, containerPoint }) {
|
|
|
- console.log('clickMapSite === ', 1)
|
|
|
+ console.log("type, target, lnglat, containerPoint = ", type, target, lnglat, containerPoint)
|
|
|
const Lng = lnglat.getLng();
|
|
|
const Lat = lnglat.getLat();
|
|
|
this.$emit('handleMapSite', { Lng, Lat })
|
|
|
+
|
|
|
},
|
|
|
// 天地图缩放事件
|
|
|
handleZoomEvent(event) {
|
|
@@ -220,7 +409,7 @@
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- initTmap() {
|
|
|
+ initTmap_() {
|
|
|
try {
|
|
|
Tmap = null;
|
|
|
Tmap = new T.Map('mapDiv', {
|
|
@@ -252,6 +441,7 @@
|
|
|
},
|
|
|
|
|
|
initTMap(newValue, oldValue, ownerInstance, instance) {
|
|
|
+ console.log('-----1----', newValue)
|
|
|
this.options = newValue
|
|
|
if (newValue.type === 'open' && newValue.apikey) {
|
|
|
if (!window.T) {
|
|
@@ -265,7 +455,7 @@
|
|
|
lng,
|
|
|
lat
|
|
|
} = this.options
|
|
|
- this.initTmap()
|
|
|
+ this.initTmap_()
|
|
|
Tmap.centerAndZoom(new T.LngLat(lng, lat), 15);
|
|
|
this.$ownerInstance.callMethod('nextPoint', {
|
|
|
lng,
|
|
@@ -293,9 +483,8 @@
|
|
|
lat
|
|
|
} = this.options
|
|
|
var that = this;
|
|
|
- this.initTmap()
|
|
|
+ this.initTmap_()
|
|
|
Tmap.centerAndZoom(new T.LngLat(lng, lat), 15);
|
|
|
- this.setIcon(lng, lat, true)
|
|
|
this.$ownerInstance.callMethod('nextPoint', {
|
|
|
lng,
|
|
|
lat
|
|
@@ -310,21 +499,23 @@
|
|
|
this.addMapEvent()
|
|
|
this.$emit("handleSearch")
|
|
|
},
|
|
|
- upDataChartsRender(lng, lat) {
|
|
|
- if (!Tmap) return
|
|
|
- this.setIcon(lng, lat, true)
|
|
|
- Tmap.centerAndZoom(new T.LngLat(lng, lat), 15);
|
|
|
- },
|
|
|
- setIcon(lng, lat, isClear, iconU, info, max = false) {
|
|
|
- if (isClear) {
|
|
|
- this.clearIcon()
|
|
|
- }
|
|
|
+ // upDataChartsRender(lng, lat) {
|
|
|
+ // if (!Tmap) return
|
|
|
+ // this.setIcon(lng, lat, true)
|
|
|
+ // Tmap.centerAndZoom(new T.LngLat(lng, lat), 15);
|
|
|
+ // },
|
|
|
+ // setIcon(lng, lat, isClear, iconU, info, max = false) {
|
|
|
+ setIcon(row) {
|
|
|
+ const { longitude, latitude, mapTypeIcon, locationName, maxIcon } = row
|
|
|
+
|
|
|
+ // this.setCentre({ lng, lat })
|
|
|
+ // return
|
|
|
const icon = new T.Icon({
|
|
|
- iconUrl: iconU || this.options.png,
|
|
|
- iconSize: max ? new T.Point(60, 60) : new T.Point(45, 45),
|
|
|
+ iconUrl: mapTypeIcon || this.options.png,
|
|
|
+ iconSize: maxIcon ? new T.Point(60, 60) : new T.Point(45, 45),
|
|
|
iconAnchor: new T.Point(15, 45)
|
|
|
});
|
|
|
- const marker = new T.Marker(new T.LngLat(lng, lat), {
|
|
|
+ const marker = new T.Marker(new T.LngLat(longitude, latitude), {
|
|
|
icon
|
|
|
});
|
|
|
// 点位注册点击事件
|
|
@@ -335,11 +526,11 @@
|
|
|
// 缓存注册点击事件的点位
|
|
|
this.markerList.push(marker)
|
|
|
Tmap.addOverLay(marker);
|
|
|
- if (info) {
|
|
|
+ if (locationName) {
|
|
|
try {
|
|
|
var label = new T.Label({
|
|
|
- // text: this.setLable(info.locationName),
|
|
|
- text: info.locationName,
|
|
|
+ // text: this.setLable(locationName),
|
|
|
+ text: locationName,
|
|
|
position: marker.getLngLat(),
|
|
|
offset: new T.Point(left, 30)
|
|
|
});
|
|
@@ -368,6 +559,8 @@
|
|
|
});
|
|
|
this.markerList = [];
|
|
|
this.labelLsit = [];
|
|
|
+ this.centreMarker = null;
|
|
|
+ this.MyMarker = null;
|
|
|
Tmap.clearOverLays();
|
|
|
this.setMyIcon()
|
|
|
} catch (error) {
|
|
@@ -401,22 +594,23 @@
|
|
|
|
|
|
},
|
|
|
setMyIcon() {
|
|
|
- const { lng, lat } = this.MyLngLat || {}
|
|
|
- if (!Tmap || !lng || !lat) return;
|
|
|
+ const { longitude, latitude } = this.useLocation || {}
|
|
|
+ if (!Tmap || !longitude || !latitude) return;
|
|
|
const icon = new T.Icon({
|
|
|
- iconUrl: iconPath,
|
|
|
- iconSize: new T.Point(45, 45),
|
|
|
- iconAnchor: new T.Point(15, 30)
|
|
|
+ iconUrl: locationPath,
|
|
|
+ iconSize: new T.Point(36, 36)
|
|
|
});
|
|
|
- const marker = new T.Marker(new T.LngLat(lng, lat), {
|
|
|
+ const marker = new T.Marker(new T.LngLat(longitude, latitude), {
|
|
|
icon
|
|
|
});
|
|
|
|
|
|
- // Tmap.addOverLay(marker);
|
|
|
+ Tmap.addOverLay(marker);
|
|
|
try {
|
|
|
marker.removeEventListener("click", () => {});
|
|
|
} catch (error) {}
|
|
|
marker.addEventListener("click", () => {});
|
|
|
+ this.MyMarker = marker
|
|
|
+
|
|
|
},
|
|
|
setLable(locationName) {
|
|
|
let el = '';
|
|
@@ -428,6 +622,33 @@
|
|
|
}
|
|
|
};
|
|
|
return `<p class='map-label'>${el}<p>`
|
|
|
+ },
|
|
|
+ // setTcon
|
|
|
+ // centreDot
|
|
|
+ // 设置中心点坐标
|
|
|
+ setCentre() {
|
|
|
+ if (type !== 'H6') return
|
|
|
+ // siteListArr
|
|
|
+ if (this.centreDot) {
|
|
|
+ try {
|
|
|
+ const { Lng, Lat } = this.centreDot || {}
|
|
|
+ const icon = new T.Icon({
|
|
|
+ iconUrl: dotPath,
|
|
|
+ iconSize: new T.Point(36, 36)
|
|
|
+ });
|
|
|
+ const d_ = new T.Marker(new T.LngLat(Lng, Lat), {
|
|
|
+ icon,
|
|
|
+ zIndexOffset: 666
|
|
|
+ });
|
|
|
+ Tmap.addOverLay(d_);
|
|
|
+ this.centreMarker = d_
|
|
|
+ } catch (error) {
|
|
|
+ //TODO handle the exception
|
|
|
+ console.log('this.centreDot error ', error)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
}
|