admin
2021-11-25 70a344485bd0c9b68ac91f72ed23ec5bfa998b09
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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];
  }
}