This commit is contained in:
WindowBird 2025-10-29 18:01:30 +08:00
parent 7b96d7254d
commit eb224ae2e8
2 changed files with 9 additions and 248 deletions

View File

@ -17,7 +17,7 @@
<div class="error-content">
<h3>地图加载失败</h3>
<p>{{ error }}</p>
<button @click="retryLoad" class="retry-btn">重试</button>
<button class="retry-btn" @click="retryLoad">重试</button>
</div>
</div>
</div>
@ -27,7 +27,6 @@
import { ref, onMounted, onUnmounted, watch } from 'vue'
import { amapConfig, getAMapScriptUrl, validateKeys } from '~/config/amap'
//
const props = defineProps({
// [, ]
@ -38,7 +37,7 @@ const props = defineProps({
//
zoom: {
type: Number,
default: 11
default: 17
},
// 2D 3D
viewMode: {
@ -49,7 +48,7 @@ const props = defineProps({
//
height: {
type: String,
default: '400px'
default: '342px'
}
})
@ -128,7 +127,6 @@ const initMap = async () => {
doubleClickZoom: true, //
scrollWheel: true, //
touchZoom: true, //
})
//
@ -352,4 +350,4 @@ onUnmounted(() => {
margin: 0 16px;
}
}
</style>
</style>

View File

@ -1,29 +1,16 @@
<template>
<div class="map-demo-page">
<div class="page-header mt-12">
<div class="page-header mt-22 mx-auto">
<h1>高德地图组件演示</h1>
<p>基于您提供的HTML示例创建的Vue组件</p>
</div>
<div class="demo-section">
<h2>基础地图</h2>
<div class="map-controls">
</div>
<AMapComponent
ref="mapRef"
:center="mapCenter"
:zoom="17"
height="342px"
@map-ready="onMapReady"
/>
</div>
</div>
</template>
@ -35,24 +22,15 @@ 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)
const currentZoom = ref(17)
//
const mapCenter = computed(() => [centerLng.value, centerLat.value])
//
const onMapReady = (mapInstance) => {
console.log('地图实例:', mapInstance)
mapStatus.value = '地图加载完成'
// 🔍
console.log('✅ 地图实例已就绪:', mapInstance)
console.log('📍 当前中心点:', mapInstance?.getCenter?.())
console.log('🔍 当前缩放级别:', mapInstance?.getZoom?.())
//
if (mapRef.value) {
@ -62,219 +40,4 @@ const onMapReady = (mapInstance) => {
})
}
}
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 = () => {
// watch
//
console.log('更新中心点到:', mapCenter.value)
}
//
const goToLocation = (location) => {
console.log('快速定位到:', location.name, location.center)
centerLng.value = location.center[0]
centerLat.value = location.center[1]
zoomLevel.value = location.zoom
// watch
}
</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>