-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_patch.py
More file actions
211 lines (188 loc) · 9.82 KB
/
Copy pathmap_patch.py
File metadata and controls
211 lines (188 loc) · 9.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"""
Patch map_screen.dart:
1. Fix satellite crash — remove dynamic maxZoom from MapOptions, enforce via addPostFrameCallback
2. Add _showHeatMap state variable
3. Import heat_map_layer.dart
4. Add HeatMapLayer inside FlutterMap children
5. Add heat-map toggle button to the expandable sidebar
6. Add HeatMapLegend Positioned widget when active
"""
with open('lib/map_screen.dart', 'r', encoding='utf-8') as f:
src = f.read()
# ── 1. Add heat_map import ────────────────────────────────────────────────────
src = src.replace(
"import 'services/auth_service.dart';",
"import 'services/auth_service.dart';\nimport 'layers/heat_map_layer.dart';",
1
)
# ── 2. Add _showHeatMap state variable after _sidebarExpanded ─────────────────
src = src.replace(
' bool _sidebarExpanded = false; // whether the collapsible action buttons are shown',
' bool _sidebarExpanded = false; // whether the collapsible action buttons are shown\n bool _showHeatMap = false; // overlay heat map of captured zones',
1
)
# ── 3. Fix satellite crash: remove dynamic maxZoom, keep it null always ───────
src = src.replace(
' maxZoom: mapStyle == SettingsService.mapStyleSatellite ? _satelliteMaxZoom() : null,',
' // maxZoom enforced programmatically in onPositionChanged\n // (dynamic maxZoom in MapOptions crashes flutter_map during panning)\n maxZoom: null,',
1
)
# ── 4. In onPositionChanged, enforce satellite zoom programmatically ──────────
old_pos = ''' onPositionChanged: (camera, hasGesture) {
final newZoom = camera.zoom;
final newLat = camera.center.latitude;
final panGesture = hasGesture && _followingUser;
if (panGesture || newZoom != _mapZoom || (newLat - _mapLat).abs() > 0.0001) {
setState(() {
_mapZoom = newZoom;
_mapLat = newLat;
if (panGesture) _followingUser = false;
});
}
},'''
new_pos = ''' onPositionChanged: (camera, hasGesture) {
final newZoom = camera.zoom;
final newLat = camera.center.latitude;
final panGesture = hasGesture && _followingUser;
// ── Satellite zoom guard (no more dynamic maxZoom crash) ───
if (mapStyle == SettingsService.mapStyleSatellite) {
final maxZ = _satelliteMaxZoom();
if (newZoom > maxZ) {
// Clamp AFTER the current frame so it doesn't conflict
// with an ongoing gesture recognizer.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _mapController.move(camera.center, maxZ);
});
}
}
if (panGesture || newZoom != _mapZoom || (newLat - _mapLat).abs() > 0.0001) {
setState(() {
_mapZoom = newZoom;
_mapLat = newLat;
if (panGesture) _followingUser = false;
});
}
},'''
src = src.replace(old_pos, new_pos, 1)
# ── 5. Add HeatMapLayer inside FlutterMap children after RepaintBoundary ──────
old_polygon = ''' RepaintBoundary(
child: PolygonLayer(
polygons: _events.map((event) => Polygon(
points: event.polygon,
color: playerColor.withValues(alpha: 0.25),
borderColor: playerColor,
borderStrokeWidth: 3,
)).toList(),
),
),'''
new_polygon = ''' RepaintBoundary(
child: PolygonLayer(
polygons: _events.map((event) => Polygon(
points: event.polygon,
color: playerColor.withValues(alpha: 0.25),
borderColor: playerColor,
borderStrokeWidth: 3,
)).toList(),
),
),
// ── Heat Map overlay ─────────────────────────────────────────
if (_showHeatMap)
HeatMapLayer(
points: _events.map((e) => GeoCalculator.getVisualCenter(e.polygon)).toList(),
radius: (40.0 + _mapZoom * 2.5).clamp(40.0, 120.0),
),'''
src = src.replace(old_polygon, new_polygon, 1)
# ── 6. Add heat-map toggle button to expandable sidebar ───────────────────────
old_recon_btn = ''' // Recon / Planning mode
_buildSidebarBtn(
icon: Icons.explore,
color: _isPlanningMode
? recColor.withValues(alpha: 0.2)
: Colors.black.withValues(alpha: 0.3),
iconColor: _isPlanningMode ? recColor : Colors.white70,
border: Border.all(
color: _isPlanningMode ? recColor : Colors.white.withValues(alpha: 0.1),
),
onPressed: _togglePlanningMode,
tooltip: 'Recon Mode',
),'''
new_recon_btn = ''' // Recon / Planning mode
_buildSidebarBtn(
icon: Icons.explore,
color: _isPlanningMode
? recColor.withValues(alpha: 0.2)
: Colors.black.withValues(alpha: 0.3),
iconColor: _isPlanningMode ? recColor : Colors.white70,
border: Border.all(
color: _isPlanningMode ? recColor : Colors.white.withValues(alpha: 0.1),
),
onPressed: _togglePlanningMode,
tooltip: 'Recon Mode',
),
const SizedBox(height: 12),
// Heat Map toggle
_buildSidebarBtn(
icon: Icons.local_fire_department,
color: _showHeatMap
? Colors.deepOrange.withValues(alpha: 0.25)
: Colors.black.withValues(alpha: 0.3),
iconColor: _showHeatMap ? Colors.deepOrangeAccent : Colors.white70,
border: Border.all(
color: _showHeatMap
? Colors.deepOrangeAccent.withValues(alpha: 0.7)
: Colors.white.withValues(alpha: 0.1),
),
onPressed: () => setState(() => _showHeatMap = !_showHeatMap),
tooltip: 'Heat Map',
),'''
src = src.replace(old_recon_btn, new_recon_btn, 1)
# ── 7. Add HeatMapLegend positioned widget near the scale bar ─────────────────
old_scale_positioned = ''' // Map scale indicator — bottom-left, Google Maps style
if (settings.showMapScale.value)
Positioned(
bottom: 16,
left: 16,
child: _buildMapScaleWidget(settings.useMetric.value),
),'''
new_scale_positioned = ''' // Map scale indicator — bottom-left, Google Maps style
if (settings.showMapScale.value)
Positioned(
bottom: 16,
left: 16,
child: _buildMapScaleWidget(settings.useMetric.value),
),
// Heat map legend (shown when heat map is active)
if (_showHeatMap)
Positioned(
bottom: settings.showMapScale.value ? 60 : 16,
left: 16,
child: const HeatMapLegend(),
),'''
src = src.replace(old_scale_positioned, new_scale_positioned, 1)
with open('lib/map_screen.dart', 'w', encoding='utf-8') as f:
f.write(src)
# ── Verify all patches ────────────────────────────────────────────────────────
checks = [
('heat_map import', "import 'layers/heat_map_layer.dart';"),
('_showHeatMap state', '_showHeatMap = false;'),
('maxZoom null', 'maxZoom: null,'),
('No dynamic satellite maxZoom', 'mapStyle == SettingsService.mapStyleSatellite ? _satelliteMaxZoom() : null' not in src),
('postFrameCallback fix', '_mapController.move(camera.center, maxZ);'),
('HeatMapLayer in FlutterMap', 'HeatMapLayer('),
('Heat map radius scaling', '_mapZoom * 2.5').clamp(40.0, 120.0'),
('Sidebar heat button', "Icons.local_fire_department,"),
('HeatMapLegend positioned', 'HeatMapLegend()'),
]
all_ok = True
for name, check in checks:
if isinstance(check, bool):
ok = check
else:
ok = check in src
status = 'OK' if ok else 'MISSING'
if not ok:
all_ok = False
print(f' [{status}] {name}')
print()
print('All checks passed!' if all_ok else 'SOME CHECKS FAILED — see above')
print(f'File size: {len(src)} bytes, {src.count(chr(10))} lines')