对接远程遥控
This commit is contained in:
@@ -4,15 +4,21 @@ class DeviceAddPathPointModel {
|
||||
|
||||
DeviceAddPathPointModel({required this.latitude, required this.longitude});
|
||||
|
||||
Map<String, dynamic> toJson() => {'lat': latitude.toString(), 'lon': longitude.toString()};
|
||||
Map<String, dynamic> toJson() => {
|
||||
'lat': latitude.toString(),
|
||||
'lng': longitude.toString(),
|
||||
};
|
||||
|
||||
factory DeviceAddPathPointModel.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceAddPathPointModel(
|
||||
latitude: double.parse((json['lat'] ?? json['latitude']).toString()),
|
||||
longitude: double.parse((json['lon'] ?? json['longitude']).toString()),
|
||||
longitude: double.parse(
|
||||
(json['lng'] ?? json['lon'] ?? json['longitude']).toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => '{lat: ${latitude.toString()}, lon: ${longitude.toString()}}';
|
||||
String toString() =>
|
||||
'{lat: ${latitude.toString()}, lon: ${longitude.toString()}}';
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ class ReferencePoint {
|
||||
|
||||
ReferencePoint({required this.lat, required this.lon});
|
||||
|
||||
Map<String, dynamic> toJson() => {'lat': lat, 'lon': lon};
|
||||
Map<String, dynamic> toJson() => {'lat': lat, 'lng': lon};
|
||||
}
|
||||
|
||||
class OuterBoundary {
|
||||
@@ -13,7 +13,10 @@ class OuterBoundary {
|
||||
|
||||
OuterBoundary({required this.position, required this.sideWidth});
|
||||
|
||||
Map<String, dynamic> toJson() => {'position': position.map((p) => p.toJson()).toList(), 'sideWidth': sideWidth};
|
||||
Map<String, dynamic> toJson() => {
|
||||
'position': position.map((p) => p.toJson()).toList(),
|
||||
'sideWidth': sideWidth,
|
||||
};
|
||||
}
|
||||
|
||||
class HoleBoundary {
|
||||
@@ -36,13 +39,17 @@ class HoleBoundary {
|
||||
// 一维数组,包装成二维数组 [[p1,p2,p3]]
|
||||
return [input];
|
||||
} else {
|
||||
throw ArgumentError('position 必须是 List<Position> 或 List<List<Position>> 类型');
|
||||
throw ArgumentError(
|
||||
'position 必须是 List<Position> 或 List<List<Position>> 类型',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 核心修改:toJson 输出二维数组格式
|
||||
Map<String, dynamic> toJson() => {
|
||||
'position': position.map((innerList) => innerList.map((p) => p.toJson()).toList()).toList(), // 二维数组:[[{lat,lon}], ...]
|
||||
'position': position
|
||||
.map((innerList) => innerList.map((p) => p.toJson()).toList())
|
||||
.toList(), // 二维数组:[[{lat,lon}], ...]
|
||||
'sideWidth': sideWidth,
|
||||
};
|
||||
|
||||
@@ -53,7 +60,9 @@ class HoleBoundary {
|
||||
// 2. 遍历外层数组,将每个内层数组转为 List<Position>
|
||||
final List<List<Position>> position = outerList.map((innerList) {
|
||||
// 3. 处理内层数组,转为 Position 对象列表
|
||||
return (innerList as List).map((p) => Position.fromJson(p as Map<String, dynamic>)).toList();
|
||||
return (innerList as List)
|
||||
.map((p) => Position.fromJson(p as Map<String, dynamic>))
|
||||
.toList();
|
||||
}).toList();
|
||||
|
||||
// 4. 提取sideWidth(确保数字类型)
|
||||
@@ -72,9 +81,10 @@ class Position {
|
||||
factory Position.fromJson(Map<String, dynamic> json) {
|
||||
// 安全解析经纬度,避免空值/非数字
|
||||
final double lat = (json['lat'] as num?)?.toDouble() ?? 0.0;
|
||||
final double lon = (json['lon'] as num?)?.toDouble() ?? 0.0;
|
||||
final double lon =
|
||||
((json['lng'] ?? json['lon']) as num?)?.toDouble() ?? 0.0;
|
||||
return Position(lat: lat, lon: lon);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {'lat': lat, 'lon': lon};
|
||||
Map<String, dynamic> toJson() => {'lat': lat, 'lng': lon};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user