Merge pull request #617 from cano64/map-performance

Speed improvements for the Online Node Map,
This commit is contained in:
zjs81 authored and GitHub committed 2026-10-31 13:42:30 -07:00
commit 41fa841e74
1 file changed
+70 -46
+70 -46
View File
@@ -109,6 +109,35 @@ Color networkMapStatusColor(NetworkMapRepeaterStatus status) {
}; };
} }
/// Above this many in-view repeaters, hexagons and marker shadows are skipped.
const int networkMapDenseNodeCount = 30;
/// Above this many in-view links, each line is one stroke at half width
const int networkMapDenseLinkCount = 70;
/// Full style is a 3.5 px confirmed stroke or a 2.5 px unconfirmed stroke,
/// each with a 1 px border. Simple style keeps the pattern and drops the
/// border, so the painter records the line once, at half the stroke width.
Polyline _onlineLinkPolyline(NetworkMapLink link, {required bool simple}) {
final confirmed = link.confirmed;
final strokeWidth = confirmed ? 3.5 : 2.5;
return Polyline(
points: [link.aCell.center, link.bCell.center],
strokeWidth: simple ? strokeWidth / 2 : strokeWidth,
color: MapPalette.router.withValues(alpha: confirmed ? 0.85 : 0.6),
borderStrokeWidth: simple ? 0 : 1,
borderColor: MapPalette.markerOutline.withValues(alpha: 0.7),
pattern: confirmed
? const StrokePattern.solid()
: StrokePattern.dashed(segments: const [10, 8]),
);
}
/// Map layers for the online network: links, repeater hexagons and a /// Map layers for the online network: links, repeater hexagons and a
/// tappable center marker so small cells stay visible when zoomed out. /// tappable center marker so small cells stay visible when zoomed out.
/// ///
@@ -120,51 +149,44 @@ List<Widget> buildNetworkMapOnlineLayers({
required ValueChanged<NetworkMapRepeater> onTap, required ValueChanged<NetworkMapRepeater> onTap,
}) { }) {
final repeaters = controller.repeaters; final repeaters = controller.repeaters;
final links = controller.links;
final dropHexagons = repeaters.length > networkMapDenseNodeCount;
final simpleLines = links.length > networkMapDenseLinkCount;
return [ return [
PolylineLayer( PolylineLayer(
polylines: [ polylines: [
for (final link in controller.links) for (final link in links)
Polyline( _onlineLinkPolyline(link, simple: simpleLines),
points: [link.aCell.center, link.bCell.center],
strokeWidth: link.confirmed ? 3.5 : 2.5,
color: MapPalette.router.withValues(
alpha: link.confirmed ? 0.85 : 0.6,
),
borderStrokeWidth: 1,
borderColor: MapPalette.markerOutline.withValues(alpha: 0.7),
pattern: link.confirmed
? const StrokePattern.solid()
: StrokePattern.dashed(segments: const [10, 8]),
),
], ],
), ),
GestureDetector( if (!dropHexagons)
onTap: () { GestureDetector(
final hits = controller.hitNotifier.value?.hitValues; onTap: () {
if (hits != null && hits.isNotEmpty) onTap(hits.first); final hits = controller.hitNotifier.value?.hitValues;
}, if (hits != null && hits.isNotEmpty) onTap(hits.first);
child: PolygonLayer<NetworkMapRepeater>( },
hitNotifier: controller.hitNotifier, child: PolygonLayer<NetworkMapRepeater>(
polygons: [ hitNotifier: controller.hitNotifier,
for (final repeater in repeaters) polygons: [
if (repeater.cell.boundary.length >= 3) for (final repeater in repeaters)
Polygon<NetworkMapRepeater>( if (repeater.cell.boundary.length >= 3)
points: repeater.cell.boundary, Polygon<NetworkMapRepeater>(
hitValue: repeater, points: repeater.cell.boundary,
color: localMarkerKeys.contains(repeater.key) hitValue: repeater,
? null color: localMarkerKeys.contains(repeater.key)
: networkMapStatusColor( ? null
repeater.status, : networkMapStatusColor(
).withValues(alpha: 0.22), repeater.status,
borderColor: networkMapStatusColor(repeater.status), ).withValues(alpha: 0.22),
borderStrokeWidth: 2.5, borderColor: networkMapStatusColor(repeater.status),
pattern: repeater.confirmed borderStrokeWidth: 2.5,
? const StrokePattern.solid() pattern: repeater.confirmed
: StrokePattern.dashed(segments: const [8, 6]), ? const StrokePattern.solid()
), : StrokePattern.dashed(segments: const [8, 6]),
], ),
],
),
), ),
),
MarkerLayer( MarkerLayer(
markers: [ markers: [
for (final repeater in repeaters) for (final repeater in repeaters)
@@ -183,13 +205,15 @@ List<Widget> buildNetworkMapOnlineLayers({
color: MapPalette.markerOutline, color: MapPalette.markerOutline,
width: 2.5, width: 2.5,
), ),
boxShadow: const [ boxShadow: dropHexagons
BoxShadow( ? null
color: MapPalette.markerShadow, : const [
blurRadius: 6, BoxShadow(
offset: Offset(0, 2), color: MapPalette.markerShadow,
), blurRadius: 6,
], offset: Offset(0, 2),
),
],
), ),
child: Icon( child: Icon(
repeater.type == advTypeRoom repeater.type == advTypeRoom