Commit 7a6a960b authored by Nicolas Richard Walter Boeckh's avatar Nicolas Richard Walter Boeckh 💬

Changed map mode, less memory consumption because rebuild of singular layer.

parent 83b92d5d
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.7+2\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.7+2\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+8\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+5\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-07-27 12:45:17.444374","version":"1.19.0-2.0.pre.49"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.7+2\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.7+2\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+8\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+5\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-08-08 21:49:57.528732","version":"1.19.0-2.0.pre.49"}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:latlong/latlong.dart';
import 'package:logair_application/logic/handlers/data_handler.dart';
import 'package:logair_application/logic/handlers/database_handler.dart';
import 'package:logair_application/logic/handlers/network_handler.dart';
import 'package:logair_application/logic/data_header.dart';
import 'package:logair_application/logic/data_packet.dart';
......@@ -33,34 +34,60 @@ class MapDisplayController {
/// [Marker] representing the user's current [Position].
Marker _marker;
HashMap<PMSymbol, List<CircleMarker>> _pmMarkers = HashMap.from({
PMSymbol.PM1: <CircleMarker>[],
PMSymbol.PM2_5: <CircleMarker>[],
PMSymbol.PM4: <CircleMarker>[],
PMSymbol.PM10: <CircleMarker>[]}
);
Future<void> _rebuildMarkers() async {
List<DataPacket> packets = await DatabaseHandler().getLastPackets(200);
packets.forEach((DataPacket packet) {
switch (_pmSymbol) {
case PMSymbol.PM1:
this.addToList(this._currentPos, packet.pm1(), 200);
break;
case PMSymbol.PM1:
this.addToList(this._currentPos, packet.pm2_5(), 200);
break;
case PMSymbol.PM4:
this.addToList(this._currentPos, packet.pm4(), 200);
break;
case PMSymbol.PM10:
this.addToList(this._currentPos, packet.pm10(), 200);
break;
default:
break;
}
});
}
List<CircleMarker> _pmMarkers = <CircleMarker>[];
/// [Singleton]() instantiation factory.
factory MapDisplayController() => _singleton;
/// @Getter for [_polylines].
List<Polyline> polylines() => this._polylines;
List<Polyline> get polylines => this._polylines;
/// @Getter for [_marker].
Marker marker() => this._marker != null ? this._marker : _buildLocationMarker(LatLng(0, 0));
Marker get marker => this._marker != null ? this._marker : _buildLocationMarker(LatLng(0, 0));
/// Object used to calculate the real-life distance of two [Position]s
final Distance _distance = new Distance();
// TODO Faster to rebuild than to store ?
List<CircleMarker> pmMarkers() => this._pmMarkers[_pmKey];
List<String> _pmKey = PMSymbol.list.map((e) => e.key);
List<CircleMarker> get pmMarkers => this._pmMarkers;
PMSymbol _pmSymbol = PMSymbol.PM2_5;
PMSymbol _pmKeyIndex = PMSymbol.PM2_5;
void setPMKeyIndex(PMSymbol value) {
print('PM Index $value gives ${value.key}');
this._pmSymbol = value;
this._rebuildMarkers();
}
void setPMKeyIndex(PMSymbol value) { print('PM Index $value gives ${value.key}'); this._pmKeyIndex = value; }
void addToList(LatLng position, double value, int maxPoints) {
if (this._pmMarkers.length > maxPoints)
this._pmMarkers.removeRange(0, this._pmMarkers.length - 200);
this._pmMarkers.add(_buildPMMarker(position, value));
}
/// This function is executed on first initialization of the [MapDisplayController]
/// TODO: Throttle to 1 in 5 updates for efficiency ?
......@@ -106,10 +133,22 @@ class MapDisplayController {
this._polylines.last.points.add(this._currentPos);
if (latest != null) {
if (latest.pm1() != null) this._pmMarkers['PM1'].add(_buildPMMarker(this._currentPos, latest.pm1()));
if (latest.pm2_5() != null) this._pmMarkers['PM2_5'].add(_buildPMMarker(this._currentPos, latest.pm2_5()));
if (latest.pm4() != null) this._pmMarkers['PM4'].add(_buildPMMarker(this._currentPos, latest.pm4()));
if (latest.pm10() != null) this._pmMarkers['PM10'].add(_buildPMMarker(this._currentPos, latest.pm10()));
switch (_pmSymbol) {
case PMSymbol.PM1:
this.addToList(this._currentPos, latest.pm1(), 200);
break;
case PMSymbol.PM1:
this.addToList(this._currentPos, latest.pm2_5(), 200);
break;
case PMSymbol.PM4:
this.addToList(this._currentPos, latest.pm4(), 200);
break;
case PMSymbol.PM10:
this.addToList(this._currentPos, latest.pm10(), 200);
break;
default:
break;
}
}
}
});
......@@ -118,8 +157,10 @@ class MapDisplayController {
// TODO Set user defined duration
// TODO Set user defined radius
new Timer.periodic(Duration(minutes: 1), (Timer t) {
if (this._controller != null && this._controller.bounds != null)
if (this._controller != null && this._controller.bounds != null) {
print(this._controller.bounds);
NetworkHandler().getProximityPoints(DataHeader().deviceID, this._controller.bounds);
}
});
}
......@@ -178,7 +219,7 @@ class MapDisplayController {
return CircleMarker(
radius: 8,
point: position,
color: this._pmKeyIndex.colorizeValue(pmValue).withAlpha(0xff),
color: this._pmSymbol.colorizeValue(pmValue).withAlpha(0xff),
borderStrokeWidth: 1,
borderColor: Colors.blue[300]
);
......
......@@ -73,9 +73,12 @@ class DataHandler {
/// TODO Caching
List<DataPacket> getData() => _sortedData;
/// Get a subrange of [DataPacket]s.
/// Get a subrange of [DataPacket]s from the start.
List<DataPacket> getDataRange(int range) => (range > _sortedData.length) ? _sortedData : _sortedData.sublist(0, range);
/// Get a subrange of [DataPacket]s from the start.
List<DataPacket> getDataRangeLatest(int range) => (range <= _sortedData.length) ? _sortedData : _sortedData.sublist(_sortedData.length - range, _sortedData.length);
/// Remove the entirety of the acquired data.
void clearData() {
_sortedData.removeWhere((element) => true);
......
......@@ -153,4 +153,12 @@ class DatabaseHandler {
await Future.delayed(Duration(seconds: 5));
}
}
Future<List<DataPacket>> getLastPackets(int maxResults) async {
final Database database = await _database;
final List<Map<String, dynamic>> data = await database.rawQuery('SELECT * FROM data ORDER BY id DESC LIMIT $maxResults;');
return List.generate(data.length, (i) => DataPacket.fromMappedData(data[i]));
}
}
\ No newline at end of file
......@@ -78,7 +78,7 @@ class NetworkHandler {
/// Get all of the points in proximity to the device.
void getProximityPoints(String deviceId, LatLngBounds bounds) async {
/// The default endpoint.
String url = 'https://api.logair.unige.ch/v1/service/map/bounds?localId=$deviceId&lat1=${bounds.northEast.latitude}&lng1=${bounds.northEast.longitude}&lat2=${bounds.southWest.latitude}&lng2=${bounds.southWest.longitude}&age=${5000}&limit=${200}&skip=0';
String url = 'https://api.logair.unige.ch/v1/geo/bounds?device_id=$deviceId&lat1=${bounds.northEast.latitude}&lng1=${bounds.northEast.longitude}&lat2=${bounds.southWest.latitude}&lng2=${bounds.southWest.longitude}&age=${300000}&limit=${200}';
/// Attempt to send the data to the endpoint via HTTP POST request.
http.Response response = await http.get(
url,
......
......@@ -25,14 +25,14 @@ class MapContainer extends BaseWidget {
subdomains: ['a', 'b', 'c']
),
PolylineLayerOptions(
polylines: MapDisplayController().polylines()
polylines: MapDisplayController().polylines,
),
CircleLayerOptions(
circles: MapDisplayController().pmMarkers()
circles: MapDisplayController().pmMarkers,
),
MarkerLayerOptions(
markers: [
MapDisplayController().marker(),
MapDisplayController().marker,
],
),
],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment