修改位置交互,修改代码逻辑
This commit is contained in:
@@ -14,11 +14,32 @@ export class DataModule {
|
||||
/**
|
||||
* 初始化页面数据
|
||||
*/
|
||||
public initializeData(): void {
|
||||
public async initializeData(): Promise<void> {
|
||||
// 检查是否已静默登录,如果是则尝试获取真实位置
|
||||
let initialLongitude = 102.833722;
|
||||
let initialLatitude = 24.880095;
|
||||
|
||||
const app = getApp<any>();
|
||||
if (app.globalData.isLoggedIn) {
|
||||
try {
|
||||
// 导入地图服务
|
||||
const mapService = require('../../../services/mapService').default;
|
||||
const location = await mapService.getCurrentLocation();
|
||||
|
||||
if (location && !isNaN(location.latitude) && !isNaN(location.longitude)) {
|
||||
initialLongitude = location.longitude;
|
||||
initialLatitude = location.latitude;
|
||||
console.log('[DATA MODULE] 静默登录后使用真实位置:', location);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('[DATA MODULE] 获取真实位置失败,使用默认位置:', error);
|
||||
}
|
||||
}
|
||||
|
||||
this.pageContext.setData({
|
||||
// 地图相关数据
|
||||
longitude: 102.833722,
|
||||
latitude: 24.880095,
|
||||
longitude: initialLongitude,
|
||||
latitude: initialLatitude,
|
||||
scale: 13,
|
||||
markers: [] as Marker[],
|
||||
polyline: null,
|
||||
@@ -148,7 +169,7 @@ export class DataModule {
|
||||
*/
|
||||
public updateMarkers(markers: Marker[]): void {
|
||||
// 验证每个标记点的坐标
|
||||
const validatedMarkers = markers.map((marker, index) => {
|
||||
const validatedMarkers = markers.map((marker) => {
|
||||
// 检查经纬度是否为有效数字
|
||||
if (isNaN(marker.longitude) || isNaN(marker.latitude)) {
|
||||
// 为无效坐标设置默认值
|
||||
@@ -283,4 +304,26 @@ export class DataModule {
|
||||
public resetAllData(): void {
|
||||
this.initializeData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取位置模块(用于其他模块访问位置模块)
|
||||
*/
|
||||
public getLocationModule(): any {
|
||||
// 通过页面上下文获取位置模块
|
||||
if (this.pageContext.data.mainPageModule) {
|
||||
return this.pageContext.data.mainPageModule.getLocationModule();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地图模块(用于其他模块访问地图模块)
|
||||
*/
|
||||
public getMapModule(): any {
|
||||
// 通过页面上下文获取地图模块
|
||||
if (this.pageContext.data.mainPageModule) {
|
||||
return this.pageContext.data.mainPageModule.getMapModule();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user