2025-07-14 10:24:02 +08:00
|
|
|
<template>
|
2025-08-01 16:36:43 +08:00
|
|
|
<view class="map-container">
|
2025-08-02 16:38:54 +08:00
|
|
|
<map id="map" :style="{ width: '100%', height: '100vh' }" :latitude="latitude" :longitude="longitude" :zoom="13"
|
|
|
|
:markers="markers" :custom-style-file="customStyleFile" @markertap="onMarkerTap" @callouttap="onCalloutTap">
|
|
|
|
</map>
|
2025-08-01 16:36:43 +08:00
|
|
|
</view>
|
2025-07-14 10:24:02 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2025-08-01 16:36:43 +08:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2025-08-02 16:38:54 +08:00
|
|
|
latitude: 30.592,
|
|
|
|
longitude: 114.305,
|
2025-08-01 16:36:43 +08:00
|
|
|
markers: [],
|
2025-08-02 16:38:54 +08:00
|
|
|
// 为自定义基座提供样式文件路径
|
|
|
|
customStyleFile: ''
|
2025-08-01 16:36:43 +08:00
|
|
|
}
|
|
|
|
},
|
2025-08-02 16:38:54 +08:00
|
|
|
onLoad() {
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
this.customStyleFile = plus.io.convertLocalFileSystemURL("_www/static/native-res/raw/mapstyle_grey.json");
|
|
|
|
// #endif
|
|
|
|
const eventChannel = this.getOpenerEventChannel();
|
|
|
|
eventChannel.on('MapData', (data) => {
|
|
|
|
if (data && data.points) {
|
|
|
|
this.processMapData(data.points);
|
|
|
|
} else {
|
|
|
|
this.addDefaultMarkers();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// In case no data is received
|
|
|
|
setTimeout(() => {
|
|
|
|
if (this.markers.length === 0) {
|
|
|
|
this.addDefaultMarkers();
|
|
|
|
}
|
|
|
|
}, 1000);
|
2025-08-01 16:36:43 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2025-08-02 16:38:54 +08:00
|
|
|
processMapData(points) {
|
|
|
|
const newMarkers = points.map((point, index) => ({
|
|
|
|
id: index,
|
|
|
|
latitude: point.lnglat[1],
|
|
|
|
longitude: point.lnglat[0],
|
|
|
|
iconPath: '/static/images/biao.png',
|
|
|
|
width: 30,
|
|
|
|
height: 30,
|
|
|
|
callout: {
|
|
|
|
content: point.name,
|
|
|
|
color: '#ffffff',
|
|
|
|
fontSize: 14,
|
|
|
|
borderRadius: 10,
|
|
|
|
bgColor: '#000000',
|
|
|
|
padding: 10,
|
|
|
|
display: 'BYCLICK'
|
2025-08-01 16:36:43 +08:00
|
|
|
}
|
2025-08-02 16:38:54 +08:00
|
|
|
}));
|
2025-08-01 16:36:43 +08:00
|
|
|
|
2025-08-02 16:38:54 +08:00
|
|
|
if (newMarkers.length > 0) {
|
|
|
|
this.latitude = newMarkers[0].latitude;
|
|
|
|
this.longitude = newMarkers[0].longitude;
|
|
|
|
this.markers = newMarkers;
|
2025-08-01 16:36:43 +08:00
|
|
|
}
|
|
|
|
},
|
2025-08-02 16:38:54 +08:00
|
|
|
addDefaultMarkers() {
|
|
|
|
const wuhanPoints = [{
|
|
|
|
lnglat: [114.404, 30.507],
|
|
|
|
name: "华中科技大学"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lnglat: [114.428, 30.476],
|
|
|
|
name: "光谷金融港"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lnglat: [114.433, 30.504],
|
|
|
|
name: "武汉东站"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
this.processMapData(wuhanPoints)
|
2025-08-01 16:36:43 +08:00
|
|
|
},
|
2025-08-02 16:38:54 +08:00
|
|
|
onMarkerTap(e) {
|
|
|
|
console.log('marker tapped', e.detail.markerId);
|
2025-08-01 16:36:43 +08:00
|
|
|
},
|
2025-08-02 16:38:54 +08:00
|
|
|
onCalloutTap(e) {
|
|
|
|
console.log('callout tapped', e.detail.markerId);
|
2025-08-01 16:36:43 +08:00
|
|
|
}
|
|
|
|
}
|
2025-08-01 14:53:20 +08:00
|
|
|
}
|
2025-07-28 18:04:40 +08:00
|
|
|
</script>
|
2025-07-14 10:24:02 +08:00
|
|
|
|
|
|
|
<style>
|
2025-08-01 16:36:43 +08:00
|
|
|
.map-container {
|
|
|
|
width: 100%;
|
|
|
|
height: 100vh;
|
|
|
|
}
|
2025-08-02 16:38:54 +08:00
|
|
|
</style>
|