|
@@ -4,6 +4,9 @@
|
|
|
<script setup>
|
|
<script setup>
|
|
|
import { onMounted, onUnmounted, ref } from "vue";
|
|
import { onMounted, onUnmounted, ref } from "vue";
|
|
|
import AMapLoader from "@amap/amap-jsapi-loader";
|
|
import AMapLoader from "@amap/amap-jsapi-loader";
|
|
|
|
|
+import router from "../router";
|
|
|
|
|
+import { useRoute } from "vue-router";
|
|
|
|
|
+const route = useRoute();
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
longitude: {
|
|
longitude: {
|
|
|
type: Number,
|
|
type: Number,
|
|
@@ -17,6 +20,14 @@ const props = defineProps({
|
|
|
type: Array,
|
|
type: Array,
|
|
|
default: [],
|
|
default: [],
|
|
|
},
|
|
},
|
|
|
|
|
+ showLabel: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ handleAble: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: false,
|
|
|
|
|
+ },
|
|
|
loadPorts: {
|
|
loadPorts: {
|
|
|
type: Array,
|
|
type: Array,
|
|
|
default: [],
|
|
default: [],
|
|
@@ -29,6 +40,22 @@ const props = defineProps({
|
|
|
type: String,
|
|
type: String,
|
|
|
default: "container",
|
|
default: "container",
|
|
|
},
|
|
},
|
|
|
|
|
+ zoomEnable: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ dragEnable: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ ToolBar: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ HawkEye: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: true,
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
const mapId = ref(props.mapId);
|
|
const mapId = ref(props.mapId);
|
|
|
const map = ref({});
|
|
const map = ref({});
|
|
@@ -42,48 +69,37 @@ function initMap() {
|
|
|
zoom: 12, // 初始化地图级别
|
|
zoom: 12, // 初始化地图级别
|
|
|
center: [props.longitude, props.latitude], // 初始化地图中心点位置
|
|
center: [props.longitude, props.latitude], // 初始化地图中心点位置
|
|
|
mapStyle: "amap://styles/f48d96805f5fa7f5aada657c5ee37017",
|
|
mapStyle: "amap://styles/f48d96805f5fa7f5aada657c5ee37017",
|
|
|
- zoomEnable: true,
|
|
|
|
|
- dragEnable: true,
|
|
|
|
|
|
|
+ zoomEnable: props.zoomEnable,
|
|
|
|
|
+ dragEnable: props.dragEnable,
|
|
|
});
|
|
});
|
|
|
- let markers = [];
|
|
|
|
|
|
|
+ if (props.ToolBar || props.HawkEye) {
|
|
|
|
|
+ map.value.plugin(["AMap.ToolBar", "AMap.HawkEye"], function () {
|
|
|
|
|
+ if (props.ToolBar) {
|
|
|
|
|
+ let ToolBar = new AMap.ToolBar({
|
|
|
|
|
+ position: {
|
|
|
|
|
+ top: "40px",
|
|
|
|
|
+ right: "40px",
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ map.value.addControl(ToolBar);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for (let i of props.ships) {
|
|
|
|
|
- let marker = generateMarker({
|
|
|
|
|
- longitude: i.longitude,
|
|
|
|
|
- latitude: i.latitude,
|
|
|
|
|
- label: i.shipName,
|
|
|
|
|
- });
|
|
|
|
|
- markers.push(marker);
|
|
|
|
|
- }
|
|
|
|
|
- for (let i of props.loadPorts) {
|
|
|
|
|
- let marker = generateMarker({
|
|
|
|
|
- longitude: i.longitude,
|
|
|
|
|
- latitude: i.latitude,
|
|
|
|
|
- iconSrc:
|
|
|
|
|
- "https://hhd-pat-1255802371.cos.ap-shanghai.myqcloud.com/frontend/port-green.png",
|
|
|
|
|
- iconWidth: 30,
|
|
|
|
|
- iconHeight: 30,
|
|
|
|
|
- offsetY: -30,
|
|
|
|
|
- label: "装货港",
|
|
|
|
|
- });
|
|
|
|
|
- markers.push(marker);
|
|
|
|
|
- }
|
|
|
|
|
- for (let i of props.dischargePorts) {
|
|
|
|
|
- let marker = generateMarker({
|
|
|
|
|
- longitude: i.longitude,
|
|
|
|
|
- latitude: i.latitude,
|
|
|
|
|
- iconSrc:
|
|
|
|
|
- "https://hhd-pat-1255802371.cos.ap-shanghai.myqcloud.com/frontend/port-red.png",
|
|
|
|
|
- iconWidth: 30,
|
|
|
|
|
- iconHeight: 30,
|
|
|
|
|
- offsetY: -30,
|
|
|
|
|
- label: "卸货港",
|
|
|
|
|
|
|
+ if (props.HawkEye) {
|
|
|
|
|
+ let HawkEye = new AMap.HawkEye({
|
|
|
|
|
+ opened: false,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ map.value.addControl(HawkEye);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
- markers.push(marker);
|
|
|
|
|
}
|
|
}
|
|
|
- let overlayGroups = new AMap.OverlayGroup(markers);
|
|
|
|
|
- map.value.add(overlayGroups);
|
|
|
|
|
- map.value.setFitView(markers, true, [150, 50, 100, 100], 9);
|
|
|
|
|
|
|
+ let markers = [
|
|
|
|
|
+ ...generateMarkers(props.ships, "ships"),
|
|
|
|
|
+ ...generateMarkers(props.loadPorts, "loadPorts"),
|
|
|
|
|
+ ...generateMarkers(props.dischargePorts, "dischargePorts"),
|
|
|
|
|
+ ];
|
|
|
|
|
+ drawMarkers(markers);
|
|
|
|
|
+ setFitView(markers);
|
|
|
})
|
|
})
|
|
|
.catch((e) => {
|
|
.catch((e) => {
|
|
|
console.log(e);
|
|
console.log(e);
|
|
@@ -91,14 +107,16 @@ function initMap() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function generateMarker({
|
|
function generateMarker({
|
|
|
|
|
+ id = 0,
|
|
|
longitude = 120.498409,
|
|
longitude = 120.498409,
|
|
|
latitude = 32.039665,
|
|
latitude = 32.039665,
|
|
|
iconSrc = "https://hhd-pat-1255802371.cos.ap-shanghai.myqcloud.com/frontend/ship-red-icon.png",
|
|
iconSrc = "https://hhd-pat-1255802371.cos.ap-shanghai.myqcloud.com/frontend/ship-red-icon.png",
|
|
|
offsetX = -80,
|
|
offsetX = -80,
|
|
|
- offsetY = -20,
|
|
|
|
|
|
|
+ offsetY = -25,
|
|
|
label = "",
|
|
label = "",
|
|
|
- iconWidth = 20,
|
|
|
|
|
- iconHeight = 20,
|
|
|
|
|
|
|
+ iconWidth = 30,
|
|
|
|
|
+ iconHeight = 30,
|
|
|
|
|
+ handleType = "",
|
|
|
}) {
|
|
}) {
|
|
|
let marker = new AMap.Marker({
|
|
let marker = new AMap.Marker({
|
|
|
content: `<div style='width:160px'>
|
|
content: `<div style='width:160px'>
|
|
@@ -116,14 +134,96 @@ function generateMarker({
|
|
|
style: "",
|
|
style: "",
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ if (handleType === "route") {
|
|
|
|
|
+ marker.on("click", () => {
|
|
|
|
|
+ goTo("/voyage/voyageDetail", {
|
|
|
|
|
+ id,
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return marker;
|
|
return marker;
|
|
|
}
|
|
}
|
|
|
|
|
+//ship-orange-icon
|
|
|
|
|
+function generateMarkers(points, type) {
|
|
|
|
|
+ let markers = [];
|
|
|
|
|
+ for (let i of points) {
|
|
|
|
|
+ let config = {
|
|
|
|
|
+ longitude: i.longitude,
|
|
|
|
|
+ latitude: i.latitude,
|
|
|
|
|
+ };
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case "ships": {
|
|
|
|
|
+ config.label = i.shipName;
|
|
|
|
|
+ config.id = i.voyageId;
|
|
|
|
|
+ config.handleType = "route";
|
|
|
|
|
+ if (route.path === "/index") {
|
|
|
|
|
+ config.iconSrc =
|
|
|
|
|
+ "https://frontend-1255802371.cos.ap-shanghai.myqcloud.com/ship-orange-icon.png";
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "loadPorts": {
|
|
|
|
|
+ config.iconSrc =
|
|
|
|
|
+ "https://hhd-pat-1255802371.cos.ap-shanghai.myqcloud.com/frontend/port-green.png";
|
|
|
|
|
+ config.label = "装货港";
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "dischargePorts": {
|
|
|
|
|
+ config.iconSrc =
|
|
|
|
|
+ "https://hhd-pat-1255802371.cos.ap-shanghai.myqcloud.com/frontend/port-red.png";
|
|
|
|
|
+ config.label = "卸货港";
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ markers.push(generateMarker(config));
|
|
|
|
|
+ }
|
|
|
|
|
+ return markers;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function drawMarkers(markers) {
|
|
|
|
|
+ let overlayGroups = new AMap.OverlayGroup(markers);
|
|
|
|
|
+ map.value.add(overlayGroups);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function setFitView(markers = [], zoom = 9) {
|
|
|
|
|
+ map.value.setFitView(markers, true, [150, 50, 100, 100], zoom);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function clearMap() {
|
|
|
|
|
+ map.value.clearMap();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function goTo(path = "/voyage/voyageDetail", query = {}) {
|
|
|
|
|
+ router.push({
|
|
|
|
|
+ path,
|
|
|
|
|
+ query,
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+let currentUrl = ref("");
|
|
|
|
|
+let mediaModal = ref(false);
|
|
|
|
|
+let modalType = ref(1);
|
|
|
|
|
+let modalTitle = ref("");
|
|
|
|
|
+let modalPreview = ref([]);
|
|
|
|
|
+function openMediaModal(url, type, title, item = {}) {
|
|
|
|
|
+ modalPreview.value = [url];
|
|
|
|
|
+ modalTitle.value = title;
|
|
|
|
|
+ modalType.value = type;
|
|
|
|
|
+ currentUrl.value = url;
|
|
|
|
|
+ mediaModal.value = true;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
initMap();
|
|
initMap();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+defineExpose({
|
|
|
|
|
+ clearMap,
|
|
|
|
|
+ drawMarkers,
|
|
|
|
|
+ initMap,
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
onUnmounted(() => {
|
|
onUnmounted(() => {
|
|
|
map.value.destroy();
|
|
map.value.destroy();
|
|
|
});
|
|
});
|