fully fixes connection refused errors by limiting concurrent connections.

This commit is contained in:
stopflock
2025-07-19 00:32:43 -05:00
parent 95df976475
commit 32d57ba3cd

View File

@@ -1,6 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:io';
import 'package:http/io_client.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
@@ -96,16 +98,14 @@ class _MapViewState extends State<MapView> {
final appState = context.watch<AppState>(); final appState = context.watch<AppState>();
final session = appState.session; final session = appState.session;
// If we just entered addmode and no target yet, seed it with current map center. // Seed addmode target once, after first controller center is available.
if (session != null && session.target == null) { if (session != null && session.target == null) {
try { try {
final center = _controller.camera.center; final center = _controller.camera.center;
WidgetsBinding.instance.addPostFrameCallback( WidgetsBinding.instance.addPostFrameCallback(
(_) => appState.updateSession(target: center), (_) => appState.updateSession(target: center),
); );
} catch (_) { } catch (_) {/* controller not ready yet */}
// controller not ready yet; will update onPositionChanged soon
}
} }
final zoom = _safeZoom(); final zoom = _safeZoom();
@@ -155,12 +155,37 @@ class _MapViewState extends State<MapView> {
children: [ children: [
TileLayer( TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
tileProvider: NetworkTileProvider(
headers: {
'User-Agent':
'FlockMap/0.4 (+https://github.com/yourrepo)',
},
httpClient: IOClient(
HttpClient()..maxConnectionsPerHost = 4,
),
),
userAgentPackageName: 'com.example.flock_map_app', userAgentPackageName: 'com.example.flock_map_app',
), ),
PolygonLayer(polygons: overlays), PolygonLayer(polygons: overlays),
MarkerLayer(markers: markers), MarkerLayer(markers: markers),
], ],
), ),
// Attribution overlay
Positioned(
bottom: 8,
right: 8,
child: Container(
color: Colors.white70,
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),
child: const Text(
'© OpenStreetMap contributors',
style: TextStyle(fontSize: 11),
),
),
),
// Fixed pin when adding camera
if (session != null) if (session != null)
const IgnorePointer( const IgnorePointer(
child: Center( child: Center(
@@ -173,7 +198,7 @@ class _MapViewState extends State<MapView> {
Polygon _buildCone(LatLng origin, double bearingDeg, double zoom) { Polygon _buildCone(LatLng origin, double bearingDeg, double zoom) {
const halfAngle = 15.0; const halfAngle = 15.0;
final length = 0.002 * math.pow(2, 15 - zoom); // scale with zoom final length = 0.002 * math.pow(2, 15 - zoom);
LatLng _project(double deg) { LatLng _project(double deg) {
final rad = deg * math.pi / 180; final rad = deg * math.pi / 180;