test2
This commit is contained in:
parent
7b96d7254d
commit
eb224ae2e8
|
|
@ -17,7 +17,7 @@
|
||||||
<div class="error-content">
|
<div class="error-content">
|
||||||
<h3>地图加载失败</h3>
|
<h3>地图加载失败</h3>
|
||||||
<p>{{ error }}</p>
|
<p>{{ error }}</p>
|
||||||
<button @click="retryLoad" class="retry-btn">重试</button>
|
<button class="retry-btn" @click="retryLoad">重试</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
import { ref, onMounted, onUnmounted, watch } from 'vue'
|
import { ref, onMounted, onUnmounted, watch } from 'vue'
|
||||||
import { amapConfig, getAMapScriptUrl, validateKeys } from '~/config/amap'
|
import { amapConfig, getAMapScriptUrl, validateKeys } from '~/config/amap'
|
||||||
|
|
||||||
|
|
||||||
// 组件属性
|
// 组件属性
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
// 地图中心点坐标 [经度, 纬度]
|
// 地图中心点坐标 [经度, 纬度]
|
||||||
|
|
@ -38,7 +37,7 @@ const props = defineProps({
|
||||||
// 地图缩放级别
|
// 地图缩放级别
|
||||||
zoom: {
|
zoom: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 11
|
default: 17
|
||||||
},
|
},
|
||||||
// 视图模式:2D 或 3D
|
// 视图模式:2D 或 3D
|
||||||
viewMode: {
|
viewMode: {
|
||||||
|
|
@ -49,7 +48,7 @@ const props = defineProps({
|
||||||
// 地图高度
|
// 地图高度
|
||||||
height: {
|
height: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '400px'
|
default: '342px'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -128,7 +127,6 @@ const initMap = async () => {
|
||||||
doubleClickZoom: true, // 是否允许双击缩放
|
doubleClickZoom: true, // 是否允许双击缩放
|
||||||
scrollWheel: true, // 是否允许滚轮缩放
|
scrollWheel: true, // 是否允许滚轮缩放
|
||||||
touchZoom: true, // 是否允许触摸缩放
|
touchZoom: true, // 是否允许触摸缩放
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 地图加载完成事件
|
// 地图加载完成事件
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,16 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="map-demo-page">
|
<div class="map-demo-page">
|
||||||
<div class="page-header mt-12">
|
<div class="page-header mt-22 mx-auto">
|
||||||
<h1>高德地图组件演示</h1>
|
<h1>高德地图组件演示</h1>
|
||||||
<p>基于您提供的HTML示例创建的Vue组件</p>
|
<p>基于您提供的HTML示例创建的Vue组件</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="demo-section">
|
<div class="demo-section">
|
||||||
<h2>基础地图</h2>
|
|
||||||
<div class="map-controls">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<AMapComponent
|
<AMapComponent
|
||||||
ref="mapRef"
|
ref="mapRef"
|
||||||
:center="mapCenter"
|
|
||||||
:zoom="17"
|
:zoom="17"
|
||||||
|
|
||||||
height="342px"
|
|
||||||
@map-ready="onMapReady"
|
@map-ready="onMapReady"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -35,24 +22,15 @@ import AMapComponent from '~/components/AMapComponent.vue'
|
||||||
const mapRef = ref(null)
|
const mapRef = ref(null)
|
||||||
const centerLng = ref(120.258419)
|
const centerLng = ref(120.258419)
|
||||||
const centerLat = ref(27.11402)
|
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 mapCenter = computed(() => [centerLng.value, centerLat.value])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 地图事件处理
|
// 地图事件处理
|
||||||
const onMapReady = (mapInstance) => {
|
const onMapReady = (mapInstance) => {
|
||||||
console.log('地图实例:', mapInstance)
|
// 🔍 调试信息:验证地图实例是否正确传递
|
||||||
mapStatus.value = '地图加载完成'
|
console.log('✅ 地图实例已就绪:', mapInstance)
|
||||||
|
console.log('📍 当前中心点:', mapInstance?.getCenter?.())
|
||||||
|
console.log('🔍 当前缩放级别:', mapInstance?.getZoom?.())
|
||||||
|
|
||||||
// 添加一个标记点
|
// 添加一个标记点
|
||||||
if (mapRef.value) {
|
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>
|
</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>
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user