Files
meshcore-open/lib/widgets/map_poi_cluster.dart
T
zjs81 88dcc5943f UI refresh: shared widgets, screen cleanups, and full translations
- Extract reusable widgets (chat composer/send pipeline, message bubble
  frame, reaction chips, path map scaffold, radio settings dialog,
  translation settings section, map POI clusters, nav tiles, etc.) and
  slim down the screens that used them
- Map: hide/remove markers with restore, confirm before setting node
  location, POI clustering, semantics labels
- Map cache: cancellable downloads and a bulk tile limit
- Repeater: unsaved-changes guard, CLI search/copy/share transcript,
  framed-command debug preview, disconnected banner
- Confirm before clearing chats and debug logs
- Keep cached unread totals in sync on per-contact/channel updates
- Move remaining hardcoded strings into l10n and translate the 98 new
  keys into all 17 non-English locales
2026-10-11 15:17:01 -07:00

122 lines
3.6 KiB
Dart

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:latlong2/latlong.dart';
import '../theme/mesh_theme.dart';
/// Size in degrees of a square grid cell that covers roughly [cellPx]
/// screen pixels at [zoom] (Web Mercator, 256 px tiles).
double mapGridCellDegrees(double zoom, {double cellPx = 64}) =>
360.0 / (256.0 * pow(2.0, zoom)) * cellPx;
/// Key of the grid cell that [point] falls into for a cell size of [cellDeg].
String mapGridCellKey(LatLng point, double cellDeg) =>
'${(point.latitude / cellDeg).floor()}:${(point.longitude / cellDeg).floor()}';
/// Buckets [items] into grid cells of [cellDeg] degrees, keeping insertion
/// order inside each cell.
Map<String, List<T>> mapGridCluster<T>(
Iterable<T> items,
LatLng Function(T item) positionOf,
double cellDeg,
) {
final cells = <String, List<T>>{};
for (final item in items) {
(cells[mapGridCellKey(positionOf(item), cellDeg)] ??= <T>[]).add(item);
}
return cells;
}
/// Round marker that stands for several shared points of interest. When
/// [includesSelf] is set, it is drawn with the "You" ring and person icon so
/// the user's own position stays visible under the POIs placed there.
class PoiClusterMarker extends StatelessWidget {
final int count;
final bool includesSelf;
final String semanticLabel;
const PoiClusterMarker({
super.key,
required this.count,
required this.semanticLabel,
this.includesSelf = false,
});
@override
Widget build(BuildContext context) {
final circle = Container(
width: 40,
height: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: includesSelf ? MapPalette.panelDark : MapPalette.router,
border: Border.all(
color: includesSelf ? MapPalette.selected : MapPalette.markerOutline,
width: 3,
),
boxShadow: const [
BoxShadow(
color: MapPalette.markerShadow,
blurRadius: 8,
offset: Offset(0, 3),
),
],
),
alignment: Alignment.center,
child: includesSelf
? const Icon(
Icons.person_pin_circle,
color: MapPalette.selected,
size: 24,
)
: Text(
'$count',
style: MeshTheme.mono(
fontSize: count >= 100 ? 13 : 15,
fontWeight: FontWeight.w800,
color: MapPalette.markerOutline,
),
),
);
return Semantics(
button: true,
label: semanticLabel,
excludeSemantics: true,
child: Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
circle,
if (includesSelf)
Positioned(
right: -2,
top: -2,
child: Container(
constraints: const BoxConstraints(minWidth: 22, minHeight: 22),
padding: const EdgeInsets.symmetric(horizontal: 4),
decoration: BoxDecoration(
color: MapPalette.router,
borderRadius: BorderRadius.circular(MeshRadii.pill),
border: Border.all(
color: MapPalette.markerOutline,
width: 1.5,
),
),
alignment: Alignment.center,
child: Text(
'$count',
style: MeshTheme.mono(
fontSize: 12,
fontWeight: FontWeight.w800,
color: MapPalette.markerOutline,
),
),
),
),
],
),
);
}
}