import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:locations/utils/map_util.dart';
|
import 'package:locations/utils/ui_constant.dart';
|
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
|
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
|
import 'dart:math' as math;
|
|
//三角形
|
class TrianglePainter extends CustomPainter {
|
final Color color;
|
Paint? _paint; //画笔
|
Path? _path; //绘制路径
|
|
TrianglePainter(this.color) {
|
_paint = Paint()
|
..strokeWidth = 1.0 //线宽
|
..color = color
|
..isAntiAlias = true;
|
_path = Path();
|
}
|
|
@override
|
void paint(Canvas canvas, Size size) {
|
final baseX = size.width * 0.5;
|
final baseY = size.height * 0.5;
|
//起点
|
// _path!.moveTo(baseX - 0.86 * baseX, 0.5 * baseY);
|
// _path!.lineTo(baseY, 1.5 * baseY);
|
// _path!.lineTo(baseX + 0.86 * baseX, 0.5 * baseY);
|
|
_path!.moveTo(size.width / 2, 0);
|
_path!.lineTo(size.width, size.height);
|
_path!.lineTo(0, size.height);
|
canvas.drawPath(_path!, _paint!);
|
}
|
|
@override
|
bool shouldRepaint(CustomPainter oldDelegate) {
|
return true;
|
}
|
}
|
|
///用户位置marker
|
class PersonLocationMarkerWithOrientation extends StatelessWidget {
|
final double angle;
|
final Image portrait;
|
|
PersonLocationMarkerWithOrientation(this.angle, this.portrait);
|
|
@override
|
Widget build(BuildContext context) {
|
return Container(
|
width: 70,
|
height: 70,
|
child: Stack(
|
alignment: Alignment.center,
|
children: [
|
Positioned(
|
top: 0,
|
child: Transform.rotate(
|
angle: angle,
|
child: Container(
|
height: 69.28,
|
width: 69.28,
|
child: Stack(alignment: Alignment.topCenter, children: [
|
CustomPaint(
|
size: Size(40, 34.64),
|
painter: TrianglePainter(ColorConstant.theme),
|
)
|
])),
|
)),
|
Container(
|
width: 42,
|
height: 42,
|
padding: EdgeInsets.all(3),
|
decoration: BoxDecoration(
|
color: Colors.white, borderRadius: BorderRadius.circular(40)),
|
child: Container(
|
width: 42 - 3 * 2,
|
height: 42 - 3 * 2,
|
padding: EdgeInsets.all(2),
|
decoration: BoxDecoration(
|
color: ColorConstant.theme,
|
borderRadius: BorderRadius.circular(40)),
|
child: portrait,
|
),
|
),
|
],
|
));
|
}
|
}
|
|
//用户(带头像)位置marker
|
class PersonLocationMarker extends StatelessWidget {
|
final Image portrait;
|
|
PersonLocationMarker(this.portrait);
|
|
@override
|
Widget build(BuildContext context) {
|
return Container(
|
width: 42,
|
height: 42,
|
padding: EdgeInsets.all(3),
|
decoration: BoxDecoration(
|
color: Colors.white, borderRadius: BorderRadius.circular(40)),
|
child: Container(
|
width: 42 - 3 * 2,
|
height: 42 - 3 * 2,
|
padding: EdgeInsets.all(2),
|
decoration: BoxDecoration(
|
color: ColorConstant.theme,
|
borderRadius: BorderRadius.circular(40)),
|
child: Image.asset(
|
"assets/images/mine/icon_mine_default_portrait.png",
|
),
|
),
|
);
|
}
|
}
|
|
class MapMarkerUtil {
|
///添加轨迹开始点
|
static Future<List<BMFMarker>> addTravelStartMarker(
|
BMFMapController? _mapController, BMFCoordinate position) async {
|
BMFMarker marker = await MapUtil.addMarker(
|
_mapController, position, "assets/images/map/icon_travel_start.png",
|
zIndex: 1);
|
BMFMarker marker1 = await MapUtil.addMarker(
|
_mapController, position, "assets/images/map/icon_travel_start_1.png",
|
offset: BMFPoint(0, 38));
|
return [marker, marker1];
|
}
|
|
//添加轨迹结束点
|
static Future<List<BMFMarker>> addTravelEndMarker(
|
BMFMapController? _mapController, BMFCoordinate position) async {
|
BMFMarker marker = await MapUtil.addMarker(
|
_mapController, position, "assets/images/map/icon_travel_end.png",
|
zIndex: 1);
|
BMFMarker marker1 = await MapUtil.addMarker(
|
_mapController, position, "assets/images/map/icon_travel_end_1.png",
|
offset: BMFPoint(0, 38));
|
return [marker, marker1];
|
}
|
}
|