Skip to content

Commit

Permalink
Fixed editor memory leaks by forcing a global zoom level
Browse files Browse the repository at this point in the history
  • Loading branch information
TKFRvisionOfficial committed May 3, 2024
1 parent 13f2f1e commit 70174d8
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 162 deletions.
31 changes: 27 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,23 @@ class _MyHomePageState extends State<MyHomePage> {
RecordingManager(databaseBloc: widget.databaseBloc),
const LiveView(),
FutureBuilder(
future: AppVersion.getCommitId(),
builder: (context, AsyncSnapshot<String> snapshot) {
future: _getLicensePageData(),
builder: (context, AsyncSnapshot<_LicensePageData> snapshot) {
if (snapshot.hasError) {
throw snapshot.error!;
} else if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
final data = snapshot.data!;

final commitId = snapshot.data!.trim().substring(0, 8);
final commitId = data.commitId.trim().substring(0, 8);
var userId = "";
if (data.userId != null) {
userId = " [user id: ${data.userId}]";
}

return LicensePage(
applicationName: "Strasi ($commitId)",
applicationName: "Strasi ($commitId)$userId",
applicationLegalese: """Copyright 2023 TLM Solutions
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -242,3 +247,21 @@ limitations under the License.""",
super.dispose();
}
}

class _LicensePageData {
final String commitId;
final String? userId;

const _LicensePageData({
required this.commitId,
required this.userId,
});
}

Future<_LicensePageData> _getLicensePageData() async {
final commitId = await AppVersion.getCommitId();
final userId = (await SharedPreferences.getInstance()).getString("user_id");

return _LicensePageData(commitId: commitId, userId: userId);
}

2 changes: 1 addition & 1 deletion lib/pages/vehicle_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class _VehicleSelectionState extends State<VehicleSelection> with AutomaticKeepA
),
DropdownMenuItem(
value: 1,
child: Center(child: Text("Chemnitz")),
child: Center(child: Text("CC:\Users\tkfrv\IdeaProjects\freddy_bus_bauenhemnitz")),
),
DropdownMenuItem(
value: 4,
Expand Down
24 changes: 16 additions & 8 deletions lib/widgets/recording_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ class _RecordingMapState extends State<RecordingMap> {
}

void _updateBounds() {
/*
_mapController.fitCamera(CameraFit.bounds(
bounds: _getBoundsFromPoints(widget.pointList),
padding: const EdgeInsets.all(80.0),
));*/
));
}

@override
Expand All @@ -62,6 +61,7 @@ class _RecordingMapState extends State<RecordingMap> {
padding: const EdgeInsets.all(80.0),
),
backgroundColor: Colors.black54,
maxZoom: 20,
),
children: [
TileLayer(
Expand Down Expand Up @@ -119,6 +119,8 @@ class _RecordingMapState extends State<RecordingMap> {


LatLngBounds _getBoundsFromPoints(List<LatLng> points) {
const minDiff = 0.001;

var bounds = LatLngBounds.fromPoints(points);

/*
Expand All @@ -128,17 +130,23 @@ LatLngBounds _getBoundsFromPoints(List<LatLng> points) {
This normally only happens during debugging.
*/

if (bounds.southWest.latitude == bounds.northEast.latitude) {
/* todo check if necessary. this is to figure out if the
the zoom level is to big. but we have set a global max zoom level */

final latitudeDiff = minDiff - (bounds.southWest.latitude - bounds.northEast.latitude).abs();
final longitudeDiff = minDiff - (bounds.southWest.longitude - bounds.northEast.longitude).abs();

if (latitudeDiff > 0) {
bounds = LatLngBounds(
LatLng(bounds.southWest.latitude + 0.0005, bounds.southWest.longitude),
LatLng(bounds.northEast.latitude - 0.0005, bounds.northEast.longitude),
LatLng(bounds.southWest.latitude + minDiff / 2, bounds.southWest.longitude),
LatLng(bounds.northEast.latitude - minDiff / 2, bounds.northEast.longitude),
);
}

if (bounds.southWest.longitude == bounds.northEast.longitude) {
if (longitudeDiff > 0) {
bounds = LatLngBounds(
LatLng(bounds.southWest.latitude, bounds.southWest.longitude - 0.0005),
LatLng(bounds.northEast.latitude, bounds.northEast.longitude + 0.005),
LatLng(bounds.southWest.latitude, bounds.southWest.longitude - minDiff / 2),
LatLng(bounds.northEast.latitude, bounds.northEast.longitude + minDiff / 2),
);
}

Expand Down
Loading

0 comments on commit 70174d8

Please sign in to comment.