xx
This commit is contained in:
104
lib/features/home/presentation/widgets/map/dji_tile_layer.dart
Normal file
104
lib/features/home/presentation/widgets/map/dji_tile_layer.dart
Normal file
@@ -0,0 +1,104 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
|
||||
// 🔥 1. 定义场站模型(核心)
|
||||
class DJIStation {
|
||||
/// 场站标识(对应瓦片目录名:assets/tiles/[name])
|
||||
final String name;
|
||||
|
||||
/// 场站显示名称(用于UI展示,如"一号场站")
|
||||
final String displayName;
|
||||
|
||||
const DJIStation({required this.name, required this.displayName});
|
||||
}
|
||||
|
||||
/// 大疆高清瓦片图层组件(适配 flutter_map v6.x)
|
||||
class DJITileLayer extends StatefulWidget {
|
||||
/// 场站名称(对应 tiles/[stationName] 目录)
|
||||
final String stationName;
|
||||
|
||||
/// 地图控制器(用于加载中心点后移动地图)
|
||||
final MapController mapController;
|
||||
|
||||
const DJITileLayer({super.key, required this.stationName, required this.mapController});
|
||||
|
||||
@override
|
||||
State<DJITileLayer> createState() => _DJITileLayerState();
|
||||
}
|
||||
|
||||
class _DJITileLayerState extends State<DJITileLayer> {
|
||||
/// 场站中心点(从 parm/center.json 读取)
|
||||
LatLng? _stationCenter;
|
||||
|
||||
/// 瓦片缩放级别范围
|
||||
final double _minZoom = 16;
|
||||
final double _maxZoom = 23;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadStationCenter();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant DJITileLayer oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.stationName != widget.stationName) {
|
||||
_loadStationCenter();
|
||||
}
|
||||
}
|
||||
|
||||
/// 从 assets/tiles/[stationName]/parm/center.json 读取中心点
|
||||
Future<void> _loadStationCenter() async {
|
||||
try {
|
||||
debugPrint("xsdscdvc");
|
||||
|
||||
final String configPath = 'assets/tiles/${widget.stationName}/parm/center.json';
|
||||
debugPrint(configPath);
|
||||
final jsonString = await rootBundle.loadString('assets/tiles/liaoning/parm/center.json');
|
||||
debugPrint("$jsonString,jsonString");
|
||||
final Map<String, dynamic> centerJson = json.decode(jsonString);
|
||||
debugPrint("$centerJson,centerJson");
|
||||
|
||||
final double lng = centerJson['lng'] ?? centerJson['lon'];
|
||||
final double lat = centerJson['lat'];
|
||||
final LatLng newCenter = LatLng(lat, lng);
|
||||
|
||||
setState(() => _stationCenter = newCenter);
|
||||
widget.mapController.move(newCenter, 19);
|
||||
} catch (e) {
|
||||
debugPrint('加载${widget.stationName}中心点失败:$e');
|
||||
setState(() => _stationCenter = const LatLng(32.040644, 120.805718));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String tileUrlTemplate = 'assets/tiles/${widget.stationName}/{z}/{x}/{y}.png';
|
||||
|
||||
return TileLayer(
|
||||
urlTemplate: tileUrlTemplate,
|
||||
tileProvider: AssetTileProvider(), // 修复:直接使用类实例
|
||||
tms: true,
|
||||
minZoom: _minZoom,
|
||||
maxZoom: _maxZoom,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 修复:适配 v6.x 的 AssetTileProvider(移除过时的 TileLayerOptions)
|
||||
class AssetTileProvider extends TileProvider {
|
||||
@override
|
||||
ImageProvider<Object> getImage(TileCoordinates coords, TileLayer options) {
|
||||
// 修复:v6.x 中使用 TileCoordinates 替代 Coords,TileLayer 替代 TileLayerOptions
|
||||
final String path = options.urlTemplate!
|
||||
.replaceAll('{z}', coords.z.toString())
|
||||
.replaceAll('{x}', coords.x.toString())
|
||||
.replaceAll('{y}', coords.y.toString());
|
||||
debugPrint('加载大疆瓦片:$path');
|
||||
return AssetImage(path);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import 'package:maibu_satabot_v2/components/input_confirm_dialog.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/common/tracepoint.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/CenterLocation.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/HeadingPointer.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/dji_tile_layer.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/obsToast.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/startpoint_area.dart';
|
||||
import 'package:image/image.dart' as _image; // 注意命名空间冲突,使用 as img
|
||||
@@ -130,9 +131,24 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
double _workDistance = 0.0; // 作业行距(单位:米)
|
||||
double _angle = 0.0; // 航线方向角(单位:度)
|
||||
|
||||
// 大疆地图
|
||||
bool isDjMapShow = false;
|
||||
late DJIStation _currentStation;
|
||||
|
||||
// 所有可用的场站列表(根据你的实际瓦片目录配置)
|
||||
final List<DJIStation> _stationList = [
|
||||
const DJIStation(name: 'liaoning', displayName: '一号场站'),
|
||||
const DJIStation(name: 'station_b', displayName: '二号场站'),
|
||||
const DJIStation(name: 'station_c', displayName: '三号场站'),
|
||||
// 新增场站只需在这里添加,无需修改其他逻辑
|
||||
];
|
||||
|
||||
// 其他
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_currentStation = _stationList.first;
|
||||
_traceManager = TracePoint<PlotPoint>();
|
||||
_initLocationEnterprise();
|
||||
//_traceManager.onCurrentPointUpdated = (point) {
|
||||
@@ -690,6 +706,8 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
_currentLatLng = null;
|
||||
_currentWgsLatLng = null;
|
||||
_mapCenter = _getDefaultValidCenter(); // 仅用兜底坐标初始化地图中心
|
||||
|
||||
isDjMapShow = false;
|
||||
});
|
||||
|
||||
// 3. 重新初始化定位
|
||||
@@ -1233,6 +1251,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
),
|
||||
maxZoom: 18,
|
||||
),
|
||||
//if (isDjMapShow) DJITileLayer(stationName: _currentStation.name, mapController: _mapController),
|
||||
|
||||
// 绘制path折线(Line模式)
|
||||
if (gcjPathPoints.isNotEmpty)
|
||||
@@ -2155,6 +2174,12 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
_isWorkPanelOpen = false;
|
||||
});
|
||||
},
|
||||
onDjShow: (bool isOpen) {
|
||||
setState(() {
|
||||
isDjMapShow = isOpen;
|
||||
});
|
||||
},
|
||||
|
||||
onWorkModeSelected: (mode) {
|
||||
_currentWorkMode = mode;
|
||||
debugPrint('外部收到作业模式:$mode');
|
||||
|
||||
Reference in New Issue
Block a user