Merge upstream/dev (28 commits) [upstream-sync]
This commit is contained in:
commit
596e7f9dcd
44 files changed
+1444
-38
No files matched your search
@@ -40,9 +40,9 @@ class NetworkMapOnlineController extends ChangeNotifier {
|
||||
List<NetworkMapLink> get links => _links;
|
||||
NetworkMapLoadState get state => _state;
|
||||
|
||||
void requestBounds(LatLngBounds bounds) {
|
||||
void requestBounds(LatLngBounds bounds, {bool fetchLinks = true}) {
|
||||
_timer?.cancel();
|
||||
_timer = Timer(_debounce, () => _load(bounds));
|
||||
_timer = Timer(_debounce, () => _load(bounds, fetchLinks: fetchLinks));
|
||||
}
|
||||
|
||||
/// Drops any pending or in-flight request (the online layer was hidden).
|
||||
@@ -51,7 +51,7 @@ class NetworkMapOnlineController extends ChangeNotifier {
|
||||
_generation++;
|
||||
}
|
||||
|
||||
Future<void> _load(LatLngBounds bounds) async {
|
||||
Future<void> _load(LatLngBounds bounds, {required bool fetchLinks}) async {
|
||||
final boxes = NetworkMapBbox.forVisibleArea(
|
||||
west: bounds.west,
|
||||
south: bounds.south,
|
||||
@@ -65,19 +65,21 @@ class NetworkMapOnlineController extends ChangeNotifier {
|
||||
}
|
||||
_setState(NetworkMapLoadState.loading);
|
||||
try {
|
||||
final results = await Future.wait([
|
||||
Future.wait(boxes.map(_client.fetchRepeaters)),
|
||||
Future.wait(boxes.map((b) => _client.fetchLinks(b))),
|
||||
]);
|
||||
final repeaterFuture = Future.wait(boxes.map(_client.fetchRepeaters));
|
||||
final Future<List<List<NetworkMapLink>>> linkFuture = fetchLinks
|
||||
? Future.wait<List<NetworkMapLink>>(
|
||||
boxes.map((b) => _client.fetchLinks(b)),
|
||||
)
|
||||
: Future.value(const <List<NetworkMapLink>>[]);
|
||||
final repeaterResults = await repeaterFuture;
|
||||
final linkResults = await linkFuture;
|
||||
if (_disposed || generation != _generation) return;
|
||||
// Two boxes (antimeridian) can both return items on the seam.
|
||||
_repeaters = {
|
||||
for (final r in results[0].expand((l) => l as List<NetworkMapRepeater>))
|
||||
r.key: r,
|
||||
for (final r in repeaterResults.expand((l) => l)) r.key: r,
|
||||
}.values.toList();
|
||||
_links = {
|
||||
for (final l in results[1].expand((l) => l as List<NetworkMapLink>))
|
||||
'${l.a}:${l.b}': l,
|
||||
for (final l in linkResults.expand((l) => l)) '${l.a}:${l.b}': l,
|
||||
}.values.toList();
|
||||
_setState(NetworkMapLoadState.ready);
|
||||
} catch (_) {
|
||||
@@ -109,15 +111,12 @@ 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.
|
||||
@@ -136,8 +135,6 @@ Polyline _onlineLinkPolyline(NetworkMapLink link, {required bool simple}) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Map layers for the online network: links, repeater hexagons and a
|
||||
/// tappable center marker so small cells stay visible when zoomed out.
|
||||
///
|
||||
@@ -145,20 +142,27 @@ Polyline _onlineLinkPolyline(NetworkMapLink link, {required bool simple}) {
|
||||
/// their hexagon outline is added.
|
||||
List<Widget> buildNetworkMapOnlineLayers({
|
||||
required NetworkMapOnlineController controller,
|
||||
List<NetworkMapRepeater>? repeaters,
|
||||
bool showLinks = true,
|
||||
required Set<String> localMarkerKeys,
|
||||
required ValueChanged<NetworkMapRepeater> onTap,
|
||||
}) {
|
||||
final repeaters = controller.repeaters;
|
||||
final links = controller.links;
|
||||
final dropHexagons = repeaters.length > networkMapDenseNodeCount;
|
||||
final visibleRepeaters = repeaters ?? controller.repeaters;
|
||||
final visibleKeys = {for (final repeater in visibleRepeaters) repeater.key};
|
||||
final links = [
|
||||
for (final link in controller.links)
|
||||
if (visibleKeys.contains(link.a) && visibleKeys.contains(link.b)) link,
|
||||
];
|
||||
final dropHexagons = visibleRepeaters.length > networkMapDenseNodeCount;
|
||||
final simpleLines = links.length > networkMapDenseLinkCount;
|
||||
return [
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
for (final link in links)
|
||||
_onlineLinkPolyline(link, simple: simpleLines),
|
||||
],
|
||||
),
|
||||
if (showLinks)
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
for (final link in links)
|
||||
_onlineLinkPolyline(link, simple: simpleLines),
|
||||
],
|
||||
),
|
||||
if (!dropHexagons)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
@@ -168,7 +172,7 @@ List<Widget> buildNetworkMapOnlineLayers({
|
||||
child: PolygonLayer<NetworkMapRepeater>(
|
||||
hitNotifier: controller.hitNotifier,
|
||||
polygons: [
|
||||
for (final repeater in repeaters)
|
||||
for (final repeater in visibleRepeaters)
|
||||
if (repeater.cell.boundary.length >= 3)
|
||||
Polygon<NetworkMapRepeater>(
|
||||
points: repeater.cell.boundary,
|
||||
@@ -189,7 +193,7 @@ List<Widget> buildNetworkMapOnlineLayers({
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
for (final repeater in repeaters)
|
||||
for (final repeater in visibleRepeaters)
|
||||
if (!localMarkerKeys.contains(repeater.key))
|
||||
Marker(
|
||||
point: repeater.cell.center,
|
||||
|
||||
Reference in new issue
Block a user