|
@@ -1,8 +1,10 @@
|
|
|
-import { defineComponent, onMounted, reactive, ref, shallowRef } from 'vue';
|
|
|
+import { defineComponent, onMounted, reactive, shallowRef } from 'vue';
|
|
|
import styles from './amap-gps.module.less';
|
|
|
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
|
import MHeader from '@/components/m-header';
|
|
|
import MSticky from '@/components/m-sticky';
|
|
|
+import iconMap from './images/icon-map.png';
|
|
|
+import iconMapError from './images/icon-map-error.png';
|
|
|
export default defineComponent({
|
|
|
name: 'amap-gps',
|
|
|
setup() {
|
|
@@ -11,7 +13,7 @@ export default defineComponent({
|
|
|
attendance_range: 1000,
|
|
|
lnglat: [114.343011, 30.55499] as any, // 教学点 A座
|
|
|
address: '',
|
|
|
- signInLongitudeLatitude: [114.341116, 30.552401], // 签到 B座
|
|
|
+ signInLongitudeLatitude: [114.333488, 30.547087], // 签到 B座
|
|
|
signOutLongitudeLatitude: [114.34424, 30.556584], // 签退
|
|
|
signInMark: null,
|
|
|
signOutMark: null,
|
|
@@ -42,8 +44,8 @@ export default defineComponent({
|
|
|
map.value = new AMap.Map('gpsContainer', {
|
|
|
resizeEnable: true,
|
|
|
zoom: 16,
|
|
|
- zooms: [2, 22],
|
|
|
- center: [114.34371, 30.55939]
|
|
|
+ zooms: [2, 22]
|
|
|
+ // center: [114.34371, 30.55939]
|
|
|
});
|
|
|
AMap.plugin(
|
|
|
[
|
|
@@ -76,20 +78,20 @@ export default defineComponent({
|
|
|
}
|
|
|
|
|
|
// 加载签到点
|
|
|
- // if (
|
|
|
- // selectMapAddress.signInLongitudeLatitude &&
|
|
|
- // selectMapAddress.signInLongitudeLatitude.length > 0
|
|
|
- // ) {
|
|
|
- // console.log(
|
|
|
- // 'signInLongitudeLatitude',
|
|
|
- // selectMapAddress.signInLongitudeLatitude
|
|
|
- // );
|
|
|
- // addMarker(
|
|
|
- // selectMapAddress.signInLongitudeLatitude,
|
|
|
- // '签到点',
|
|
|
- // 'signInMark'
|
|
|
- // );
|
|
|
- // }
|
|
|
+ if (
|
|
|
+ selectMapAddress.signInLongitudeLatitude &&
|
|
|
+ selectMapAddress.signInLongitudeLatitude.length > 0
|
|
|
+ ) {
|
|
|
+ console.log(
|
|
|
+ 'signInLongitudeLatitude',
|
|
|
+ selectMapAddress.signInLongitudeLatitude
|
|
|
+ );
|
|
|
+ addMarker(
|
|
|
+ selectMapAddress.signInLongitudeLatitude,
|
|
|
+ '签到点',
|
|
|
+ 'signInMark'
|
|
|
+ );
|
|
|
+ }
|
|
|
// 加载签退点
|
|
|
if (
|
|
|
selectMapAddress.signOutLongitudeLatitude &&
|
|
@@ -110,8 +112,7 @@ export default defineComponent({
|
|
|
// 连线 设置签到点与教学点的距离
|
|
|
computeDis(
|
|
|
selectMapAddress.addressMark,
|
|
|
- selectMapAddress.signInMark,
|
|
|
- 'top'
|
|
|
+ selectMapAddress.signInMark
|
|
|
);
|
|
|
console.log('连线 设置签到点与教学点的距离');
|
|
|
}
|
|
@@ -122,8 +123,7 @@ export default defineComponent({
|
|
|
// 连线 设置签退点与教学点的距离
|
|
|
computeDis(
|
|
|
selectMapAddress.addressMark,
|
|
|
- selectMapAddress.signOutMark,
|
|
|
- 'bottom'
|
|
|
+ selectMapAddress.signOutMark
|
|
|
);
|
|
|
console.log('连线 设置签退点与教学点的距离');
|
|
|
}
|
|
@@ -137,26 +137,22 @@ export default defineComponent({
|
|
|
type: 'signInMark' | 'signOutMark' | 'addressMark'
|
|
|
) {
|
|
|
const Icon = new AMap.Icon({
|
|
|
- size: [25, 34],
|
|
|
- image: 'https://daya.ks3-cn-beijing.ksyun.com/202211/TO13VtW.png',
|
|
|
- imageSize: [25, 34]
|
|
|
+ size: [27, 28],
|
|
|
+ image: iconMap,
|
|
|
+ imageSize: [27, 28]
|
|
|
});
|
|
|
- // const Icon = new AMap.Icon({
|
|
|
- // size: new AMap.Size([25, 34]), // 图标尺寸
|
|
|
- // image: 'https://daya.ks3-cn-beijing.ksyun.com/202211/TO13VtW.png', // Icon的图像
|
|
|
- // // imageOffset: new AMap.Pixel(0, -60), // 图像相对展示区域的偏移量,适于雪碧图等
|
|
|
- // imageSize: new AMap.Size([25, 34]) // 根据所设置的大小拉伸或压缩图片
|
|
|
- // });
|
|
|
marker = new AMap.Marker({
|
|
|
- // icon: Icon,
|
|
|
- // offset: new AMap.Pixel(-25, -14),
|
|
|
+ icon: Icon,
|
|
|
+ // offset: new AMap.Pixel(-14, -28),
|
|
|
+ anchor: 'bottom-center',
|
|
|
position: new AMap.LngLat(...lnglat),
|
|
|
title
|
|
|
});
|
|
|
|
|
|
marker.setLabel({
|
|
|
- content: `<div class='${styles.info}' >${title}</div>`, //设置文本标注内容
|
|
|
- direction: 'top'
|
|
|
+ content: `${title}`, //设置文本标注内容
|
|
|
+ direction: 'top',
|
|
|
+ offset: [0, -2]
|
|
|
});
|
|
|
|
|
|
selectMapAddress[type] = marker;
|
|
@@ -171,67 +167,88 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
// 连线 写标记
|
|
|
- function computeDis(m1: any, m2: any, type: string) {
|
|
|
- const line = new AMap.Polyline({
|
|
|
- strokeColor: '#01C1B5',
|
|
|
- strokeWeight: 3,
|
|
|
- isOutline: false,
|
|
|
- outlineColor: '#01C1B5'
|
|
|
- });
|
|
|
- line.setMap(map.value);
|
|
|
-
|
|
|
+ function computeDis(m1: any, m2: any) {
|
|
|
+ console.log(m2, 'm1 m2');
|
|
|
const p1 = m1.getPosition();
|
|
|
const p2 = m2.getPosition();
|
|
|
const textPos = p1.divideBy(2).add(p2.divideBy(2));
|
|
|
const distance = Math.round(p1.distance(p2));
|
|
|
const path = [p1, p2];
|
|
|
- line.setPath(path);
|
|
|
+ const mainColor =
|
|
|
+ distance > selectMapAddress.attendance_range
|
|
|
+ ? '#FF5A56'
|
|
|
+ : '#01C1B5';
|
|
|
+ // 判断距离是否已经在圈外了
|
|
|
+ if (distance > selectMapAddress.attendance_range) {
|
|
|
+ m2.dom.classList.add('myClassM2');
|
|
|
+ m2.setIcon(iconMapError);
|
|
|
+ }
|
|
|
|
|
|
- const a = calcAngle([p1.lng, p2.lng], [p2.lng, p1.lng]);
|
|
|
- console.log(a, 'aaaaaaa');
|
|
|
+ const line = new AMap.Polyline({
|
|
|
+ strokeColor: mainColor,
|
|
|
+ strokeWeight: 2,
|
|
|
+ isOutline: true,
|
|
|
+ outlineColor: mainColor
|
|
|
+ });
|
|
|
+ line.setMap(map.value);
|
|
|
+ line.setPath(path);
|
|
|
|
|
|
- if (type == 'top') {
|
|
|
- console.log(p1, p2, textPos, distance, 'computed', type);
|
|
|
- const text = new AMap.Text({
|
|
|
- // text: '签到点距离学校' + distance + '米',
|
|
|
- text: distance + 'M',
|
|
|
- // angle: a,
|
|
|
- style: {
|
|
|
- 'font-size': '12px'
|
|
|
- }
|
|
|
- //设置文本标注方位
|
|
|
- });
|
|
|
+ // const a = calcAngle([p1.lng, p2.lng], [p2.lng, p1.lng]);
|
|
|
+ // console.log(a, 'aaaaaaa');
|
|
|
+ const text = new AMap.Text({
|
|
|
+ text: distance + 'M',
|
|
|
+ style: {
|
|
|
+ 'font-size': '12px',
|
|
|
+ color: '#fff',
|
|
|
+ border: 'none',
|
|
|
+ backgroundColor: mainColor
|
|
|
+ }
|
|
|
+ //设置文本标注方位
|
|
|
+ });
|
|
|
+ text.setPosition(textPos);
|
|
|
+ text.setMap(map.value);
|
|
|
+ // if (type == 'top') {
|
|
|
+ // console.log(p1, p2, textPos, distance, 'computed', type);
|
|
|
+ // const text = new AMap.Text({
|
|
|
+ // // text: '签到点距离学校' + distance + '米',
|
|
|
+ // text: distance + 'M',
|
|
|
+ // // angle: a,
|
|
|
+ // style: {
|
|
|
+ // 'font-size': '12px'
|
|
|
+ // }
|
|
|
+ // //设置文本标注方位
|
|
|
+ // });
|
|
|
|
|
|
- // text.setOffset(new AMap.Pixel(-40, -10));
|
|
|
- text.setPosition(textPos);
|
|
|
- text.setMap(map.value);
|
|
|
- } else {
|
|
|
- const text = new AMap.Text({
|
|
|
- // text: '签退点距离学校' + distance + '米',
|
|
|
- text: distance + 'M',
|
|
|
- angle: a,
|
|
|
- style: {
|
|
|
- 'font-size': '12px'
|
|
|
- }
|
|
|
- //设置文本标注方位
|
|
|
- });
|
|
|
- // text.setOffset(new AMap.Pixel(-40, -50));
|
|
|
- text.setPosition(textPos);
|
|
|
- text.setMap(map.value);
|
|
|
- // line.setPath(path);
|
|
|
- }
|
|
|
+ // // text.setOffset(new AMap.Pixel(-40, -10));
|
|
|
+ // text.setPosition(textPos);
|
|
|
+ // text.setMap(map.value);
|
|
|
+ // } else {
|
|
|
+ // const text = new AMap.Text({
|
|
|
+ // // text: '签退点距离学校' + distance + '米',
|
|
|
+ // text: distance + 'M',
|
|
|
+ // // angle: a,
|
|
|
+ // style: {
|
|
|
+ // 'font-size': '12px'
|
|
|
+ // }
|
|
|
+ // //设置文本标注方位
|
|
|
+ // });
|
|
|
+ // // text.setOffset(new AMap.Pixel(-40, -50));
|
|
|
+ // text.setPosition(textPos);
|
|
|
+ // text.setMap(map.value);
|
|
|
+ // // line.setPath(path);
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
// 计算两点间的角度
|
|
|
- function calcAngle(start: any, end: any) {
|
|
|
- const p_start = map.value.lngLatToContainer(start),
|
|
|
- p_end = map.value.lngLatToContainer(end);
|
|
|
+ // function calcAngle(start: any, end: any) {
|
|
|
+ // const p_start = map.value.lngLatToContainer(start),
|
|
|
+ // p_end = map.value.lngLatToContainer(end);
|
|
|
|
|
|
- const diff_x = p_end.x - p_start.x,
|
|
|
- diff_y = p_end.y - p_start.y;
|
|
|
- console.log((360 * Math.atan2(diff_y, diff_x)) / (2 * Math.PI));
|
|
|
- return (360 * Math.atan2(diff_y, diff_x)) / (2 * Math.PI) - 45;
|
|
|
- }
|
|
|
+ // const diff_x = p_end.x - p_start.x,
|
|
|
+ // diff_y = p_end.y - p_start.y;
|
|
|
+ // console.log((360 * Math.atan2(diff_y, diff_x)) / (2 * Math.PI));
|
|
|
+ // return (360 * Math.atan2(diff_y, diff_x)) / (2 * Math.PI) - 45;
|
|
|
+ // }
|
|
|
})
|
|
|
.catch(() => {
|
|
|
//
|