Commit 40a51f18 authored by Nicolas Richard Walter Boeckh's avatar Nicolas Richard Walter Boeckh 💬

Added Colored markers for pm

parent 943a4798
......@@ -30,9 +30,11 @@ class MapDisplayController {
/// [Marker] representing the user's current [Position].
Marker _marker;
List<CircleMarker> _pmMarkers = [];
/// [List] of [Color]s to be smudged as a gradient and cherry picked based on a value (lerped).
/// @see [_colorizeValue]
List<Color> _colors = [ Color.fromARGB(0, 0, 0xcc, 0), Color.fromARGB(0, 0, 0xcc, 0), Color.fromARGB(0, 0xff, 0xff, 0), Color.fromARGB(0, 0xeb, 0x8a, 0x14), Color.fromARGB(0, 0xff, 0, 0), Color.fromARGB(0, 0xa1, 0x06, 0x49), Color.fromARGB(0, 0x7e, 0, 0x23) ];
List<Color> _colors = [ Color.fromARGB(0xff, 0, 0xcc, 0), Color.fromARGB(0xff, 0, 0xcc, 0), Color.fromARGB(0xff, 0xff, 0xff, 0), Color.fromARGB(0xff, 0xeb, 0x8a, 0x14), Color.fromARGB(0xff, 0xff, 0, 0), Color.fromARGB(0xff, 0xa1, 0x06, 0x49), Color.fromARGB(0xff, 0x7e, 0, 0x23) ];
/// [List] of stops for the lerping to occur.
/// @see [_colorizeValue]
......@@ -50,6 +52,9 @@ class MapDisplayController {
/// This function is hooked to the [PositionHandler]s progress, ie. when a new [Position] is acquired (once per second), it is broadcasted across the app and can be listened to.
PositionHandler().getCurrentOrLastPosition().listen((posChanged) {
if (posChanged == null)
return;
/// If a [BluetoothDevice] is connected, then the [DataHandler] will have a [DataPacket] available.
DataPacket latest = DataHandler().getLatestData();
......@@ -68,27 +73,21 @@ class MapDisplayController {
this._controller.move(this._currentPos, this._zoom);
/// Move the [Marker] to the current [Position].
this._marker = this._buildMarker(this._currentPos);
if (this._lastPos != null && this._currentPos != null && this._distance.as(LengthUnit.Meter, this._lastPos, this._currentPos) >= 2) {
// TODO Remove "|| true" to allow PM dependent gradient colors.
if (latest == null || true) {
if (this._polylines.length == 0)
this._polylines.add(
Polyline(
points: [this._lastPos, this._currentPos],
color: Colors.blue
)
);
else if (this._polylines.last.color == Colors.blue)
this._polylines.last.points.add(this._currentPos);
} else {
this._marker = this._buildLocationMarker(this._currentPos);
if ((this._lastPos != null && this._currentPos != null && this._distance.as(LengthUnit.Meter, this._lastPos, this._currentPos) >= 2)) {
if (this._polylines.length == 0) {
this._polylines.add(
Polyline(
points: [this._lastPos, this._currentPos],
color: _colorizeValue(latest.pm2_5())
color: Colors.blue
)
);
} else
this._polylines.last.points.add(this._currentPos);
if (latest != null) {
this._pmMarkers.add(_buildPMMarker(this._currentPos, latest.pm2_5()));
}
}
});
......@@ -139,7 +138,9 @@ class MapDisplayController {
List<Polyline> polylines() => this._polylines;
/// @Getter for [_marker].
Marker marker() => this._marker != null ? this._marker : _buildMarker(LatLng(0, 0));
Marker marker() => this._marker != null ? this._marker : _buildLocationMarker(LatLng(0, 0));
List<CircleMarker> pmMarkers() => this._pmMarkers;
/// Gets the lerped [Color] value at a for a given PM value.
Color _colorizeValue(double pmValue) {
......@@ -157,7 +158,7 @@ class MapDisplayController {
}
/// Wrapper function to build a [Marker], with default values.
Marker _buildMarker(LatLng position) => Marker(
Marker _buildLocationMarker(LatLng position) => Marker(
width: 20.0,
height: 20.0,
point: position,
......@@ -166,4 +167,14 @@ class MapDisplayController {
),
);
/// TODO MAKE PM Value be switchable.
CircleMarker _buildPMMarker(LatLng position, double pmValue) {
return CircleMarker(
radius: 6,
point: position,
color: _colorizeValue(pmValue).withAlpha(0xff),
borderStrokeWidth: 1,
borderColor: Colors.green
);
}
}
\ No newline at end of file
......@@ -24,9 +24,12 @@ class MapContainer extends BaseWidget {
),
MarkerLayerOptions(
markers: [
MapDisplayController().marker()
MapDisplayController().marker(),
],
),
CircleLayerOptions(
circles: MapDisplayController().pmMarkers()
),
PolylineLayerOptions(
polylines: MapDisplayController().polylines()
)
......@@ -72,6 +75,7 @@ class MapContainer extends BaseWidget {
width: 40,
height: 40,
child: FloatingActionButton(
heroTag: "buttonMapZoomIn",
onPressed: () => MapDisplayController().setControllerZoom(true),
backgroundColor: Colors.grey[400],
child: Icon(
......@@ -84,6 +88,7 @@ class MapContainer extends BaseWidget {
width: 40,
height: 40,
child: FloatingActionButton(
heroTag: "buttonMapZoomOut",
onPressed: () => MapDisplayController().setControllerZoom(false),
backgroundColor: Colors.grey[400],
child: Icon(
......@@ -105,6 +110,7 @@ class MapContainer extends BaseWidget {
child: Container(
padding: EdgeInsets.all(5),
child: FloatingActionButton(
heroTag: "buttonMap",
onPressed: () => MapDisplayController().setControllerAutomatic(),
child: Icon(
Icons.adjust
......
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