Skip to content
Snippets Groups Projects
Commit 30a6d1b7 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: full shape selection

parent 2a5118df
No related branches found
No related tags found
1 merge request!10Clhp map
...@@ -34,22 +34,20 @@ class ChoroplethMap extends StatefulWidget { ...@@ -34,22 +34,20 @@ class ChoroplethMap extends StatefulWidget {
} }
class _ChoroplethMapState extends State<ChoroplethMap> { class _ChoroplethMapState extends State<ChoroplethMap> {
late MapShapeSource dataSource;
int selectedIndex = -1; int selectedIndex = -1;
Color selectedColor = Colors.grey; // Initialise to gray
late MapShapeSource dataSource;
late MapShapeSource mapShapeSource; late MapShapeSource mapShapeSource;
late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior(); late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior();
List<SubDiv> subdivisions = <SubDiv>[]; List<SubDiv> subdivisions = <SubDiv>[];
int count = 0;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// Create list of all subdivisions // Extract all subdivisions from list of measurements
for (Measurement measurement in widget.measurements) { for (Measurement measurement in widget.measurements) {
for (SubDiv subdivision in measurement.subDivs) { for (SubDiv subdivision in measurement.subDivs) {
subdivisions.add(subdivision); subdivisions.add(subdivision);
count++;
} }
}; };
...@@ -57,32 +55,32 @@ class _ChoroplethMapState extends State<ChoroplethMap> { ...@@ -57,32 +55,32 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
dataSource = MapShapeSource.memory( dataSource = MapShapeSource.memory(
widget.relation, widget.relation,
shapeDataField: 'sub_div_id', shapeDataField: 'sub_div_id',
dataCount: count, dataCount: subdivisions.length,
primaryValueMapper: (int index) => primaryValueMapper: (int index) =>
subdivisions[index].sub_div_id, subdivisions[index].sub_div_id,
shapeColorValueMapper: (int index) => shapeColorValueMapper: (int index) =>
subdivisions[index].avgThickness, subdivisions[index].avgThickness, // NB will later be minThickness, fix in server first
shapeColorMappers: const [ shapeColorMappers: const [
MapColorMapper( MapColorMapper(
from: 0, from: 0,
to: 4, to: 4,
color: Color(0xFFff0000), color: Color(0xFFff0000),
text: '{0},{25}'), text: '{0},{4}'),
MapColorMapper( MapColorMapper(
from: 4, from: 4,
to: 7, to: 6,
color: Color(0xffff6a00), color: Color(0xffff6a00),
text: '75'), text: '6'),
MapColorMapper( MapColorMapper(
from: 7, from: 6,
to: 10, to: 8,
color: Color(0xFFb1ff00), color: Color(0xFFb1ff00),
text: '150'), text: '8'),
MapColorMapper( MapColorMapper(
from: 10, from: 8,
to: 400, to: 400,
color: Color(0xff4fa8d7), color: Color(0xFF00d6ff),
text: '400'), text: '>8'),
], ],
); );
} }
...@@ -92,8 +90,8 @@ class _ChoroplethMapState extends State<ChoroplethMap> { ...@@ -92,8 +90,8 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
return Stack( return Stack(
children: [ children: [
SfMapsTheme( SfMapsTheme(
data: SfMapsThemeData( // Shape selection behavior data: SfMapsThemeData( // Coloring of selected shape
selectionColor: Colors.orange, selectionColor: selectedColor,
selectionStrokeWidth: 3, selectionStrokeWidth: 3,
selectionStrokeColor: Colors.red[900], selectionStrokeColor: Colors.red[900],
), ),
...@@ -101,13 +99,14 @@ class _ChoroplethMapState extends State<ChoroplethMap> { ...@@ -101,13 +99,14 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
layers: [ layers: [
MapShapeLayer( MapShapeLayer(
source: dataSource, source: dataSource,
//zoomPanBehavior: _zoomPanBehavior, zoomPanBehavior: _zoomPanBehavior,
strokeColor: Colors.blue.shade50, strokeColor: Colors.blue.shade50,
// Shape selection // Shape selection
selectedIndex: selectedIndex, selectedIndex: selectedIndex,
onSelectionChanged: (int index) { onSelectionChanged: (int index) { // Shape selection behavior
setState(() { // Shape selection setState(() {
selectedIndex = index; selectedIndex = index;
selectedColor = subdivisions[index].color.withOpacity(0.7);
}); });
widget.onSelectionChanged(selectedIndex); widget.onSelectionChanged(selectedIndex);
}, },
......
No preview for this file type
...@@ -85,7 +85,7 @@ def get_all_markers(self, cursor, waterBodyName): ...@@ -85,7 +85,7 @@ def get_all_markers(self, cursor, waterBodyName):
'CenLatitude': 7.0, 'CenLatitude': 7.0,
'CenLongitude': 8.0, 'CenLongitude': 8.0,
'Accuracy': 1.0, 'Accuracy': 1.0,
'Color': calculateColor(min_thickness) 'Color': calculateColor(avg_thickness)
} }
sub_divisions.append(subdivision) sub_divisions.append(subdivision)
...@@ -134,7 +134,7 @@ def calculateColor(thickness: float): # NB not final colors nor ranges ...@@ -134,7 +134,7 @@ def calculateColor(thickness: float): # NB not final colors nor ranges
if 0 < thickness <= 4: if 0 < thickness <= 4:
return 0xFFff0000 # Red return 0xFFff0000 # Red
elif 4 < thickness <= 6: elif 4 < thickness <= 6:
return 0xFFff9400 # Orange return 0xffff6a00 # Orange
elif 6 < thickness <= 8: elif 6 < thickness <= 8:
return 0xFFb1ff00 # Green return 0xFFb1ff00 # Green
elif thickness > 8: elif thickness > 8:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment