poi_search_bound.dart 915 B

123456789101112131415161718192021222324252627282930313233343536
  1. import '../../flutter_map.dart';
  2. class PoiSearchBound {
  3. final LatLng? center; // 圆形范围中心点
  4. final int? radius; // 半径(米)
  5. final List<LatLng>? points; // 多边形点集
  6. /// 圆形范围构造
  7. PoiSearchBound.circle({
  8. required this.center,
  9. required this.radius,
  10. }) : points = null;
  11. /// 多边形范围构造
  12. PoiSearchBound.polygon({
  13. required this.points,
  14. }) : center = null,
  15. radius = null;
  16. /// 转 Map,用于传给 MethodChannel
  17. Map<String, dynamic> toJson() {
  18. if (center != null && radius != null) {
  19. return {
  20. 'type': 'circle',
  21. 'center': center!.toJson(),
  22. 'radius': radius,
  23. };
  24. } else if (points != null) {
  25. return {
  26. 'type': 'polygon',
  27. 'points': points!.map((e) => e.toJson()).toList(),
  28. };
  29. }
  30. throw Exception('Invalid PoiSearchBound: 必须是 circle 或 polygon');
  31. }
  32. }