|
@@ -0,0 +1,129 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <!-- 地图容器 -->
|
|
|
+ <div id="container" style="width:200px;height:100px;"></div>
|
|
|
+ <!-- 输入框用于模拟实时接收经纬度数据 -->
|
|
|
+ <!-- <button @click="updateMarkerPosition">更新位置</button> -->
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ name: 'TencentMap',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ map: null,
|
|
|
+ marker: null,
|
|
|
+ currentPosition: { latitude: 39.909, longitude: 116.397 }, // 默认北京天安门坐标
|
|
|
+ newPosition: '',
|
|
|
+ attitudeHead: 0,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.initMap();
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ getCurrentPosition() {
|
|
|
+ return this.$store.state.currentPosition;
|
|
|
+ },
|
|
|
+ // getAttitudeHead() {
|
|
|
+ // return this.$store.state.attitudeHead;
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ getCurrentPosition(val) {
|
|
|
+ // console.log("taskNum", val);
|
|
|
+ if (val) this.updateMarkerPosition(val)
|
|
|
+ },
|
|
|
+ // getAttitudeHead(val) {
|
|
|
+ // if (val) this.updateMarkerPosition(this.$store.state.currentPosition)
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ initMap() {
|
|
|
+ const center = new qq.maps.LatLng(this.currentPosition.latitude, this.currentPosition.longitude);
|
|
|
+ this.map = new qq.maps.Map(document.getElementById('container'), {
|
|
|
+ center: center,
|
|
|
+ zoom: 13,
|
|
|
+ mapTypeControl: false, // 禁用地图类型控件
|
|
|
+ // 可以根据需求添加其他控件
|
|
|
+ zoomControl: false, // 显示缩放控件
|
|
|
+ mapTypeId: qq.maps.MapTypeId.ROADMAP // 设置地图类型为普通街景图
|
|
|
+ });
|
|
|
+ const icon = new qq.maps.MarkerImage(
|
|
|
+ 'https://wrj-songlanyn.oss-cn-beijing.aliyuncs.com/2025/07/21/20667ea4e2b14e149d758350d819995b.png', // 图标图片路径(放在 public/ 目录下)
|
|
|
+ // new qq.maps.Size(40, 40), // 图标大小
|
|
|
+ // new qq.maps.Point(0, 0) // 锚点位置(图标中心点对准坐标点)
|
|
|
+ );
|
|
|
+ // 添加初始标记
|
|
|
+ this.marker = new qq.maps.Marker({
|
|
|
+ position: center,
|
|
|
+ map: this.map,
|
|
|
+ icon: icon, // 使用自定义图标
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 更新标记位置
|
|
|
+ updateMarkerPosition(pos = {}) {
|
|
|
+ if (!pos.latitude) return;
|
|
|
+ if (pos.latitude != null && pos.longitude != null) { // 确保输入正确
|
|
|
+ const newPos = new qq.maps.LatLng(pos.latitude, pos.longitude);
|
|
|
+ // 更新当前标记的位置
|
|
|
+ this.marker.setPosition(newPos);
|
|
|
+ if (this.$store.state.attitudeHead != this.attitudeHead && this.$store.state.attitudeHead != null) {
|
|
|
+ this.attitudeHead = this.$store.state.attitudeHead;
|
|
|
+ // 创建带有旋转角度的图标
|
|
|
+ // 将特殊偏航角转换为标准方位角
|
|
|
+ const standardBearing = (360 + this.$store.state.attitudeHead * 1) % 360;
|
|
|
+ // this.marker.setIcon(this.createIcon(standardBearing));
|
|
|
+ }
|
|
|
+ // 更新图标及其方向
|
|
|
+ // 移动地图视图到新位置
|
|
|
+ this.map.panTo(newPos);
|
|
|
+ // 更新当前坐标
|
|
|
+ this.currentPosition.latitude = pos.latitude;
|
|
|
+ this.currentPosition.longitude = pos.longitude;
|
|
|
+ } else {
|
|
|
+ // alert('请输入有效的经纬度,格式为"纬度,经度"');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 创建带有旋转角度的图标
|
|
|
+ createIcon(direction = 0) {
|
|
|
+ // 创建带有旋转角度的图标
|
|
|
+ const originalUrl = 'https://wrj-songlanyn.oss-cn-beijing.aliyuncs.com/2025/07/21/c2417a25a6844f12ae6f632956e9cf6a.png'; // 自定义图标路径
|
|
|
+ // 创建图标对象
|
|
|
+ const icon = new qq.maps.MarkerImage(
|
|
|
+ originalUrl,
|
|
|
+ // size,
|
|
|
+ // origin,
|
|
|
+ // anchor
|
|
|
+ );
|
|
|
+
|
|
|
+ console.log("direction", direction);
|
|
|
+ // 设置旋转角度
|
|
|
+ const transformStyle = `rotate(${direction}deg)`;
|
|
|
+ const div = document.createElement('div');
|
|
|
+ div.style.transform = transformStyle;
|
|
|
+ div.style.webkitTransform = transformStyle;
|
|
|
+ // 应用旋转样式
|
|
|
+ // const div = document.createElement('div');
|
|
|
+ // div.style.transform = transformStyle;
|
|
|
+ // div.style.webkitTransform = transformStyle;
|
|
|
+ return icon;
|
|
|
+ },
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+/* 确保地图容器有固定的高度 */
|
|
|
+#container {
|
|
|
+ width: 200px;
|
|
|
+ height: 100px;
|
|
|
+ /* transform: rotate(90deg); */
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+::v-deep a .csssprite {
|
|
|
+ display: none;
|
|
|
+}
|
|
|
+</style>
|