2025-10-29 14:44:18 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="map-demo-page">
|
2025-10-29 15:40:24 +08:00
|
|
|
|
<div class="page-header mt-12">
|
2025-10-29 14:44:18 +08:00
|
|
|
|
<h1>高德地图组件演示</h1>
|
|
|
|
|
|
<p>基于您提供的HTML示例创建的Vue组件</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="demo-section">
|
|
|
|
|
|
<h2>基础地图</h2>
|
|
|
|
|
|
<div class="map-controls">
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<AMapComponent
|
2025-10-29 16:26:51 +08:00
|
|
|
|
ref="mapRef"
|
|
|
|
|
|
:center="mapCenter"
|
|
|
|
|
|
:zoom="17"
|
|
|
|
|
|
|
|
|
|
|
|
height="342px"
|
|
|
|
|
|
@map-ready="onMapReady"
|
|
|
|
|
|
|
2025-10-29 14:44:18 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-29 16:26:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-10-29 14:44:18 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
import { ref, computed } from 'vue'
|
|
|
|
|
|
import AMapComponent from '~/components/AMapComponent.vue'
|
|
|
|
|
|
|
|
|
|
|
|
// 响应式数据
|
|
|
|
|
|
const mapRef = ref(null)
|
|
|
|
|
|
const centerLng = ref(120.258419)
|
|
|
|
|
|
const centerLat = ref(27.11402)
|
|
|
|
|
|
const zoomLevel = ref(17)
|
|
|
|
|
|
const viewMode = ref('2D')
|
|
|
|
|
|
const mapStatus = ref('加载中...')
|
|
|
|
|
|
const lastClick = ref(null)
|
|
|
|
|
|
const currentCenter = ref(null)
|
2025-10-29 15:40:24 +08:00
|
|
|
|
const currentZoom = ref(17)
|
2025-10-29 14:44:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 计算属性
|
|
|
|
|
|
const mapCenter = computed(() => [centerLng.value, centerLat.value])
|
|
|
|
|
|
|
2025-10-29 16:26:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-29 14:44:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 地图事件处理
|
|
|
|
|
|
const onMapReady = (mapInstance) => {
|
|
|
|
|
|
console.log('地图实例:', mapInstance)
|
|
|
|
|
|
mapStatus.value = '地图加载完成'
|
2025-10-29 15:40:24 +08:00
|
|
|
|
|
2025-10-29 14:44:18 +08:00
|
|
|
|
// 添加一个标记点
|
|
|
|
|
|
if (mapRef.value) {
|
|
|
|
|
|
mapRef.value.addMarker(mapCenter.value, {
|
|
|
|
|
|
title: '当前位置',
|
2025-10-29 15:40:24 +08:00
|
|
|
|
content: '<div style="background: #007bff; color: white; padding: 4px 8px; border-radius: 4px; font-size: 12px;">创特物联</div>'
|
2025-10-29 14:44:18 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onMapClick = (event) => {
|
|
|
|
|
|
lastClick.value = event
|
|
|
|
|
|
console.log('地图点击:', event)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onZoomChange = (zoom) => {
|
|
|
|
|
|
currentZoom.value = zoom
|
|
|
|
|
|
console.log('缩放级别变化:', zoom)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onCenterChange = (center) => {
|
|
|
|
|
|
currentCenter.value = center
|
|
|
|
|
|
centerLng.value = center.lng
|
|
|
|
|
|
centerLat.value = center.lat
|
|
|
|
|
|
console.log('中心点变化:', center)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新中心点
|
|
|
|
|
|
const updateCenter = () => {
|
2025-10-29 15:40:24 +08:00
|
|
|
|
// 由于watch监听器会自动更新地图,这里不需要手动调用
|
|
|
|
|
|
// 只需要确保数据已经更新即可
|
|
|
|
|
|
console.log('更新中心点到:', mapCenter.value)
|
2025-10-29 14:44:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 快速定位
|
|
|
|
|
|
const goToLocation = (location) => {
|
2025-10-29 15:40:24 +08:00
|
|
|
|
console.log('快速定位到:', location.name, location.center)
|
2025-10-29 14:44:18 +08:00
|
|
|
|
centerLng.value = location.center[0]
|
|
|
|
|
|
centerLat.value = location.center[1]
|
|
|
|
|
|
zoomLevel.value = location.zoom
|
2025-10-29 15:40:24 +08:00
|
|
|
|
// 由于watch监听器会自动更新地图,这里不需要手动调用
|
2025-10-29 14:44:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.map-demo-page {
|
|
|
|
|
|
max-width: 1200px;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
padding: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-header {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
margin-bottom: 40px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-header h1 {
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-header p {
|
|
|
|
|
|
color: #666;
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.demo-section {
|
|
|
|
|
|
margin-bottom: 40px;
|
|
|
|
|
|
background: white;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
padding: 24px;
|
|
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.demo-section h2 {
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.map-controls {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
gap: 20px;
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
padding: 16px;
|
|
|
|
|
|
background: #f8f9fa;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.control-group {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.control-group label {
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
color: #555;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.coord-input {
|
|
|
|
|
|
width: 120px;
|
|
|
|
|
|
padding: 6px 8px;
|
|
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.update-btn {
|
|
|
|
|
|
background: #007bff;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
padding: 6px 12px;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
transition: background-color 0.2s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.update-btn:hover {
|
|
|
|
|
|
background: #0056b3;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.zoom-slider {
|
|
|
|
|
|
width: 120px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.zoom-value {
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
color: #007bff;
|
|
|
|
|
|
min-width: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.view-select {
|
|
|
|
|
|
padding: 6px 8px;
|
|
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.event-info {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
|
|
|
|
|
gap: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-item {
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
background: #f8f9fa;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
border-left: 4px solid #007bff;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-item strong {
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
margin-right: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.status-success {
|
|
|
|
|
|
color: #28a745;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.status-loading {
|
|
|
|
|
|
color: #ffc107;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.status-error {
|
|
|
|
|
|
color: #dc3545;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.quick-locations {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.location-btn {
|
|
|
|
|
|
background: #6c757d;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
padding: 8px 16px;
|
|
|
|
|
|
border-radius: 20px;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
transition: all 0.2s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.location-btn:hover {
|
|
|
|
|
|
background: #5a6268;
|
|
|
|
|
|
transform: translateY(-1px);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 响应式设计 */
|
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
|
.map-demo-page {
|
|
|
|
|
|
padding: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.map-controls {
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: stretch;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.control-group {
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.coord-input {
|
|
|
|
|
|
width: 100px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.event-info {
|
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.quick-locations {
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|