From 089f5367d694e823b273faeee66d8bfbba51eb9a Mon Sep 17 00:00:00 2001
From: weipengfei <2187978347@qq.com>
Date: Mon, 22 Jan 2024 18:08:02 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.vue | 48 ++++++--
src/components/areaList.vue | 9 ++
src/components/headView.vue | 130 +++++++++++---------
src/router/index.js | 7 +-
src/view/delivery/components/AMap.vue | 168 ++++++++++++++------------
5 files changed, 215 insertions(+), 147 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index 5415d9c..3f7a2c5 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,24 +1,58 @@
diff --git a/src/router/index.js b/src/router/index.js
index b862fb2..d9da7a9 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -3,12 +3,13 @@ import { createRouter, createWebHistory } from "vue-router"
const routes = [
{
path: '/',
- name: 'index',
+ name: 'app',
component: () => import('../layout/index.vue'),
+ redirect: 'index',
children: [
{
- path: '/',
- name: '',
+ path: '/index',
+ name: 'index',
component: () => import('../view/index/index.vue')
},
{
diff --git a/src/view/delivery/components/AMap.vue b/src/view/delivery/components/AMap.vue
index 92c6d12..8fc220d 100644
--- a/src/view/delivery/components/AMap.vue
+++ b/src/view/delivery/components/AMap.vue
@@ -9,22 +9,22 @@ const loading = ref(true);
const props = defineProps({
list: {
type: Object,
- default: () => []
+ default: () => [],
},
open: {
type: String,
- default: ''
- }
-})
+ default: ()=>"",
+ },
+});
const initMap = () => {
AMapLoader.load({
key: "4f8f55618010007147aab96fc72bb408", // 申请好的Web端开发者Key,首次调用 load 时必填
version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
- plugins: ['AMap.Geocoder'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
+ plugins: ["AMap.Geocoder"], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
Loca: {
- version: '2.0.0'
- }
+ version: "2.0.0",
+ },
})
.then((AMap) => {
map = new AMap.Map("container", {
@@ -35,98 +35,102 @@ const initMap = () => {
mapStyle: "amap://styles/darkblue",
});
// 监听地图加载完成事件
- map.on('complete', () => {
+ map.on("complete", () => {
// 地图加载完成后执行的操作
setTimeout(() => {
loading.value = false;
- }, 500)
+ }, 500);
});
map.setPitch(30);
- let geocoder = new AMap.Geocoder();
+ if (props.open.length>0) {
+ let geocoder = new AMap.Geocoder();
+ geocoder.getLocation(props.open, function (status, result) {
+ if (status === "complete" && result.info === "OK") {
+ // 获取成功,result.geocodes包含了返回的经纬度信息
+ let latlong = result.geocodes[0].location;
+ let start = [latlong.lng, latlong.lat];
+ let line = [];
+ map.setCenter(start);
+ // 创建 AMap.Icon 实例:
+ const icon = new AMap.Icon({
+ size: new AMap.Size(50, 60), // 图标尺寸
+ // vue3/vite 需要用特定的本地图片引入方式,不可require引入
+ image: new URL(
+ "/src/assets/delivery_img/icon10.png",
+ import.meta.url
+ ).href, // Icon的图像
+ imageSize: new AMap.Size(50, 60), // 根据所设置的大小拉伸或压缩图片
+ imageOffset: new AMap.Pixel(0, 0),
+ });
+ // 创建一个 Marker 实例:
+ const marker = new AMap.Marker({
+ position: start, // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
+ icon: icon,
+ offset: new AMap.Pixel(-25, -60), // 图标相对于标记点的位置偏移量
+ });
- geocoder.getLocation(props.open, function (status, result) {
- if (status === 'complete' && result.info === 'OK') {
- // 获取成功,result.geocodes包含了返回的经纬度信息
- let latlong = result.geocodes[0].location;
- let start = [latlong.lng, latlong.lat];
- let line = [];
- map.setCenter(start);
+ // 将创建的点标记添加到已有的地图实例:
+ map.add(marker);
- // 创建 AMap.Icon 实例:
- const icon = new AMap.Icon({
- size: new AMap.Size(50, 60), // 图标尺寸
- // vue3/vite 需要用特定的本地图片引入方式,不可require引入
- image: new URL('/src/assets/delivery_img/icon10.png', import.meta.url).href, // Icon的图像
- imageSize: new AMap.Size(50, 60), // 根据所设置的大小拉伸或压缩图片
- imageOffset: new AMap.Pixel(0, 0)
- });
- // 创建一个 Marker 实例:
- const marker = new AMap.Marker({
- position: start, // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
- icon: icon,
- offset: new AMap.Pixel(-25, -60), // 图标相对于标记点的位置偏移量
- });
-
- // 将创建的点标记添加到已有的地图实例:
- map.add(marker);
-
- props.list.forEach(item => {
- geocoder.getLocation(item, function (status, result) {
- if (status === 'complete' && result.info === 'OK') {
- // 获取成功,result.geocodes包含了返回的经纬度信息
- let geocodes = result.geocodes[0].location;
- line.push([geocodes.lng, geocodes.lat]);
- if (line.length == props.list.length) {
- initLine(start, line);
+ props.list.forEach((item) => {
+ geocoder.getLocation(item, function (status, result) {
+ if (status === "complete" && result.info === "OK") {
+ // 获取成功,result.geocodes包含了返回的经纬度信息
+ let geocodes = result.geocodes[0].location;
+ line.push([geocodes.lng, geocodes.lat]);
+ if (line.length == props.list.length) {
+ initLine(start, line);
+ }
+ } else {
+ // 获取失败,可根据具体需求进行错误处理
+ console.log("获取经纬度失败");
}
- } else {
- // 获取失败,可根据具体需求进行错误处理
- console.log('获取经纬度失败');
- }
- })
- })
- } else {
- // 获取失败,可根据具体需求进行错误处理
- console.log('获取经纬度失败');
- }
- });
-
+ });
+ });
+ } else {
+ // 获取失败,可根据具体需求进行错误处理
+ console.log("获取经纬度失败", props);
+ // setTimeout(() => {
+ // initMap();
+ // }, 2000);
+ }
+ setTimeout(() => {
+ loading.value = false;
+ }, 500);
+ });
+ }
})
.catch((e) => {
console.log(e);
});
-}
+};
const initLine = (start = [], line = []) => {
-
let features = [];
- line.forEach((item => {
+ line.forEach((item) => {
features.push({
- "type": "Feature",
- "properties": {},
- "geometry": {
- "type": "LineString",
- "coordinates": [
- start,
- item
- ]
- }
- },)
- }))
+ type: "Feature",
+ properties: {},
+ geometry: {
+ type: "LineString",
+ coordinates: [start, item],
+ },
+ });
+ });
// 创建 Loca 实例
let loca = new Loca.Container({
- map: map
+ map: map,
});
// 创建数据源
let dataSource = new Loca.GeoJSONSource({
// url: 'xxx.geojson', 或者使用 data 字段
data: {
- "type": "FeatureCollection",
- "features": features
+ type: "FeatureCollection",
+ features: features,
},
});
@@ -140,9 +144,9 @@ const initLine = (start = [], line = []) => {
depth: true,
});
- pulseLink.setSource(dataSource)
+ pulseLink.setSource(dataSource);
pulseLink.setStyle({
- unit: 'meter',
+ unit: "meter",
dash: [80, 0, 80, 0],
lineWidth: function () {
return [30, 5];
@@ -158,17 +162,21 @@ const initLine = (start = [], line = []) => {
},
flowLength: 300,
lineColors: function (index, feat) {
- return ['rgba(47, 194, 250, 0.20)', 'rgba(91, 219, 246, 0.70)', 'rgba(0, 156, 255, 0.20)'];
+ return [
+ "rgba(47, 194, 250, 0.20)",
+ "rgba(91, 219, 246, 0.70)",
+ "rgba(0, 156, 255, 0.20)",
+ ];
},
maxHeightScale: 0.4, // 弧顶位置比例
- headColor: 'rgba(91, 219, 246, 1)',
- trailColor: 'rgba(255, 255,0,0)',
+ headColor: "rgba(91, 219, 246, 1)",
+ trailColor: "rgba(255, 255,0,0)",
});
// 添加到地图上
loca.add(pulseLink);
loca.animate.start();
-}
+};
onMounted(() => {
initMap();
@@ -182,13 +190,13 @@ onUnmounted(() => {